Class: Beacon
- Inherits:
-
Object
- Object
- Beacon
- Defined in:
- lib/ruby-beaconpush.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#host ⇒ Object
Returns the value of attribute host.
-
#secret_key ⇒ Object
Returns the value of attribute secret_key.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
-
#initialize(api_key, secret_key, options = {}) ⇒ Beacon
constructor
A new instance of Beacon.
- #logout(username) ⇒ Object
- #online?(username) ⇒ Boolean
- #publish(channel, data) ⇒ Object
- #users(channel) ⇒ Object
- #users_count ⇒ Object
- #whisper(username, data) ⇒ Object
Constructor Details
#initialize(api_key, secret_key, options = {}) ⇒ Beacon
Returns a new instance of Beacon.
9 10 11 12 13 14 15 16 |
# File 'lib/ruby-beaconpush.rb', line 9 def initialize(api_key, secret_key, = {}) @api_key = api_key @secret_key = secret_key @host = [:host] || 'api.beaconpush.com' @headers = [:headers] || {} @version = [:version] || '1.0.0' end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
6 7 8 |
# File 'lib/ruby-beaconpush.rb', line 6 def api_key @api_key end |
#host ⇒ Object
Returns the value of attribute host.
6 7 8 |
# File 'lib/ruby-beaconpush.rb', line 6 def host @host end |
#secret_key ⇒ Object
Returns the value of attribute secret_key.
6 7 8 |
# File 'lib/ruby-beaconpush.rb', line 6 def secret_key @secret_key end |
#version ⇒ Object
Returns the value of attribute version.
6 7 8 |
# File 'lib/ruby-beaconpush.rb', line 6 def version @version end |
Instance Method Details
#logout(username) ⇒ Object
37 38 39 40 |
# File 'lib/ruby-beaconpush.rb', line 37 def logout(username) RestClient.delete("#{base_url}/users/#{username}", headers) username end |
#online?(username) ⇒ Boolean
31 32 33 34 |
# File 'lib/ruby-beaconpush.rb', line 31 def online?(username) response = RestClient.get("#{base_url}/users/#{username}", headers) JSON.load(response)['status'] == 200 end |
#publish(channel, data) ⇒ Object
19 20 21 22 |
# File 'lib/ruby-beaconpush.rb', line 19 def publish(channel, data) RestClient.post("#{base_url}/channels/#{channel}", JSON.dump(data), headers) data end |
#users(channel) ⇒ Object
43 44 45 46 |
# File 'lib/ruby-beaconpush.rb', line 43 def users(channel) response = RestClient.get("#{base_url}/channels/#{channel}", headers) JSON.load(response)['users'] end |
#users_count ⇒ Object
25 26 27 28 |
# File 'lib/ruby-beaconpush.rb', line 25 def users_count response = RestClient.get("#{base_url}/users", headers) JSON.load(response)['online'] end |
#whisper(username, data) ⇒ Object
49 50 51 52 |
# File 'lib/ruby-beaconpush.rb', line 49 def whisper(username, data) RestClient.post("#{base_url}/users/#{username}", JSON.dump(data), headers) data end |