Permalink
Browse files

Merge branch 'feature/support-blackberry-api' into develop

  • Loading branch information...
2 parents 1ba3301 + cdae329 commit 0de42c4ceddf68b0e98a40994321bf7665cfd535 @jherdman jherdman committed Mar 2, 2012
Showing with 168 additions and 37 deletions.
  1. +6 −0 Changelog.md
  2. +79 −37 lib/zeppelin.rb
  3. +83 −0 spec/zeppelin_spec.rb
View
@@ -1,3 +1,9 @@
+# dev
+
+## Enhancements
+
+* Support Blackberry API
+
# 0.7.0
## Enhancements
View
@@ -31,7 +31,7 @@ def connection
@connection = initialize_connection
end
- # Registers a device token.
+ # Registers an iPhone device token.
#
# @param [String] device_token
# @param [Hash] payload the payload to send during registration
@@ -44,58 +44,47 @@ def register_device_token(device_token, payload = {})
put_request(uri, payload)
end
- # Retrieves information on a device token.
- #
- # @param [String] device_token
- # @return [Hash, nil]
- #
- # @raise [Zeppelin::ResourceNotFound] invalid device token provided
- def device_token(device_token)
- uri = device_token_uri(device_token)
- get_request(uri)
- end
-
- # Deletes a device token.
- #
- # @param [String] device_token
- #
- # @return [Boolean] whether or not the deletion was successful
- #
- # @raise [Zeppelin::ResourceNotFound] invalid device token provided
- def delete_device_token(device_token)
- uri = device_token_uri(device_token)
- delete_request(uri)
- end
-
- # Retrieve a page of device tokens
+ # Registers an Android APID.
#
- # @param [Integer] page (nil) Page of device tokens to retrieve
+ # @param [String] apid
#
- # @return [Hash] result set. See documentation for details
+ # @param [Hash] payload the payload to send during registration
#
- # @Note that the next page number is included in the result set instead of the
- # raw URI to request for the next page
+ # @return [Boolean] whether or not the registration was successful
#
- # @raise [Zeppelin::ClientError] invalid request
- def device_tokens(page=nil)
- uri = device_token_uri(nil, :page => page)
- get_paged_request(uri)
+ # @raise [Zeppelin::ClientError] invalid payload format
+ def register_apid(apid, payload = {})
+ uri = apid_uri(apid)
+ put_request(uri, payload)
end
- # Registers an APID.
+ # Registers a Blackberry PIN
#
- # @param [String] apid
+ # @param [String] pin
#
# @param [Hash] payload the payload to send during registration
#
# @return [Boolean] whether or not the registration was successful
#
# @raise [Zeppelin::ClientError] invalid payload format
- def register_apid(apid, payload = {})
- uri = apid_uri(apid)
+ #
+ # @see http://urbanairship.com/docs/blackberry.html#registration
+ def register_pin(pin, payload = {})
+ uri = pin_uri(pin)
put_request(uri, payload)
end
+ # Retrieves information on a device token.
+ #
+ # @param [String] device_token
+ # @return [Hash, nil]
+ #
+ # @raise [Zeppelin::ResourceNotFound] invalid device token provided
+ def device_token(device_token)
+ uri = device_token_uri(device_token)
+ get_request(uri)
+ end
+
# Retrieves information on an APID.
#
# @param [String] apid
@@ -108,6 +97,28 @@ def apid(apid)
get_request(uri)
end
+ # @param [String] pin
+ #
+ # @return [Hash, nil]
+ #
+ # @raise [Zeppelin::ResourceNotFound] invalid PIN provided
+ def pin(pin)
+ uri = pin_uri(pin)
+ get_request(uri)
+ end
+
+ # Deletes a device token.
+ #
+ # @param [String] device_token
+ #
+ # @return [Boolean] whether or not the deletion was successful
+ #
+ # @raise [Zeppelin::ResourceNotFound] invalid device token provided
+ def delete_device_token(device_token)
+ uri = device_token_uri(device_token)
+ delete_request(uri)
+ end
+
# Deletes an APID.
#
# @param [String] apid
@@ -120,6 +131,33 @@ def delete_apid(apid)
delete_request(uri)
end
+ # Deletes a PIN
+ #
+ # @param [String] pin
+ #
+ # @return [Boolean] whether or not deletion was successful
+ #
+ # @raise [Zeppelin::ResourceNotFound] invalid PIN provided
+ def delete_pin(pin)
+ uri = pin_uri(pin)
+ delete_request(uri)
+ end
+
+ # Retrieve a page of device tokens
+ #
+ # @param [Integer] page (nil) Page of device tokens to retrieve
+ #
+ # @return [Hash] result set. See documentation for details
+ #
+ # @Note that the next page number is included in the result set instead of the
+ # raw URI to request for the next page
+ #
+ # @raise [Zeppelin::ClientError] invalid request
+ def device_tokens(page=nil)
+ uri = device_token_uri(nil, :page => page)
+ get_paged_request(uri)
+ end
+
# Retrieve a page of APIDs
#
# @param [Integer] page (nil) Page of APIDs to retrieve
@@ -339,6 +377,10 @@ def tag_uri(name)
def device_tag_uri(device_token, tag_name)
device_token_uri(device_token) + "/tags/#{tag_name}"
end
+
+ def pin_uri(pin)
+ "/api/device_pins/#{pin}/"
+ end
end
require 'zeppelin/middleware'
View
@@ -575,6 +575,89 @@
end
end
+ describe '#register_pin' do
+ let(:pin) { '12345678' }
+
+ let(:uri) { "/api/device_pins/#{pin}/" }
+
+ it 'is true when the request is successful' do
+ stub_requests do |stub|
+ stub.put(uri) { [201, {}, ''] }
+ end
+
+ subject.register_pin(pin).should be_true
+ end
+
+ it 'raises an error when the request fails' do
+ stub_requests do |stub|
+ stub.put(uri) { [500, {}, ''] }
+ end
+
+ expect {
+ subject.register_pin(pin)
+ }.to raise_error(Zeppelin::ClientError)
+ end
+ end
+
+ describe '#pin' do
+ let(:pin) { '12345678' }
+
+ let(:uri) { "/api/device_pins/#{pin}/" }
+
+ let(:response_body) {
+ {
+ :device_pin => pin,
+ :alias => 'my alias',
+ :last_registration => Time.mktime(2009, 11, 6, 20, 41, 6),
+ :created => Time.mktime(2009, 11, 6, 20, 41, 6),
+ :active => true,
+ :tags => %w[one two]
+ }
+ }
+
+ it 'responds with information about a device with a PIN when successful' do
+ stub_requests do |stub|
+ stub.get(uri) { [200, { 'Content-Type' => 'application/json' }, response_body] }
+ end
+
+ subject.pin(pin).should eql(response_body)
+ end
+
+ it 'raises an error when the PIN resource cannot be found' do
+ stub_requests do |stub|
+ stub.get(uri) { [404, {}, ''] }
+ end
+
+ expect {
+ subject.pin(pin)
+ }.to raise_error(Zeppelin::ResourceNotFound)
+ end
+ end
+
+ describe '#delete_pin' do
+ let(:pin) { '12345678' }
+
+ let(:uri) { "/api/device_pins/#{pin}/" }
+
+ it 'is true when the request succeeds' do
+ stub_requests do |stub|
+ stub.delete(uri) { [204, {}, ''] }
+ end
+
+ subject.delete_pin(pin).should be_true
+ end
+
+ it 'raises an error when the request fails' do
+ stub_requests do |stub|
+ stub.delete(uri) { [404, {}, ''] }
+ end
+
+ expect {
+ subject.delete_pin(pin)
+ }.to raise_error(Zeppelin::ResourceNotFound)
+ end
+ end
+
def stub_requests
subject.connection.builder.handlers.delete(Faraday::Adapter::NetHttp)
subject.connection.adapter :test do |stubs|

0 comments on commit 0de42c4

Please sign in to comment.