Class: Zeppelin

Inherits:
Object
  • Object
show all
Defined in:
lib/zeppelin.rb,
lib/zeppelin/version.rb,
lib/zeppelin/middleware.rb,
lib/zeppelin/middleware/response_raise_error.rb

Overview

A very tiny Urban Airship Push Notification API client.

Provides thin wrappers around API calls to the most common API tasks. For more information on how the requests and responses are formatted, visit the Urban Airship Push Notification API docs.

Defined Under Namespace

Modules: Middleware, Middlware Classes: ClientError, ResourceNotFound

Constant Summary collapse

BASE_URI =
'https://go.urbanairship.com'
PUSH_URI =
'/api/push/'
BATCH_PUSH_URI =
'/api/push/batch/'
BROADCAST_URI =
'/api/push/broadcast/'
JSON_HEADERS =
{ 'Content-Type' => 'application/json' }
VERSION =
'0.8.4'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(application_key, application_master_secret, options = {}) ⇒ Zeppelin

Returns a new instance of Zeppelin.

Parameters:

  • application_key (String)

    your Urban Airship Application Key

  • application_master_secret (String)

    your Urban Airship Application Master Secret



23
24
25
26
27
# File 'lib/zeppelin.rb', line 23

def initialize(application_key, application_master_secret, options = {})
  @application_key = application_key
  @application_master_secret = application_master_secret
  @options = options
end

Instance Attribute Details

#application_key (readonly)

Returns the value of attribute application_key.



17
18
19
# File 'lib/zeppelin.rb', line 17

def application_key
  @application_key
end

#application_master_secret (readonly)

Returns the value of attribute application_master_secret.



17
18
19
# File 'lib/zeppelin.rb', line 17

def application_master_secret
  @application_master_secret
end

#options (readonly)

Returns the value of attribute options.



17
18
19
# File 'lib/zeppelin.rb', line 17

def options
  @options
end

Instance Method Details

#add_tag(name) ⇒ Boolean

Creates a tag that is not associated with any device

Parameters:

  • name (#to_s)

    The name of the tag to add

Returns:

  • (Boolean)

    whether or not the request was successful



249
250
251
252
# File 'lib/zeppelin.rb', line 249

def add_tag(name)
  uri = tag_uri(name)
  put_request(uri)
end

#add_tag_to_device(device_token, tag_name) ⇒ Boolean

Returns whether or not a tag was successfully associated with a device.

Parameters:

  • device_token (String)
  • tag_name (#to_s)

Returns:

  • (Boolean)

    whether or not a tag was successfully associated with a device

Raises:



285
286
287
288
# File 'lib/zeppelin.rb', line 285

def add_tag_to_device(device_token, tag_name)
  uri = device_tag_uri(device_token, tag_name)
  put_request(uri)
end

#apid(apid) ⇒ Hash?

Retrieves information on an APID.

Parameters:

  • apid (String)

Returns:

  • (Hash, nil)

Raises:



96
97
98
99
# File 'lib/zeppelin.rb', line 96

def apid(apid)
  uri = apid_uri(apid)
  get_request(uri)
end

#apids(page = nil) ⇒ Hash

Retrieve a page of APIDs

Parameters:

  • page (Integer) (defaults to: nil)

    (nil) Page of APIDs to retrieve

Returns:

  • (Hash)

    result set. See documentation for details

Raises:



172
173
174
175
# File 'lib/zeppelin.rb', line 172

def apids(page=nil)
  uri = apid_uri(nil, :page => page)
  get_paged_request(uri)
end

#batch_push(*payload) ⇒ Boolean

Batch pushes multiple messages.

Parameters:

  • payload (<Hash>)

    the payloads of each message

Returns:

  • (Boolean)

    whether or not pushing the messages was successful

Raises:



195
196
197
# File 'lib/zeppelin.rb', line 195

def batch_push(*payload)
  post_request(BATCH_PUSH_URI, payload)
end

#broadcast(payload) ⇒ Boolean

Broadcasts a message.

Parameters:

  • payload (Hash)

    the payload of the message

Returns:

  • (Boolean)

    whether or not broadcasting the message was successful

Raises:



206
207
208
# File 'lib/zeppelin.rb', line 206

def broadcast(payload)
  post_request(BROADCAST_URI, payload)
end

#connection

The connection to UrbanAirship



30
31
32
33
# File 'lib/zeppelin.rb', line 30

def connection
  return @connection if defined?(@connection)
  @connection = initialize_connection
end

#delete_apid(apid) ⇒ Boolean

Deletes an APID.

Parameters:

  • apid (String)

Returns:

  • (Boolean)

    whether or not the deletion was successful

Raises:



130
131
132
133
# File 'lib/zeppelin.rb', line 130

def delete_apid(apid)
  uri = apid_uri(apid)
  delete_request(uri)
end

#delete_device_token(device_token) ⇒ Boolean

Deletes a device token.

Parameters:

  • device_token (String)

Returns:

  • (Boolean)

    whether or not the deletion was successful

Raises:



118
119
120
121
# File 'lib/zeppelin.rb', line 118

def delete_device_token(device_token)
  uri = device_token_uri(device_token)
  delete_request(uri)
end

#delete_pin(pin) ⇒ Boolean

Deletes a PIN

Parameters:

  • pin (String)

Returns:

  • (Boolean)

    whether or not deletion was successful

Raises:



142
143
144
145
# File 'lib/zeppelin.rb', line 142

def delete_pin(pin)
  uri = pin_uri(pin)
  delete_request(uri)
end

#device_tags(device_token) ⇒ Hash?

Parameters:

  • device_token (String)

Returns:

  • (Hash, nil)

Raises:



272
273
274
275
# File 'lib/zeppelin.rb', line 272

def device_tags(device_token)
  uri = device_tag_uri(device_token, nil)
  get_request(uri)
end

#device_token(device_token) ⇒ Hash?

Retrieves information on a device token.

Parameters:

  • device_token (String)

Returns:

  • (Hash, nil)

Raises:



84
85
86
87
# File 'lib/zeppelin.rb', line 84

def device_token(device_token)
  uri = device_token_uri(device_token)
  get_request(uri)
end

#device_tokens(page = nil) ⇒ Hash

Retrieve a page of device tokens

Parameters:

  • page (Integer) (defaults to: nil)

    (nil) Page of device tokens to retrieve

Returns:

  • (Hash)

    result set. See documentation for details

Raises:



157
158
159
160
# File 'lib/zeppelin.rb', line 157

def device_tokens(page=nil)
  uri = device_token_uri(nil, :page => page)
  get_paged_request(uri)
end

#feedback(since) ⇒ Hash?

Retrieves feedback on device tokens.

This is useful for removing inactive device tokens for the database.

Parameters:

  • since (Time)

    the time to retrieve inactive tokens from

Returns:

  • (Hash, nil)

Raises:



219
220
221
222
# File 'lib/zeppelin.rb', line 219

def feedback(since)
  uri = feedback_uri(since)
  get_request(uri)
end

#modify_device_tokens_on_tag(tag_name, payload = {})

Modifies device tokens associated with a tag.

Parameters:

  • tag (String)

    The name of the tag to modify tag associations on

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

See Also:



239
240
241
242
# File 'lib/zeppelin.rb', line 239

def modify_device_tokens_on_tag(tag_name, payload = {})
  uri = tag_uri(tag_name)
  post_request(uri, payload)
end

#pin(pin) ⇒ Hash?

Parameters:

  • pin (String)

Returns:

  • (Hash, nil)

Raises:



106
107
108
109
# File 'lib/zeppelin.rb', line 106

def pin(pin)
  uri = pin_uri(pin)
  get_request(uri)
end

#push(payload) ⇒ Boolean

Pushes a message.

Parameters:

  • payload (Hash)

    the payload of the message

Returns:

  • (Boolean)

    whether or not pushing the message was successful

Raises:



184
185
186
# File 'lib/zeppelin.rb', line 184

def push(payload)
  post_request(PUSH_URI, payload)
end

#register_apid(apid, payload = {}) ⇒ Boolean

Registers an Android APID.

Parameters:

  • apid (String)
  • payload (Hash) (defaults to: {})

    the payload to send during registration

Returns:

  • (Boolean)

    whether or not the registration was successful

Raises:



57
58
59
60
# File 'lib/zeppelin.rb', line 57

def register_apid(apid, payload = {})
  uri = apid_uri(apid)
  put_request(uri, payload)
end

#register_device_token(device_token, payload = {}) ⇒ Boolean

Registers an iPhone device token.

Parameters:

  • device_token (String)
  • payload (Hash) (defaults to: {})

    the payload to send during registration

Returns:

  • (Boolean)

    whether or not the registration was successful

Raises:



43
44
45
46
# File 'lib/zeppelin.rb', line 43

def register_device_token(device_token, payload = {})
  uri = device_token_uri(device_token)
  put_request(uri, payload)
end

#register_pin(pin, payload = {}) ⇒ Boolean

Registers a Blackberry PIN

Parameters:

  • pin (String)
  • payload (Hash) (defaults to: {})

    the payload to send during registration

Returns:

  • (Boolean)

    whether or not the registration was successful

Raises:

See Also:



73
74
75
76
# File 'lib/zeppelin.rb', line 73

def register_pin(pin, payload = {})
  uri = pin_uri(pin)
  put_request(uri, payload)
end

#remove_tag(name) ⇒ Boolean

Removes a tag from the service

Parameters:

  • name (#to_s)

    The name of the tag to remove

Returns:

  • (Boolean)

    true when the request was successful. Note that this method will return false if the tag has already been removed.

Raises:



262
263
264
265
# File 'lib/zeppelin.rb', line 262

def remove_tag(name)
  uri = tag_uri(name)
  delete_request(uri)
end

#remove_tag_from_device(device_token, tag_name) ⇒ Boolean

Returns whether or not a tag was successfully dissociated from a device.

Parameters:

  • device_token (String)
  • tag_name (#to_s)

Returns:

  • (Boolean)

    whether or not a tag was successfully dissociated from a device

Raises:



298
299
300
301
# File 'lib/zeppelin.rb', line 298

def remove_tag_from_device(device_token, tag_name)
  uri = device_tag_uri(device_token, tag_name)
  delete_request(uri)
end

#tagsHash?

Retrieve all tags on the service

Returns:

  • (Hash, nil)


227
228
229
230
# File 'lib/zeppelin.rb', line 227

def tags
  uri = tag_uri(nil)
  get_request(uri)
end