Skip to content

Poll API

Anton Alexeev edited this page Jul 9, 2018 · 10 revisions

METHOD GET: /{admin_route_prefix}/poll

Get List of polls

Query params for list filtering:

QUERY

id        : integer
active    : tinyint
anonymous : tinyint
position  : integer
title     : string
closed_at : date
closed_at_from:date
closed_at_to: date

RETURN JSON

{
  "current_page":1,
  "data":[
     {
       "id":1,
       "title":"Who is the best football player in the world?",
       "type":"OrangeShadow\\Polls\\Types\\SingleVote",
       "active":1,
       "anonymous":0,
       "position":1,
       "closed_at":null,
       "created_at":"2018-03-15 21:48:25",
       "updated_at":"2018-03-15 21:48:25"
     },...
  ],
  "first_page_url":"http:\/\/localhost\/pollpage=1",
  "from":1,
  "last_page":1,
  "last_page_url":"http:\/\/localhost\/poll?page=1",
  "next_page_url":null,
  "path":"http:\/\/localhost\/poll",
  "per_page":50,
  "prev_page_url":null,
  "to":2,
  "total":2
}

METHOD POST: /{admin_route_prefix}/poll

Make a poll

FORM-DATA PARAMS

active    : tinyint
anonymous : tinyint
position  : integer
title*    : string
type*     : string
closed_at : date
closed_at_from:date
closed_at_to: date

field with * are required

RETURN JSON

{
   "id":1,
   "title":"Who is the best football player in the world?",
   "type":"OrangeShadow\\Polls\\Types\\SingleVote",
   "active":1,
   "anonymous":0,
   "position":1,
   "closed_at":null,
   "created_at":"2018-03-15 21:48:25",
   "updated_at":"2018-03-15 21:48:25"
}

METHOD GET: /{admin_route_prefix}/poll/{id}

Get a poll json for admin

RETURN JSON

{
   "id":1,
   "title":"Who is the best football player in the world?",
   "type":"OrangeShadow\\Polls\\Types\\SingleVote",
   "active":1,
   "anonymous":0,
   "position":1,
   "closed_at":null,
   "created_at":"2018-03-15 21:48:25",
   "updated_at":"2018-03-15 21:48:25"
}

METHOD GET: /{public_route_prefix}/poll/{id}

Get a poll json for users

RETURN JSON

{
  poll: {
          "id":1,
          "title":"Who is the best football player in the world?",
          "type":"OrangeShadow\\Polls\\Types\\SingleVote",
          "active":1,
          "anonymous":0,
          "position":1,
          "closed_at":null,
          "created_at":"2018-03-15 21:48:25",
          "updated_at":"2018-03-15 21:48:25"
  },
  options:[
    {
      id: number,
      title: string
    }, ...
  ],
  results:{ 
    "option_id": {
      "title": string
      "voter_count": numeric,
      "total_weight":numeric,
      "percent":numeric
    },...
  }
  
}

METHOD PUT: /{admin_route_prefix}/poll/{id}

Update a poll

FORM-DATA PARAMS

active    : tinyint
anonymous : tinyint
position  : integer
title*    : string
type*     : string
closed_at : date
closed_at_from:date
closed_at_to: date

field with * are required

RETURN JSON

{
   "id":1,
   "title":"Who is the best football player in the world?",
   "type":"OrangeShadow\\Polls\\Types\\SingleVote",
   "active":1,
   "anonymous":0,
   "position":1,
   "closed_at":null,
   "created_at":"2018-03-15 21:48:25",
   "updated_at":"2018-03-15 21:48:25"
}

METHOD DELETE: /{admin_route_prefix}/poll/{id}

Delete a poll

RETURN JSON

{"success":true}

METHOD POST: /{public_route_prefix}/poll/{id}/vote

Make a vote

FORM-DATA PARAMS

options*: array

field with * are required

RETURN JSON

example response from  variable poll
{
  "success":true,
  "results": {
    "10": {
      "title":"Opportunities for professional development",
      "voter_count":1,
      "total_weight":6,
      "percent":100
    },
    "8": {
      "title":"The compensation and benefits offered",
      "voter_count":1,
      "total_weight":5,
      "percent":83.33
    },
    "9": {
      "title":"The languages, frameworks, and other technologies I'd be working with",
      "voter_count":1,
      "total_weight":4,
      "percent":66.67
    },
    "11": {
      "title":"The office environment or company culture",
      "voter_count":1,
      "total_weight":3,
      "percent":50
    },
    "13": {
      "title":"The industry that I'd be working in",
      "voter_count":1,"total_weight":2,"percent":33.33
    },
    "12": {
      "title":"The opportunity to work from home\/remotely",
      "voter_count":1,
      "total_weight":1,
      "percent":16.67
    }
  }
}