Class: AppleMusic::Client

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

Direct Known Subclasses

LibraryClient, StoreClient

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ Client



31
32
33
# File 'lib/client.rb', line 31

def initialize(token)
  @token = token
end

Instance Method Details

#get(resource) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/client.rb', line 35

def get(resource)
  response = HTTParty.get(
    "https://api.music.apple.com#{resource}",
    {headers: headers})

  if response.code == 200
    JSON.parse(response.body)
  else
    puts "NON 200 CODE for resource #{resource}"
    puts response
  end
end

#headersObject



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

def headers
  {
    'Authorization': "Bearer #{@token}"
  }
end

#post(resource) ⇒ Object



48
49
50
51
52
53
# File 'lib/client.rb', line 48

def post(resource)
  HTTParty.post(
    "https://api.music.apple.com#{resource}",
    {headers: headers}
  )
end