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
13
14
15
|
# File 'lib/audio_addict/api.rb', line 13
def initialize(network)
@network = network
end
|
Instance Attribute Details
#network ⇒ Object
Returns the value of attribute network.
11
12
13
|
# File 'lib/audio_addict/api.rb', line 11
def network
@network
end
|
Instance Method Details
#basic_auth ⇒ Object
42
43
44
|
# File 'lib/audio_addict/api.rb', line 42
def basic_auth
http.basic_auth 'streams', 'diradio'
end
|
#delete(path, args = {}) ⇒ Object
34
35
36
|
# File 'lib/audio_addict/api.rb', line 34
def delete(path, args = {})
response http.delete "/#{network}/#{path}", headers: , body: args
end
|
#get(path, args = {}) ⇒ Object
26
27
28
|
# File 'lib/audio_addict/api.rb', line 26
def get(path, args = {})
response http.get "/#{network}/#{path}", headers: , body: args
end
|
#listen_key ⇒ Object
56
57
58
|
# File 'lib/audio_addict/api.rb', line 56
def listen_key
Config.listen_key
end
|
#logged_in? ⇒ Boolean
38
39
40
|
# File 'lib/audio_addict/api.rb', line 38
def logged_in?
session_key and listen_key
end
|
#login(username, password) ⇒ Object
17
18
19
20
21
22
23
24
|
# File 'lib/audio_addict/api.rb', line 17
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
30
31
32
|
# File 'lib/audio_addict/api.rb', line 30
def post(path, args = {})
response http.post "/#{network}/#{path}", headers: , body: args
end
|
#session(username, password) ⇒ Object
46
47
48
49
50
|
# File 'lib/audio_addict/api.rb', line 46
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
52
53
54
|
# File 'lib/audio_addict/api.rb', line 52
def session_key
Config.session_key
end
|