Class: Beaconpush::Client
- Inherits:
-
Object
- Object
- Beaconpush::Client
- Defined in:
- lib/beaconpush/client.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#key ⇒ Object
Returns the value of attribute key.
-
#port ⇒ Object
Returns the value of attribute port.
-
#secret ⇒ Object
Returns the value of attribute secret.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
- #channel_message(channel, message) ⇒ Object
- #channel_users(channel) ⇒ Object
-
#initialize(options) ⇒ Client
constructor
A new instance of Client.
- #user_logout(user) ⇒ Object
- #user_message(user, message) ⇒ Object
- #user_online?(user) ⇒ Boolean
- #users_count ⇒ Object
Constructor Details
#initialize(options) ⇒ Client
Returns a new instance of Client.
5 6 7 8 9 10 11 |
# File 'lib/beaconpush/client.rb', line 5 def initialize() self.key = .fetch(:key, Beaconpush.key) || raise(ArgumentError, "No key given") self.secret = .fetch(:secret, Beaconpush.secret) || raise(ArgumentError, "No secret given") self.version = .fetch(:version, Beaconpush.version) || raise(ArgumentError, "No API version given") self.host = .fetch(:host, Beaconpush.host) || raise(ArgumentError, "No Beacon host given") self.port = .fetch(:port, Beaconpush.port) || raise(ArgumentError, "No Beacon port given") end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
3 4 5 |
# File 'lib/beaconpush/client.rb', line 3 def host @host end |
#key ⇒ Object
Returns the value of attribute key.
3 4 5 |
# File 'lib/beaconpush/client.rb', line 3 def key @key end |
#port ⇒ Object
Returns the value of attribute port.
3 4 5 |
# File 'lib/beaconpush/client.rb', line 3 def port @port end |
#secret ⇒ Object
Returns the value of attribute secret.
3 4 5 |
# File 'lib/beaconpush/client.rb', line 3 def secret @secret end |
#version ⇒ Object
Returns the value of attribute version.
3 4 5 |
# File 'lib/beaconpush/client.rb', line 3 def version @version end |
Instance Method Details
#channel_message(channel, message) ⇒ Object
32 33 34 |
# File 'lib/beaconpush/client.rb', line 32 def (channel, ) request("POST", "/channels/#{channel}", .to_json)["messages_sent"] end |
#channel_users(channel) ⇒ Object
36 37 38 |
# File 'lib/beaconpush/client.rb', line 36 def channel_users(channel) request("GET", "/channels/#{channel}")["users"] end |
#user_logout(user) ⇒ Object
24 25 26 |
# File 'lib/beaconpush/client.rb', line 24 def user_logout(user) request("DELETE", "/users/#{user}") end |
#user_message(user, message) ⇒ Object
28 29 30 |
# File 'lib/beaconpush/client.rb', line 28 def (user, ) request("POST", "/users/#{user}", .to_json)["messages_sent"] end |
#user_online?(user) ⇒ Boolean
17 18 19 20 21 22 |
# File 'lib/beaconpush/client.rb', line 17 def user_online?(user) request("GET", "/users/#{user}") true rescue ResponseError => e (e.response.code.to_i == 404) ? false : raise end |
#users_count ⇒ Object
13 14 15 |
# File 'lib/beaconpush/client.rb', line 13 def users_count request("GET", "/users")["online"] end |