Class: Smartfm::RestClient::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/smartfm/rest_clients/base.rb

Direct Known Subclasses

Item, Like, List, Notification, Sentence, User

Defined Under Namespace

Classes: RESTError

Class Method Summary collapse

Class Method Details

.http_method(action) ⇒ Object



20
# File 'lib/smartfm/rest_clients/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
38
39
40
41
42
# File 'lib/smartfm/rest_clients/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
    if args[0].is_a?(Smartfm::Auth)
      path, params = path_with_params(self.path(action), args[1])
      http_get_with_auth(auth(args[0]), path, params)
    else
      path, params = path_with_params(self.path(action), args[0])
      http_get(path, params)
    end
  when :post
    path, params = path_with_params(self.path(action), args[1])
    http_post(auth(args[0]), path, params)
  when :delete
    path, params = path_with_params(self.path(action), args[1])
    http_delete(auth(args[0]), path, params)
  end
end

.path(action) ⇒ Object



19
# File 'lib/smartfm/rest_clients/base.rb', line 19

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

.valid_action?(action) ⇒ Boolean

Returns:

  • (Boolean)


18
# File 'lib/smartfm/rest_clients/base.rb', line 18

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