urbanairship / ruby-library

A Ruby wrapper for the Urban Airship API.
Other
200 stars 117 forks source link

Malformed API requests when using platform-specific fields #92

Closed mobyjames closed 8 years ago

mobyjames commented 8 years ago

Using the platform-specific payload shortcuts like this:

push.notification = UA.ios( alert: 'testing tags again', extra: { 'tag' => 'foo'} )

produces the errors like this:

{"ok"=>false, "error"=>"Could not parse request body.", "error_code"=>40000, "details"=>{"error"=>"The key 'extra' is not allowed in this context", "path"=>"notification.extra", "location"=>{"line"=>1, "column"=>144}}}

Upon inspecting the body of the request, it looks like the platform values are not getting nested under the appropriate platform-specific key.

{"alert":"testing tags again","extra":{"tag":"foo"}},"device_types":["ios"]}

should be...

{"alert":"testing tags again","ios":{"extra":{"tag":"foo"}}},"device_types":["ios"]}

Either I misinterpreted the docs or the shortcuts should be updated. I'm happy to submit a pull request if someone can chime in to clarify :)

jkvoorhis commented 8 years ago

Hey @mobyjames,

It looks like there is a discrepancy between our docs and our behavior. The payload selectors should be used like so:

push.notification = UA.notification(
    #default alert
    alert: "This won't be seen on iOS devices",
    #iOS override payload 
    ios: UA.ios(  
        alert: 'testing tags again',
        extra: {'tag' => 'foo'}
    ),
    etc...
)

Thank you for bringing this to our attention, we will update our docs!

mobyjames commented 8 years ago

Thanks!