lib/zeppelin.rb in zeppelin-0.3.0 vs lib/zeppelin.rb in zeppelin-0.4.0
- old
+ new
@@ -21,12 +21,12 @@
# Creates a new client.
#
# @param [String] application_key your Urban Airship Application Key
# @param [String] application_master_secret your Urban Airship Application
# Master Secret
- def initialize(application_key, application_master_secret)
- @connection = Faraday::Connection.new(BASE_URI) do |builder|
+ def initialize(application_key, application_master_secret, options = {})
+ @connection = Faraday::Connection.new(BASE_URI, options) do |builder|
builder.request :json
builder.adapter :net_http
end
@connection.basic_auth(application_key, application_master_secret)
@@ -53,11 +53,11 @@
#
# @param [String] device_token
# @return [Hash, nil]
def device_token(device_token)
response = @connection.get(device_token_uri(device_token))
- successful?(response) ? Yajl::Parser.parse(response.body) : nil
+ successful?(response) ? parse(response.body) : nil
end
# Deletes a device token.
#
# @param [String] device_token
@@ -88,11 +88,11 @@
#
# @param [String] apid
# @return [Hash, nil]
def apid(apid)
response = @connection.get(apid_uri(apid))
- successful?(response) ? Yajl::Parser.parse(response.body) : nil
+ successful?(response) ? parse(response.body) : nil
end
# Deletes an APID.
#
# @param [String] apid
@@ -135,13 +135,32 @@
#
# @param [Time] since the time to retrieve inactive tokens from
# @return [Hash, nil]
def feedback(since)
response = @connection.get(feedback_uri(since))
- successful?(response) ? Yajl::Parser.parse(response.body) : nil
+ successful?(response) ? parse(response.body) : nil
end
+ # Retrieve all tags on the service
+ #
+ # @return [Hash, nil]
+ def tags
+ response = @connection.get(tag_uri(nil))
+ successful?(response) ? parse(response.body) : nil
+ end
+
+ # Modifies device tokens associated with a tag.
+ #
+ # @param [String] tag The name of the tag to modify tag associations on
+ #
+ # @param [Hash] payload
+ #
+ # @see http://urbanairship.com/docs/tags.html#modifying-device-tokens-on-a-tag
+ def modify_device_tokens_on_tag(tag_name, payload = {})
+ @connection.post(tag_uri(tag_name), payload, JSON_HEADERS)
+ end
+
# Creates a tag that is not associated with any device
#
# @param [#to_s] name The name of the tag to add
#
# @return [Boolean] whether or not the request was successful
@@ -161,10 +180,18 @@
successful?(response)
end
# @param [String] device_token
#
+ # @return [Hash, nil]
+ def device_tags(device_token)
+ response = @connection.get(device_tag_uri(device_token, nil))
+ successful?(response) ? parse(response.body) : nil
+ end
+
+ # @param [String] device_token
+ #
# @param [#to_s] tag_name
#
# @return [Boolean] whether or not a tag was successfully associated with
# a device
def add_tag_to_device(device_token, tag_name)
@@ -205,9 +232,13 @@
device_token_uri(device_token) + "/tags/#{tag_name}"
end
def successful?(response)
SUCCESSFUL_STATUS_CODES.include?(response.status)
+ end
+
+ def parse(json)
+ Yajl::Parser.parse(json)
end
end
require 'zeppelin/version'