Class: GoPollGo::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/gopollgo.rb

Instance Method Summary collapse

Constructor Details

#initialize(key = nil) ⇒ Client

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.



20
21
22
# File 'lib/gopollgo.rb', line 20

def initialize(key=nil)
  @key = key
end

Instance Method Details

#create_poll(poll) ⇒ Object

Create a poll on GoPollGo



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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 [email protected]"
    else
      raise UnknownResponseCode, "Unexpected Status: #{response.code}"
  end
end