Module: Bandshell::HardwareApi
- Defined in:
- lib/bandshell/hardware_api.rb
Class Attribute Summary collapse
-
.screen_id ⇒ Object
readonly
Returns the value of attribute screen_id.
-
.screen_url ⇒ Object
readonly
Returns the value of attribute screen_url.
Class Method Summary collapse
-
.attempt_to_get_screen_data! ⇒ Object
Can return: :stat_badauth :stat_err :stat_serverr on connection or sever failure :stat_badauth on an invalid permanent token :stat_success when screen data retrieved.
- .auth_token ⇒ Object
- .concerto_url ⇒ Object
- .frontend_api_uri ⇒ Object
- .frontend_uri ⇒ Object
-
.get_player_info ⇒ Object
Fetch player settings from concerto-hardware TODO: clean up errors/ return values.
- .have_auth_token? ⇒ Boolean
- .have_temp_token? ⇒ Boolean
- .temp_token ⇒ Object
Class Attribute Details
.screen_id ⇒ Object (readonly)
Returns the value of attribute screen_id.
38 39 40 |
# File 'lib/bandshell/hardware_api.rb', line 38 def screen_id @screen_id end |
.screen_url ⇒ Object (readonly)
Returns the value of attribute screen_url.
38 39 40 |
# File 'lib/bandshell/hardware_api.rb', line 38 def screen_url @screen_url end |
Class Method Details
.attempt_to_get_screen_data! ⇒ Object
Can return:
:stat_badauth
:stat_err
:stat_serverr on connection or sever failure
:stat_badauth on an invalid permanent token
:stat_success when screen data retrieved.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/bandshell/hardware_api.rb', line 46 def attempt_to_get_screen_data! unless have_temp_token? or have_auth_token? request_temp_token! end unless have_auth_token? tt_status = check_temp_token! return tt_status unless tt_status == :stat_success end if have_auth_token? status = fetch_screen_data if status == :stat_badauth ConfigStore.write_config('auth_token','') request_temp_token! end elsif have_temp_token? status = :stat_temponly else status = :stat_err end status end |
.auth_token ⇒ Object
12 13 14 |
# File 'lib/bandshell/hardware_api.rb', line 12 def auth_token Bandshell::ConfigStore.read_config('auth_token') end |
.concerto_url ⇒ Object
16 17 18 19 20 |
# File 'lib/bandshell/hardware_api.rb', line 16 def concerto_url # Trailing slash required for proper URI Join behavior. # Double slashes not harmful. Bandshell::ConfigStore.read_config('concerto_url', '')+"/" end |
.frontend_api_uri ⇒ Object
26 27 28 |
# File 'lib/bandshell/hardware_api.rb', line 26 def frontend_api_uri URI::join(concerto_url,'frontend.json') end |
.frontend_uri ⇒ Object
22 23 24 |
# File 'lib/bandshell/hardware_api.rb', line 22 def frontend_uri URI::join(concerto_url,'frontend') end |
.get_player_info ⇒ Object
Fetch player settings from concerto-hardware TODO: clean up errors/ return values
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/bandshell/hardware_api.rb', line 204 def get_player_info return nil if auth_token.empty? # Try to do this in one GET. player_info_uri = URI::join(concerto_url,'hardware/', 'players/','current.json') response = get_with_auth(player_info_uri, 'screen', auth_token) if response.nil? return :stat_serverr end if response.code != "200" return :stat_serverr end begin data = JSON.parse(response.body) if data.has_key? 'screen_on_off' # We actually got some data return data else return :stat_badauth end rescue return :stat_serverr end end |
.have_auth_token? ⇒ Boolean
34 35 36 |
# File 'lib/bandshell/hardware_api.rb', line 34 def have_auth_token? !auth_token.empty? end |
.have_temp_token? ⇒ Boolean
30 31 32 |
# File 'lib/bandshell/hardware_api.rb', line 30 def have_temp_token? !temp_token.empty? end |
.temp_token ⇒ Object
8 9 10 |
# File 'lib/bandshell/hardware_api.rb', line 8 def temp_token Bandshell::ConfigStore.read_config('auth_temp_token') end |