Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/dirigible/device_information.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def self.get_device_pin(id)
#
# @see http://docs.urbanairship.com/reference/api/v3/device_information.html#device-listing
def self.count_device_tokens
Dirigible.get("/device_tokens/count")
Dirigible.get("/device_tokens/count/")
end


Expand All @@ -55,7 +55,7 @@ def self.count_device_tokens
#
# @see http://docs.urbanairship.com/reference/api/v3/device_information.html#device-listing
def self.list_device_tokens(options = {})
List.new(Dirigible.get('/device_tokens', options))
List.new(Dirigible.get('/device_tokens/', options))
end

# Fetch Android APIDs registered to this application and
Expand All @@ -70,7 +70,7 @@ def self.list_device_tokens(options = {})
#
# @see http://docs.urbanairship.com/reference/api/v3/device_information.html#device-listing
def self.list_apids(options = {})
List.new(Dirigible.get('/apids', options))
List.new(Dirigible.get('/apids/', options))
end

# Fetch BlackBerry PINs registered to this application and
Expand All @@ -85,7 +85,7 @@ def self.list_apids(options = {})
#
# @see http://docs.urbanairship.com/reference/api/v3/device_information.html#device-listing
def self.list_device_pins(options = {})
List.new(Dirigible.get('/device_pins', options))
List.new(Dirigible.get('/device_pins/', options))
end

# Fetch device tokens that can't recieve messages because
Expand All @@ -96,7 +96,7 @@ def self.list_device_pins(options = {})
#
# @see http://docs.urbanairship.com/reference/api/v3/device_information.html#feedback
def self.device_token_feedback(since)
Dirigible.get("/device_tokens/feedback", { since: since })
Dirigible.get("/device_tokens/feedback/", { since: since })
end

class List
Expand Down
5 changes: 4 additions & 1 deletion lib/dirigible/error.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
module Dirigible
# Custom error class for rescuing from all known Urban Airship errors
class Error < StandardError; alias_method :error, :message end
class Error < StandardError
alias_method :error, :message
attr_accessor :parsed
end

# Raised when Urban Airship returns HTTP status code 400
class BadRequest < Error; end
Expand Down
2 changes: 1 addition & 1 deletion lib/dirigible/feed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Dirigible::Feed
#
# @see http://docs.urbanairship.com/reference/api/v3/feeds.html#creating-a-new-feed
def self.create(params)
Dirigible.post('/feeds', params)
Dirigible.post('/feeds/', params)
end

# Returns information about that particular feed.
Expand Down
4 changes: 2 additions & 2 deletions lib/dirigible/location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Dirigible::Location
#
# @see http://docs.urbanairship.com/reference/api/v3/location.html#location-boundary-information
def self.search_by_name(query, boundary_type = nil)
Dirigible.get('/location', { q: query, type: boundary_type })
Dirigible.get('/location/', { q: query, type: boundary_type })
end

# Search for a location by latitude and longitude.
Expand Down Expand Up @@ -60,6 +60,6 @@ def self.from_alias(query)
#
# @see http://docs.urbanairship.com/reference/api/v3/location.html#location-data-ranges
def self.cutoff_dates
Dirigible.get("/segments/dates")
Dirigible.get("/segments/dates/")
end
end
2 changes: 1 addition & 1 deletion lib/dirigible/push.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Dirigible::Push
#
# @see http://docs.urbanairship.com/reference/api/v3/push.html#push
def self.create(params)
Dirigible.post('/push', params)
Dirigible.post('/push/', params)
end

# Accept the same range of payloads as /api/push, but parse
Expand Down
4 changes: 2 additions & 2 deletions lib/dirigible/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ def delete(path, options = {}, headers = {})
def request(method, path, options, headers)
headers.merge!({
'User-Agent' => user_agent,
'Accept' => 'application/vnd.urbanairship+json; version=3;',
'Accept' => 'application/vnd.urbanairship+json; version=3;'
})

response = connection.send(method) do |request|
request.url("#{endpoint}#{path}/")
request.url("#{endpoint}#{path}")

if [:post, :put].member?(method)
request.body = options.to_json
Expand Down
4 changes: 2 additions & 2 deletions lib/dirigible/schedule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Dirigible::Schedule
#
# @see http://docs.urbanairship.com/reference/api/v3/schedule.html#schedule-a-notification
def self.create(params)
Dirigible.post('/schedules', params)
Dirigible.post('/schedules/', params)
end

# List all existing schedules. Returns an array of schedule
Expand All @@ -30,7 +30,7 @@ def self.create(params)
#
# @see http://docs.urbanairship.com/reference/api/v3/schedule.html#list-schedules
def self.list
Dirigible.get('/schedules')
Dirigible.get('/schedules/')
end

# Fetch the current definition of a single schedule
Expand Down
4 changes: 2 additions & 2 deletions lib/dirigible/segment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Dirigible::Segment
#
# @see http://docs.urbanairship.com/reference/api/v3/segments.html#segments-information
def self.list
Dirigible.get('/segments')
Dirigible.get('/segments/')
end

# Fetch information about a particular segment.
Expand Down Expand Up @@ -35,7 +35,7 @@ def self.get(id)
#
# @see http://docs.urbanairship.com/reference/api/v3/segments.html#segment-creation
def self.create(params)
Dirigible.post('/segments', params)
Dirigible.post('/segments/', params)
end

# Change the definition of the segment.
Expand Down
4 changes: 2 additions & 2 deletions lib/dirigible/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Dirigible::Tag
#
# @see http://docs.urbanairship.com/reference/api/v3/tags.html#tag-listing
def self.list
Dirigible.get('/tags')
Dirigible.get('/tags/')
end

# Explicitly create a tag with no devices associated with
Expand Down Expand Up @@ -107,6 +107,6 @@ def self.add_or_remove(tag, params)
#
# @see http://docs.urbanairship.com/reference/api/v3/tags.html#batch-modification-of-tags
def self.batch(params)
Dirigible.post("/tags/batch", params)
Dirigible.post("/tags/batch/", params)
end
end
10 changes: 7 additions & 3 deletions lib/dirigible/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Dirigible
# @private
module Utils
def self.handle_api_error(response)
message = parse_message(response)


klass = case response.status
when 400 then BadRequest
Expand All @@ -14,14 +14,18 @@ def self.handle_api_error(response)
else Error
end

raise klass.new(message)
err = klass.new(response.body)
err.parsed = parse_message(response)
raise err

end

def self.parse_json(json)
MultiJson.load(json, symbolize_keys: true)
end

def self.parse_message(response)

begin
parse_json(response.body)
rescue
Expand Down