Class: Spire::API::Notification

Inherits:
Resource
  • Object
show all
Defined in:
lib/spire/api/notification.rb

Instance Attribute Summary

Attributes inherited from Resource

#capabilities, #properties, #url

Instance Method Summary collapse

Methods inherited from Resource

#[], #delete, #get, #initialize, #key, #media_type, #method_missing, #respond_to?, #schema, #update

Methods included from Requestable

included

Constructor Details

This class inherits a constructor from Spire::API::Resource

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Spire::API::Resource

Instance Method Details

#devicesObject



93
94
95
# File 'lib/spire/api/notification.rb', line 93

def devices
  @devices ||= {}
end

#devices!Object



76
77
78
79
80
81
82
# File 'lib/spire/api/notification.rb', line 76

def devices!
  response = request(:devices)
  unless response.status == 200
    raise "Error getting device list #{self.class.name}: (#{response.status}) #{response.body}"
  end
  response.data["devices"]
end

#register_device(device_token) ⇒ Object



84
85
86
87
88
89
90
91
# File 'lib/spire/api/notification.rb', line 84

def register_device(device_token)
  response = request(:register_device, :token => device_token)
  unless response.status == 200
    raise "Error adding device #{self.class.name}: (#{response.status}) #{response.body}"
  end
  token = response.data["token"]
  devices[token] = response.data
end

#resource_nameObject



5
6
7
# File 'lib/spire/api/notification.rb', line 5

def resource_name
  "notification"
end

#send_notification(options = {}) ⇒ Object



68
69
70
71
72
73
74
# File 'lib/spire/api/notification.rb', line 68

def send_notification(options={})
  response = request(:push, options)
  unless response.status == 200
    raise "Error sending push notification #{self.class.name}: (#{response.status}) #{response.body}"
  end
  response.data
end