Class: Yummly::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/yummly/connection.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.adapterObject



18
19
20
# File 'lib/yummly/connection.rb', line 18

def adapter
  @adapter || Yummly::FaradayAdapter
end

Class Method Details

.api_connectionObject



14
15
16
# File 'lib/yummly/connection.rb', line 14

def api_connection
  adapter.connection(UrlBuilder.domain)
end

.get(command, params = {}) ⇒ Object



9
10
11
12
# File 'lib/yummly/connection.rb', line 9

def get(command, params = {})
  response = self.api_connection.get(UrlBuilder.uri(command, params))
  self.parse_response(response)
end

.parse_response(response) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/yummly/connection.rb', line 22

def parse_response(response)
  case response.status
    when 409 then
      raise Yummly::PermissionError, response.body
    when 404 then
      nil
    when 200 then
      JSON.parse(response.body)
    when 501 then
      raise Yummly::NotImplementedError, response.body
  end
end