Class: Marvellous::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/marvellous/client.rb

Defined Under Namespace

Classes: InvalidRouteError

Constant Summary collapse

DEF_PAGE_SIZE =
10
DEF_PAGE_NUM =
1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Client

Returns a new instance of Client.



13
14
15
16
17
18
# File 'lib/marvellous/client.rb', line 13

def initialize(options)
  @public_key = options[:public_key]
  @private_key = options[:private_key]
  @prefix = '/v1/public'
  @routes = Marvellous::ROUTES
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/marvellous/client.rb', line 66

def method_missing(method, *args, &block)
  if routes.keys.include?(method)
    params = args[0] || {}
    endpoint = build_uri(method, params)
    page_hash = (routes[method][:collection] rescue false) ? paginate(params) : {}
    response = fetch_response(endpoint, page_hash)
    build_response_object(response)
  else
    raise InvalidRouteError, "#{method} is not defined in the routes."
  end
end

Instance Attribute Details

#private_keyObject

Returns the value of attribute private_key.



6
7
8
# File 'lib/marvellous/client.rb', line 6

def private_key
  @private_key
end

#public_keyObject

Returns the value of attribute public_key.



6
7
8
# File 'lib/marvellous/client.rb', line 6

def public_key
  @public_key
end