Module: Coop

Includes:
HTTParty
Defined in:
lib/coop.rb,
lib/coop/error.rb,
lib/coop/session.rb,
lib/coop/version.rb,
lib/coop/api_object.rb,
lib/coop/api_object/user.rb,
lib/coop/api_object/group.rb,
lib/coop/api_object/agenda.rb,
lib/coop/api_object/status.rb

Defined Under Namespace

Classes: APIObject, Agenda, BadRequest, Error, Group, InternalServerError, NotFound, ServiceUnavailable, Session, Status, Unauthorized, User

Constant Summary collapse

VERSION =
"1.1.1"

Class Method Summary collapse

Class Method Details

.get_parsed(*args) ⇒ Object

Public: Parse an HTTParty response into APIObjects

*args - any valid arguments for HTTParty.get

Examples

Coop.get_parsed("/groups/12345")
# => [{"type" => "Note", "users" => ...}]

Returns Array of APIObjects or APIObject, depending on response argument



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/coop.rb', line 39

def get_parsed(*args)
  begin
    request = self.get(*args)

    raise BadRequest if request.response.code == "400"
    raise Unauthorized if request.response.code == "401"
    raise NotFound if request.response.code == "404"
    raise InternalServerError if request.response.code == "500"
    raise ServiceUnavailable if request.response.code == "503"

    APIObject.parse_response(request)
  end
end

.new(email, password) ⇒ Object

Public: Shortcut for creating a new Coop::Session for API stuff

email - (String) the user’s email password - (String) the user’s password

Examples

Coop.new("[email protected]", "password123")
# => #<Coop::Session @email="[email protected]">

Returns an authenticated Coop::Session object



24
25
26
27
# File 'lib/coop.rb', line 24

def new(email, password)
  basic_auth email, password
  Coop::Session.new(email, password)
end