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) ⇒ Iterable::Device

Initialize an [Iterable::Device] to register for a user

Parameters:

  • token (String)

    The device token

  • app (String)

    The application name for mobile push

  • platform (String)

    The device device platform; one of [Iterable::Device::PLATFORMS]

  • data_fields (Hash) (defaults to: {})

    Additional device data fields

  • conf (Iterable::Config) (defaults to: nil)

    A config to optionally pass for requests



34
35
36
37
38
39
40
# File 'lib/iterable/device.rb', line 34

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.



21
22
23
# File 'lib/iterable/device.rb', line 21

def app
  @app
end

#data_fieldsObject (readonly)

Returns the value of attribute data_fields.



21
22
23
# File 'lib/iterable/device.rb', line 21

def data_fields
  @data_fields
end

#platformObject (readonly)

Returns the value of attribute platform.



21
22
23
# File 'lib/iterable/device.rb', line 21

def platform
  @platform
end

#tokenObject (readonly)

Returns the value of attribute token.



21
22
23
# File 'lib/iterable/device.rb', line 21

def token
  @token
end

Instance Method Details

#register(email, user_id = nil) ⇒ Iterable::Response

Register a device for a user email or id

Parameters:

  • email (String)

    Email of user to associate device with

  • user_id (String) (defaults to: nil)

    User ID to associate device with instead of email

Returns:



50
51
52
53
54
55
56
57
# File 'lib/iterable/device.rb', line 50

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