Class: Iterable::Device

Inherits:
ApiResource show all
Defined in:
lib/iterable/device.rb

Overview

Interact with user device API endpoints

Examples:

Creating device endpoint object

# With default config
campaigns = Iterable::Device.new 'token', 'app-name', Iterable::Device::APNS
campaigns.all

# With custom config
conf = Iterable::Device.new(token: 'new-token')
campaigns = Iterable::Device.new('token', 'app-name', Iterable::Device::APNS, config)

Constant Summary collapse

PLATFORMS =
[
  APNS = 'APNS'.freeze,
  APNS_SANDBOX = 'APNS_SANDBOX'.freeze,
  GCM = 'GCM'.freeze
].freeze

Instance Attribute Summary collapse

Attributes inherited from ApiResource

#conf

Instance Method Summary collapse

Methods inherited from ApiResource

default_config, #default_config

Constructor Details

#initialize(token, app, platform, data_fields = {}, conf = nil) ⇒ Device

Returns a new instance of Device.



45
46
47
48
49
50
51
# File 'lib/iterable/device.rb', line 45

def initialize(token, app, platform, data_fields = {}, conf = nil)
  @token = token
  @app = app
  @platform = platform
  @data_fields = data_fields
  super conf
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



23
24
25
# File 'lib/iterable/device.rb', line 23

def app
  @app
end

#data_fieldsObject (readonly)

Returns the value of attribute data_fields.



23
24
25
# File 'lib/iterable/device.rb', line 23

def data_fields
  @data_fields
end

#platformObject (readonly)

Returns the value of attribute platform.



23
24
25
# File 'lib/iterable/device.rb', line 23

def platform
  @platform
end

#tokenObject (readonly)

Returns the value of attribute token.



23
24
25
# File 'lib/iterable/device.rb', line 23

def token
  @token
end

Instance Method Details

#register(email, user_id = nil) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/iterable/device.rb', line 62

def register(email, user_id = nil)
  attrs = {
    device: device_data
  }
  attrs[:email] = email if email
  attrs[:userId] = user_id if user_id
  Iterable.request(conf, base_path).post(attrs)
end