Class: AudioAddict::API
- Inherits:
-
Object
show all
- Includes:
- Cache, HTTParty
- Defined in:
- lib/audio_addict/api.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Cache
#cache, #cache_dir, #cache_dir!, #cache_life, #cache_life!
Constructor Details
#initialize(network) ⇒ API
Returns a new instance of API.
14
15
16
|
# File 'lib/audio_addict/api.rb', line 14
def initialize(network)
@network = network
end
|
Instance Attribute Details
#network ⇒ Object
Returns the value of attribute network.
12
13
14
|
# File 'lib/audio_addict/api.rb', line 12
def network
@network
end
|
Instance Method Details
#basic_auth ⇒ Object
43
44
45
|
# File 'lib/audio_addict/api.rb', line 43
def basic_auth
http.basic_auth 'streams', 'diradio'
end
|
#delete(path, args = {}) ⇒ Object
35
36
37
|
# File 'lib/audio_addict/api.rb', line 35
def delete(path, args = {})
response http.delete "/#{network}/#{path}", headers: , body: args
end
|
#get(path, args = {}) ⇒ Object
27
28
29
|
# File 'lib/audio_addict/api.rb', line 27
def get(path, args = {})
response http.get "/#{network}/#{path}", headers: , body: args
end
|
#listen_key ⇒ Object
57
58
59
|
# File 'lib/audio_addict/api.rb', line 57
def listen_key
Config.listen_key
end
|
#logged_in? ⇒ Boolean
39
40
41
|
# File 'lib/audio_addict/api.rb', line 39
def logged_in?
session_key and listen_key
end
|
#login(username, password) ⇒ Object
18
19
20
21
22
23
24
25
|
# File 'lib/audio_addict/api.rb', line 18
def login(username, password)
session = session(username, password)
Config.session_key = session['key']
Config.listen_key = session['member']['listen_key']
Config.email = session['member']['email']
Config.premium = session['member']['user_type'] == 'premium'
Config.save
end
|
#post(path, args = {}) ⇒ Object
31
32
33
|
# File 'lib/audio_addict/api.rb', line 31
def post(path, args = {})
response http.post "/#{network}/#{path}", headers: , body: args
end
|
#session(username, password) ⇒ Object
47
48
49
50
51
|
# File 'lib/audio_addict/api.rb', line 47
def session(username, password)
params = { member_session: { username: username, password: password } }
basic_auth
response http.post "/#{network || 'di'}/member_sessions", body: params
end
|
#session_key ⇒ Object
53
54
55
|
# File 'lib/audio_addict/api.rb', line 53
def session_key
Config.session_key
end
|