Class: Atradio::Agent

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

Overview

---- authenticated agent ----

Stations are passed as Hashes with camelCase keys (stationId, name, streamUrl, source, …), matching the wire record shape.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptr) ⇒ Agent

Returns a new instance of Agent.



111
112
113
# File 'lib/atradio.rb', line 111

def initialize(ptr)
  @ptr = ptr
end

Class Method Details

.login(session_path, identifier, password, appview: nil) ⇒ Object



102
103
104
105
106
107
108
109
# File 'lib/atradio.rb', line 102

def self.(session_path, identifier, password, appview: nil)
  ptr = C.(session_path, identifier, password, appview.to_s)
  if ptr.null?
    raise Error, (Atradio.take_string(C.atradio_last_error()) || "login failed")
  end

  new(ptr)
end

Instance Method Details

#closeObject

Release the native handle. The agent is unusable afterwards.



140
141
142
143
144
145
# File 'lib/atradio.rb', line 140

def close
  return if @ptr.null?

  C.atradio_agent_free(@ptr)
  @ptr = Fiddle::Pointer.new(0)
end

#comment(station, text) ⇒ Object



123
124
125
# File 'lib/atradio.rb', line 123

def comment(station, text)
  Atradio.unwrap(C.atradio_agent_comment(@ptr, JSON.generate(station), text))
end

#delete_play_statusObject



131
132
133
# File 'lib/atradio.rb', line 131

def delete_play_status
  Atradio.unwrap(C.atradio_agent_delete_play_status(@ptr))
end

#favorite(station) ⇒ Object



115
116
117
# File 'lib/atradio.rb', line 115

def favorite(station)
  Atradio.unwrap(C.atradio_agent_favorite(@ptr, JSON.generate(station)))
end

#refresh_sessionObject



135
136
137
# File 'lib/atradio.rb', line 135

def refresh_session
  Atradio.unwrap(C.atradio_agent_refresh_session(@ptr))
end

#set_play_status(station) ⇒ Object



127
128
129
# File 'lib/atradio.rb', line 127

def set_play_status(station)
  Atradio.unwrap(C.atradio_agent_set_play_status(@ptr, JSON.generate(station)))
end

#unfavorite(station) ⇒ Object



119
120
121
# File 'lib/atradio.rb', line 119

def unfavorite(station)
  Atradio.unwrap(C.atradio_agent_unfavorite(@ptr, JSON.generate(station)))
end