Class: FiveMobilePush::Device

Inherits:
Object
  • Object
show all
Defined in:
lib/five_mobile_push/device.rb

Constant Summary collapse

VALID_OPTION_KEYS =
[:alias, :email]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, uid, token = nil) ⇒ Device

Returns a new instance of Device.

Parameters:

  • client (FiveMobilePush::Client)

    The Client to use to send this request

  • uid (String)

    The ID of the device being registered. Maximum of 64 characters.



12
13
14
15
16
# File 'lib/five_mobile_push/device.rb', line 12

def initialize(client, uid, token=nil)
  @client = client
  @uid    = uid
  @token  = token
end

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token.



6
7
8
# File 'lib/five_mobile_push/device.rb', line 6

def token
  @token
end

#uidObject (readonly)

Returns the value of attribute uid.



6
7
8
# File 'lib/five_mobile_push/device.rb', line 6

def uid
  @uid
end

Instance Method Details

#register(info, registration_data = nil) ⇒ Hash

Registers a device for receiving push notifications from an application. If the device is already registered, this call can update the existing registration details.

Parameters:

  • registration_data (String) (defaults to: nil)

    Platform specific device registration data, e.g. iOS device token. Optional for some platforms

  • device_info (Hash)

    Information about the device being registered

Returns:

  • (Hash)

    Has unique device API key. Required for many other calls.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/five_mobile_push/device.rb', line 38

def register(info, registration_data=nil)
  options = {
    :device_id   => @uid,
    :device_info => MultiJson.encode(info)
  }

  options[:reg_data] = registration_data unless registration_data.nil?
  response = @client.post 'device/register', options
  
  if response.headers['content-type'] =~ /json/i
    MultiJson.decode(response.body)
  else
    response.body
  end
end

#resumeObject



54
55
56
# File 'lib/five_mobile_push/device.rb', line 54

def resume
  client_operation 'device/resume'
end

#suspendObject



58
59
60
# File 'lib/five_mobile_push/device.rb', line 58

def suspend
  client_operation 'device/suspend'
end

#unregisterObject



62
63
64
# File 'lib/five_mobile_push/device.rb', line 62

def unregister
  client_operation 'device/unregister'
end