Class: Marvel::Api

Inherits:
Object
  • Object
show all
Includes:
ApiMethods
Defined in:
lib/marvel/api.rb,
lib/marvel/api/request.rb,
lib/marvel/api/version.rb,
lib/marvel/api/response.rb,
lib/marvel/api/api_methods.rb,
lib/marvel/api/http_service.rb

Defined Under Namespace

Modules: ApiMethods, HTTPService Classes: Request, Response

Constant Summary collapse

DEFAULT_SERVER =
'http://gateway.marvel.com'.freeze
VERSION =
'0.1.0'.freeze

Constants included from ApiMethods

ApiMethods::METHODS, ApiMethods::SUBMETHODS

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(public_key, private_key, options = {}) ⇒ Api

Returns a new instance of Api.



21
22
23
24
25
# File 'lib/marvel/api.rb', line 21

def initialize(public_key, private_key, options = {})
  @public_key = public_key
  @private_key = private_key
  @options = options
end

Class Attribute Details

.http_serviceObject

Returns the value of attribute http_service.



12
13
14
# File 'lib/marvel/api.rb', line 12

def http_service
  @http_service
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



19
20
21
# File 'lib/marvel/api.rb', line 19

def options
  @options
end

#private_keyObject (readonly)

Returns the value of attribute private_key.



19
20
21
# File 'lib/marvel/api.rb', line 19

def private_key
  @private_key
end

#public_keyObject (readonly)

Returns the value of attribute public_key.



19
20
21
# File 'lib/marvel/api.rb', line 19

def public_key
  @public_key
end

Instance Method Details

#api_call(path, args, options = {}) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/marvel/api.rb', line 27

def api_call(path, args, options = {})
  request = Request.new(
    path: path,
    args: args.merge(apikey: public_key, ts: ts, hash: request_hash),
    options: options
  )
  self.class.http_service.make_request(request)
end

#comics(args = {}) ⇒ Object



36
37
38
# File 'lib/marvel/api.rb', line 36

def comics(args = {})
  api_call('comics', args)
end