Class: PushBot::Device

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

Instance Attribute Summary

Attributes inherited from Api

#platform, #platforms, #token

Instance Method Summary collapse

Methods inherited from Api

#batch?, #initialize, #token?, #user?

Constructor Details

This class inherits a constructor from PushBot::Api

Instance Method Details

#add(registration_options = {}) ⇒ PushBot::Response

Add a specific user or batch of users to PushBots

Parameters:

Returns:

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/push_bot/device.rb', line 14

def add(registration_options={})
  raise(ArgumentError, 'Batch device add should only be to a single platform') if Array === token && platforms.size != 1

  options, type = registration_options.merge(
    :platform => platform
  ), :batch

  if user? && !(Array === token)
    type = nil
    options[:token] = token
  else
    options[:tokens] = token
  end

  request.put(type, options)
end

#alias(alias_options = {}) ⇒ PushBot::Response

Alias one user identifier to another

Parameters:

Returns:



35
36
37
# File 'lib/push_bot/device.rb', line 35

def alias(alias_options={})
  Request.new(:alias).put(nil, alias_options.merge(:token => token, :platform => platform))
end

#allPushBot::Response

Request a list of your registered devices

Returns:



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

def all
  request.get(:all)
end

#at_location(*location) ⇒ Object

Set the users location to the specified latitude and longitude

Parameters:

  • location

    two arguments of ‘latitude` and `longitude`

  • location

    a two item array [‘latitude` and `longitude`]

  • location

    an object that responds to ‘lat` + `lng` OR `lat` + `lon` OR `latitude` + `longitude`

  • location (PushBot::Location)

Raises:

  • (ArgumentError)


52
53
54
55
56
57
58
# File 'lib/push_bot/device.rb', line 52

def at_location(*location)
  lat, lng = PushBot::Location.parse(*location)

  raise ArgumentError, 'latitude and longitude are required' unless lat && lng

  Request.new(:geo).put(nil, :token => token, :platform => platform, :lat => lat, :lng => lng)
end

#infoPushBot::Response

Retrieve information about the device with this token

Returns:



42
43
44
# File 'lib/push_bot/device.rb', line 42

def info
  request.get(:one, :token => token)
end

#removePushBot::Response

Remove a specific user from PushBots

Returns:

Raises:

  • (ArgumentError)


67
68
69
70
71
# File 'lib/push_bot/device.rb', line 67

def remove
  raise(ArgumentError, 'A token and platform is required for removal') unless token && token

  request.put(:del, :token => token, :platform => platform)
end

#removedObject



60
61
62
# File 'lib/push_bot/device.rb', line 60

def removed
  Request.new(:feedback).get
end