class GoPollGo::Client

Public Class Methods

new(key=nil) click to toggle source

In order to use the write portions of the API, you’ll need an API key. If this is left blank, you’ll still be able to use read-only portions of the API.

# File lib/gopollgo.rb, line 20
def initialize(key=nil)
  @key = key
end

Public Instance Methods

create_poll(poll) click to toggle source

Create a poll on GoPollGo

# File lib/gopollgo.rb, line 25
def create_poll(poll)
  response = self.class.post('/polls',
    :query => { :key => @key },
    :body  => {
      :question => poll[:question],
      :options  => poll[:options]
    }
  )
  
  case response.code
    when 200
      return JSON.parse(response.body)
    when 400
      raise BadArguments, "Bad Arguments.  Please check your poll parameters."
    when 401
      raise Unauthorized, "Access denied.  Check your API key."
    when 500
      raise GoPollGoError, "GoPollGo Internal Error.  Please try again in a second.  If this persists, please contact dev@gopollgo.com"
    else
      raise UnknownResponseCode, "Unexpected Status: #{response.code}"
  end
end