i'm trying to send a parse.com push notification from ruby 1.8.7.
i got a test working with curl. but with ruby's net::http i'm getting Timeout::Error: Resource temporarily unavailable
how can i debug this? i don't know how to see why the parse server is responding differently or otherwise see what's happening. i tried sending the request to my own server and the headers looked ok to me.
i simplified what i'm doing to this:
http = Net::HTTP.new('api.parse.com', 443)
response = http.post("/1/push", "{\"where\":{},\"data\":{\"alert\":\"Elliot net http json test 1\"}}", {"X-Parse-Application-Id"=>"xxxxx", "Content-Type"=>"application/json", "X-Parse-REST-API-Key"=>"xxxxx"})
the json there is hard to read, it's from:
api_req = {:where => {}, :data => {:alert => "Elliot net http json test 1"}}.to_json
puts api_req
# {"where":{},"data":{"alert":"Elliot net http json test 1"}}
i also tried several other ways of sending a request with net::http. same result.
the curl request that worked was:
curl -X POST \
-H "X-Parse-Application-Id: xxxxxx" \
-H "X-Parse-REST-API-Key: xxxxx" \
-H "Content-Type: application/json" \
-d '{
"where": {},
"data": {
"alert": "Elliot curl test #4"
}
}' \
https://api.parse.com/1/push
i'm not using parse-ruby-client because i ran into problems with dependencies assuming a newer version of ruby. all i need to do is send some simple push notifications, and it seems like this should work without too much trouble.
can anyone help me get this working or tell me how to get some useful info about what's happening to debug?
As per the REST API Developers guide,
All API access is over HTTPS, and accessed via the https://api.parse.com domain.
So all you need to do is to add http.use_ssl = true.
Related
Following the indications provided by this gem , testing in the Rails console the RestClient
RestClient.post "https://upload.twitter.com/1.1/media/upload.json?media_category=tweet_image", :myfile => File.new("/Users/main/Desktop/ss2022-11-03_11.39.11.png", 'rb')
one can assert that the file exists by changing its path. Once verified, the response returns
400 Bad Request. So the request is malformed. Alas, I do not grasp what the second element of the File.new represents
The version 1.1 API documentation provides a suggestion console test
twurl -X POST -H upload.twitter.com "/1.1/media/upload.json?media_category=TWEET_IMAGE&additional_owners=3805104374" -f adsapi-heirarchy.png -F media
the response is the same whether the additional_owners is included or not (logical, it is optional).
What is missing in this sequence?
Thr translation of the twurl syntax to curl syntax would be:
curl "https://upload.twitter.com/1.1/media/upload.json?media_category=tweet_image&additional_owners=3805104374" --data-urlencode #/Users/main/Desktop/adsapi-heirarchy.png --data-urlencode 'media'
I've lost almost two whole days trying to solve PayPal related issues.
I'm trying to execute a payment after user's approval, but I'm getting MALFORMED_REQUEST everytime I send the Curl request.
def execute
# Get the access_token
token = get_paypal_token(false)
payer_id = params[:PayerID]
payment_id = params[:paymentId]
# Creating the data object
stringJson = {:payer_id => "#{payer_id}"}
# You can see that I hard-coded the payer_id to ensure the JSON is correct
curlString = `curl -v -H "Authorization: Bearer #{token}" -H "Content-Type: application/json" -d '{"payer_id" : "QULQSFESGMCX2"}' https://api.sandbox.paypal.com/v1/payments/payment/#{payment_id}/execute/`
end
And the response is:
"{\"name\":\"MALFORMED_REQUEST\",\"message\":\"The request JSON is not well formed.\",\"information_link\":\"https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST\",\"debug_id\":\"6431589715660\"}"
Looks like you are running it from windows. I tried your command from my windows and my test server receiving the json as '{payer_id. It is happening because of your single quote.
I have changed the single quotes into double and it is working fine here with me.
-d "{\"payer_id\" : \"QULQSFESGMCX2\"}"
You can run the curl command from the console and see what happens, after that you can push it inside your ruby script code.
How do I convert the following CURL PUT request to rspec and test the behaviour of JSON parser.
curl -D - -X PUT --data "not json" -H "Content-Type: application/json" http://localhost:3000
And how to check the response? Thank you in advance.
The best is to use vcr gem https://github.com/vcr/vcr
Simply create script like in https://github.com/vcr/vcr#usage but with proper HTTP request.
VCR.use_cassette("json_test") do
req = Net::HTTP::Put.new('http://localhost:3000', 'not json')
req.content_type = 'application/json'
res = Net::HTTP.get_response(req)
end
With this real HTTP request will be recorded once and in rspec local file will be used instead.
You can use the -i option:
-i, --include
(HTTP) Include the HTTP-header in the output. The HTTP-header includes things like server-name, date of the document, HTTP-version and more...
from http://curl.haxx.se/docs/manpage.html
I'm following the instructions here http://developer.bigcommerce.com/api/webhooks/quickstart to set up webhooks to initiate some third-party order processing. We've been doing this on an hourly batch, real-time webhook triggers will save us a lot of lag time.
I think I've set up the webhook broadcaster, but can't see any evidence that it's being fired- I've created a bunch of new orders and nothing reaches the rails server.
How can I tell if BigCommerce is firing events when / where I expect?
Generated the access token for the given app/user/domain:
curl -XPOST -d '{
"client_id":"[BigCommerceAppClientId]",
"client_secret":"[BigCommerceAppSecret]",
"user":"admin",
"token":"[adminAPIToken]",
"store_domain":"https://[myStore].mybigcommerce.com"
}' https://hooks-beta.bigcommerce.com/token
yields ===>
{
"access_token":"[webHooksAccessToken]",
"producer":"store/[myStoreKey]"
}
Subscribed to webhooks for store/events/listener:
curl -XPOST -d '{
"producer":"store/[myStoreKey]",
"scope":"store/order/created",
"deliverymethod":"HTTP_POST",
"destination":{"url":"http://[myPublicRailsServer]/hooks"}
}' -H 'X-Auth-Client: [BigCommerceAppClientId]' -H 'X-Auth-Token:[X-Auth-Token]' https://hooks-beta.bigcommerce.com
yields ===>
{
"client_id":"[webHooksAccessToken]",
"created_at":"2013-06-27T19:57:38+00:00",
"deliverymethod":"HTTP_POST","destination":{"url":"http://[myPublicRailsServer]/hooks"},
"id":651,
"producer":"store/[myStoreKey]",
"scope":"store/order/created",
"updated_at":"2013-06-27T19:57:38+00:00"
}
I lied. The problem was apparently trying to use https instead of http. Everything works as expected.
Furthermore- BigCommerce provides a hook to check the active clients for a given application:
curl -XGET -H
'X-Auth-Client: [BigCommerceAppClientId]' -H
'X-Auth-Token: [BigCommerceAppSecret]'
https://hooks-beta.bigcommerce.com/producer/store/[myStoreKey]
If i issue a POST request using curl command to github api to add "Resolved" label; things are good.
curl -i -H "Authorization: token xxxxxxxxxxxx" -X POST 'https://git.corp.yahoo.com/api/v3/repos/owner/repo/issues/1/labels' -d '["Resolved"]'}
But when i try to do the same using Curl easy in my Ruby script
set gh_api = https://git.corp.yahoo.com/api/v3/repos/owner/repo/issues/1/labels
curl = Curl::Easy.http_post(settings.gh_api,'["Resolved"]')
do |c|
c.headers = ["Authorization: token xxxxxxxx"]
end
The JSON reponse I get is
"{\"message\":\"Not Found\"}"
What am i doing wrong in my ruby script?
It's not at all clear what question you are asking because there is no question.
What's returned is a JSON response. Why don't you parse it with the JSON class and see what it returns:
require 'json'
puts JSON["{\"message\":\"Not Found\"}"]
=> {"message"=>"Not Found"}
I'm guessing that the problem is in the path of the URL if the response is "Not Found".
My URL was wrong. I ended the URL with a '/'.