Class: Camper::Client

Inherits:
Object
  • Object
show all
Includes:
Calendars, Events, People, Projects, Connection
Defined in:
lib/camper/client.rb,
lib/camper/client/people.rb,
lib/camper/client/events.rb,
lib/camper/client/projects.rb,
lib/camper/client/calendars.rb

Defined Under Namespace

Modules: Calendars, Events, People, Projects

Constant Summary

Constant Summary

Constants included from Connection

Camper::Connection::DEFAULT_HEADERS

Instance Attribute Summary

Attributes included from Connection

#id, #password, #token, #token_secret, #username

Instance Method Summary (collapse)

Methods included from Projects

#archived_projects, #create_project!, #project, #projects

Methods included from People

#me, #people, #person

Methods included from Events

#events

Methods included from Calendars

#calendar, #calendars, #create_calendar!

Methods included from Connection

#api_url, #connection, #delete, #get, #post, #put, #setup, #status

Instance Method Details

- (Class, ...) handle(klass, response)

Handles a Faraday response with APIObject creation

Parameters:

  • klass (Class)

    the class the response items need to be converted to

  • response (Faraday::Response)

    the raw response object from Faraday

Returns:

  • (Class, Array, false)

    If response is success, if a singular item, it returns an object of the class specified. If an array, it returns an array of the class specified. If response is unsuccessful, returns false



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/camper/client.rb', line 21

def handle(klass, response)
  if response.success?
    if response.body.is_a? Hash
      output = klass.new(self, response.body)
    elsif response.body.is_a? Array
      output = []
      response.body.each do |item|
        output << klass.new(self, item)
      end
    end

    output
  else
    false
  end
end