Class: Rushover::Client
- Inherits:
-
Object
- Object
- Rushover::Client
- Defined in:
- lib/rushover.rb
Constant Summary collapse
- MESSAGES_ENDPOINT =
"https://api.pushover.net/1/messages.json".freeze
- VALIDATE_ENDPOINT =
"https://api.pushover.net/1/users/validate.json".freeze
Instance Attribute Summary collapse
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
-
#initialize(token) ⇒ Client
constructor
A new instance of Client.
- #notify(user_key, message, options = {}) ⇒ Object
- #validate(user_key, device = nil) ⇒ Object
- #validate!(user_key, device = nil) ⇒ Object
Constructor Details
#initialize(token) ⇒ Client
Returns a new instance of Client.
12 13 14 |
# File 'lib/rushover.rb', line 12 def initialize(token) @token = token end |
Instance Attribute Details
#token ⇒ Object
Returns the value of attribute token.
10 11 12 |
# File 'lib/rushover.rb', line 10 def token @token end |
Instance Method Details
#notify(user_key, message, options = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rushover.rb', line 16 def notify(user_key, , = {}) data = { :token => token, :user => user_key, :message => } data.merge!() raw_response = begin RestClient.post MESSAGES_ENDPOINT, data.to_json, :content_type => "application/json" rescue RestClient::Exception => e e.response end Response.new JSON.parse(raw_response) end |
#validate(user_key, device = nil) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rushover.rb', line 29 def validate(user_key, device = nil) data = { :token => token, :user => user_key } data[:device] = device if device raw_response = begin RestClient.post VALIDATE_ENDPOINT, data.to_json, :content_type => "application/json" rescue RestClient::Exception => e e.response end Response.new JSON.parse(raw_response) end |
#validate!(user_key, device = nil) ⇒ Object
42 43 44 |
# File 'lib/rushover.rb', line 42 def validate!(user_key, device = nil) validate(user_key, device).ok? end |