I have an app that requires push notifications sent to user when a post matching certain criteria is put onto the db. I am using urban airship and HTTParty to make the necessary requests if the conditions are met. My model is as follows:
class Urbanairship
include HTTParty
base_uri 'https://go.urbanairship.com'
headers "Content-Type" => "application/json"
basic_auth "xxxappkeyxxx", "xxxappsecretxxx"
default_params :output => 'json'
format :json
def self.push(badge, alert_message, token)
self.post('/api/push/',:body => {:aps => {:badge => badge, :alert => alert_message}, :device_tokens => [token]})
end
end
I keep getting a 400 bad request when I test this in the console. Any ideas as to what the problem is? I know that urban airship needs a 'content-type:application/json' in the request header, but that should be covered in the model. Thanks in advance, Jack
I don't know HTTParty myself, but the most if you can introspect the result and get the actual response body, that should tell you more. A 400 could be from the missing content-type, as you mentioned, or invalid JSON, but it could also be from a an invalid device token or badge number.