Class: Iknow::RestClient::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/iknow/rest_client/base.rb

Direct Known Subclasses

Item, List, Sentence, User

Defined Under Namespace

Classes: RESTError

Class Method Summary collapse

Class Method Details

.http_method(action) ⇒ Object



20
# File 'lib/iknow/rest_client/base.rb', line 20

def self.http_method(action)   ; self::ACTIONS[action.to_sym][:http_method] || :get end

.method_missing(action, *args) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/iknow/rest_client/base.rb', line 22

def self.method_missing(action, *args)
  # GET methods are handled here
  # POST and DELETE methods should be implemented in each class
  super unless self.valid_action?(action)
  case self.http_method(action)
  when :get
    path, params = path_with_params(self.path(action), args[0])
    http_get(path, params)
  when :post
    path, params = path_with_params(self.path(action), args[1])
    http_post(iknow_auth(args[0]), path, params)
  when :delete
    path, params = path_with_params(self.path(action), args[1])
    http_delete(iknow_auth(args[0]), path, params)
  end
end

.path(action) ⇒ Object



19
# File 'lib/iknow/rest_client/base.rb', line 19

def self.path(action)          ; self::ACTIONS[action.to_sym][:path]                end

.valid_action?(action) ⇒ Boolean

Returns:

  • (Boolean)


18
# File 'lib/iknow/rest_client/base.rb', line 18

def self.valid_action?(action) ; self::ACTIONS.keys.include? action.to_sym          end