Class: Pushbots::Device

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#platformObject

Returns the value of attribute platform.



4
5
6
# File 'lib/pushbots/device.rb', line 4

def platform
  @platform
end

#tagsObject

Returns the value of attribute tags.



4
5
6
# File 'lib/pushbots/device.rb', line 4

def tags
  @tags
end

#tokenObject

Returns the value of attribute token.



4
5
6
# File 'lib/pushbots/device.rb', line 4

def token
  @token
end

Instance Method Details

#deleteObject



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

#infoObject



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.tags = http_response['tags']
  end
end

#registerObject



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