Class: RedboothRuby::Client

Inherits:
Object
  • Object
show all
Includes:
RedboothRuby::ClientOperations::Metadata, RedboothRuby::ClientOperations::Search, Helpers
Defined in:
lib/redbooth-ruby/client.rb

Constant Summary collapse

RESOURCES =
[ :me, :user, :task, :organization, :person, :project,
:conversation, :membership, :comment, :note, :subtask,
:file, :task_list ]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#camelize, #underscore

Methods included from RedboothRuby::ClientOperations::Metadata

#metadata

Methods included from RedboothRuby::ClientOperations::Search

#search

Constructor Details

#initialize(session, options = {}) ⇒ Client

Creates an client object using the given Redbooth session. existing account.

Parameters:

  • session (Redbooth::Session)

    redbooth session object with the correct authorization

  • options (Hash) (defaults to: {})

    client options

Options Hash (options):

  • retry (Proc) — default: the client will handle

    Retry block to be executed when client hits an async endpoint

Raises:



19
20
21
22
23
24
# File 'lib/redbooth-ruby/client.rb', line 19

def initialize(session, options={})
  raise RedboothRuby::AuthenticationError unless session.valid?
  @session = session
  @options = options
  self
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/redbooth-ruby/client.rb', line 11

def options
  @options
end

#sessionObject (readonly)

Returns the value of attribute session.



11
12
13
# File 'lib/redbooth-ruby/client.rb', line 11

def session
  @session
end

Instance Method Details

#resourceObject

Metaprograming of every resource to execute it over the perform! method just to add session tho the resource

Examples:

session = RedboothRuby::Session.new(api_key: '_your_api_key_', auth_token: '_aut_token_for_the_user')
client = RedboothRuby::Client.new(session)
client.user.show # returns user profile
client.files.all

Parameters:

  • action (String||Symbol)

    name of the action to execute over

  • options (Hash)

    for the execution

Returns:

  • the execution return or nil



39
40
41
42
43
44
45
# File 'lib/redbooth-ruby/client.rb', line 39

RESOURCES.each do |resource|
  eval %{
    def #{resource.to_s}(action, options={})
      perform!(:#{resource.to_s}, action, options)
    end
  }
end