Class: Harkness::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/harkness/client.rb

Constant Summary collapse

BASE_URL =

The base URL for the Marvel API.

"https://gateway.marvel.com/v1/public"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(public_key:, private_key:, logger: false) ⇒ Client

Initialize a client.

Parameters:

  • public_key (String)

    the public key for the Marvel API.

  • private_key (String)

    the private key for the Marvel API.

  • logger (Boolean) (defaults to: false)

    enable Faraday request logging.



19
20
21
22
23
# File 'lib/harkness/client.rb', line 19

def initialize(public_key:, private_key:, logger: false)
  @public_key = public_key
  @private_key = private_key
  @logger = logger
end

Instance Attribute Details

#private_keyString (readonly)

The private key for the Marvel API.

Returns:

  • (String)

    the private key for the Marvel API.



13
14
15
# File 'lib/harkness/client.rb', line 13

def private_key
  @private_key
end

#public_keyString (readonly)

The public key for the Marvel API.

Returns:

  • (String)

    the public key for the Marvel API.



10
11
12
# File 'lib/harkness/client.rb', line 10

def public_key
  @public_key
end

Instance Method Details

#charactersHarkness::CharacterResource

The character resource.

Returns:



27
28
29
# File 'lib/harkness/client.rb', line 27

def characters
  CharacterResource.new(self)
end

#comicsHarkness::ComicResource

The comics resource.

Returns:



33
34
35
# File 'lib/harkness/client.rb', line 33

def comics
  ComicResource.new(self)
end

#connectionObject

The Faraday connection to use for API requests.



62
63
64
65
66
67
68
# File 'lib/harkness/client.rb', line 62

def connection
  @connection ||= Faraday.new(BASE_URL) do |conn|
    conn.request :json

    conn.response :logger if @logger
  end
end

#creatorsHarkness::CreatorResource

The creators resource.

Returns:



39
40
41
# File 'lib/harkness/client.rb', line 39

def creators
  CreatorResource.new(self)
end

#eventsHarkness::EventResource

The events resource.

Returns:



45
46
47
# File 'lib/harkness/client.rb', line 45

def events
  EventResource.new(self)
end

#seriesHarkness::SeriesResource

The series resource.

Returns:



51
52
53
# File 'lib/harkness/client.rb', line 51

def series
  SeriesResource.new(self)
end

#storiesHarkness::StoryResource

The stories resource.

Returns:



57
58
59
# File 'lib/harkness/client.rb', line 57

def stories
  StoryResource.new(self)
end