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.
7 8 9 10 11 12 13 |
# File 'lib/beaconpush/client.rb', line 7 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.
5 6 7 |
# File 'lib/beaconpush/client.rb', line 5 def host @host end |
#key ⇒ Object
Returns the value of attribute key.
5 6 7 |
# File 'lib/beaconpush/client.rb', line 5 def key @key end |
#port ⇒ Object
Returns the value of attribute port.
5 6 7 |
# File 'lib/beaconpush/client.rb', line 5 def port @port end |
#secret ⇒ Object
Returns the value of attribute secret.
5 6 7 |
# File 'lib/beaconpush/client.rb', line 5 def secret @secret end |
#version ⇒ Object
Returns the value of attribute version.
5 6 7 |
# File 'lib/beaconpush/client.rb', line 5 def version @version end |
Instance Method Details
#channel_message(channel, message) ⇒ Object
34 35 36 |
# File 'lib/beaconpush/client.rb', line 34 def (channel, ) request("POST", "/channels/#{channel}", .to_json)["messages_sent"] end |
#channel_users(channel) ⇒ Object
38 39 40 |
# File 'lib/beaconpush/client.rb', line 38 def channel_users(channel) request("GET", "/channels/#{channel}")["users"] end |
#user_logout(user) ⇒ Object
26 27 28 |
# File 'lib/beaconpush/client.rb', line 26 def user_logout(user) request("DELETE", "/users/#{user}") end |
#user_message(user, message) ⇒ Object
30 31 32 |
# File 'lib/beaconpush/client.rb', line 30 def (user, ) request("POST", "/users/#{user}", .to_json)["messages_sent"] end |
#user_online?(user) ⇒ Boolean
19 20 21 22 23 24 |
# File 'lib/beaconpush/client.rb', line 19 def user_online?(user) request("GET", "/users/#{user}") true rescue ResponseError => e (e.response.code.to_i == 404) ? false : raise end |
#users_count ⇒ Object
15 16 17 |
# File 'lib/beaconpush/client.rb', line 15 def users_count request("GET", "/users")["online"] end |