Class: Pushbots::Device
- Inherits:
-
Object
- Object
- Pushbots::Device
- Defined in:
- lib/pushbots/device.rb
Overview
Device class
Constant Summary collapse
- PLATFORM_TYPE =
{ ios: 0, android: 1, chrome: 2 }.freeze
- PLATFORM_TYPE_R =
[:ios, :android, :chrome].freeze
Instance Attribute Summary collapse
-
#platform ⇒ Object
Returns the value of attribute platform.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
- #delete ⇒ Object
- #info ⇒ Object
-
#initialize(token, platform = nil) ⇒ Device
constructor
A new instance of Device.
- #register ⇒ Object
Constructor Details
#initialize(token, platform = nil) ⇒ Device
Returns a new instance of Device.
8 9 10 11 |
# File 'lib/pushbots/device.rb', line 8 def initialize(token, platform = nil) self.token = token self.platform = platform if platform end |
Instance Attribute Details
#platform ⇒ Object
Returns the value of attribute platform.
4 5 6 |
# File 'lib/pushbots/device.rb', line 4 def platform @platform end |
#tags ⇒ Object
Returns the value of attribute tags.
4 5 6 |
# File 'lib/pushbots/device.rb', line 4 def @tags end |
#token ⇒ Object
Returns the value of attribute token.
4 5 6 |
# File 'lib/pushbots/device.rb', line 4 def token @token end |
Instance Method Details
#delete ⇒ Object
28 29 30 31 32 |
# File 'lib/pushbots/device.rb', line 28 def delete body = { token: token, platform: PLATFORM_TYPE[platform] } response = Request.delete(body) response.code == 200 end |
#info ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/pushbots/device.rb', line 13 def info response = Request.info(token) if response.code == 200 http_response = JSON.parse(response) self.platform = PLATFORM_TYPE_R[http_response['platform']] self. = http_response['tags'] end end |
#register ⇒ Object
22 23 24 25 26 |
# File 'lib/pushbots/device.rb', line 22 def register body = { token: token, platform: PLATFORM_TYPE[platform] } response = Request.register(body) response.code == 201 end |