Class: HookTheory::Client

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

Constant Summary collapse

BASE_URI =
"https://api.hooktheory.com/v1/"
InvalidUsernameOrPassword =
Class.new(StandardError)
InvalidRequest =
Class.new(StandardError)

Instance Method Summary collapse

Constructor Details

#initialize(username:, password:) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
15
# File 'lib/hooktheory/client.rb', line 10

def initialize(username:, password:)
  @username = username
  @password = password
  @headers = { "Accept" => "application/json", "Content-Type" => "application/json" }
  grab_auth
end

Instance Method Details

#nodes(progression: []) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/hooktheory/client.rb', line 28

def nodes(progression: [])
  response = http_get(
    endpoint: "trends/nodes",
    request_params: {
      cp: progression.join(","),
    })

  response.map { |node| HookTheory::Node.new(node) }
end

#songs(progression: [], page: 1) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/hooktheory/client.rb', line 17

def songs(progression: [], page: 1)
  response = http_get(
    endpoint: "trends/songs",
    request_params: {
      cp: progression.join(","),
      page: page
    })

  response.map { |song| HookTheory::Song.new(song) }
end