My question is simple here. I want to send json data from one Rails app to other Rails app via POST. How do I achieve that?
You can find a complete architectural example of how to do this with ActiveResource here
If you just need a simple call, I'd suggest to use REST-client for the calling side.
The provider side is pretty standard. Just expose an action that responds to JSON posts. Let me know if you need more details.
Have one Rails app accept JSON via a POST action in a controller, and have the other Rails app submit the JSON via an HTTP library like rest-client.
Related
I am having a Rails Application, where I will receive a SOAP request using POST method to it.
I need to handle that request, parse the corresponding XML, and need to respond to that request accordingly.
But, Ruby on Rails by default allows only REST request.
Can anyone please let me know how to handle that in Ruby on Rails?
Thanks in advance.
If you absolutely cannot avoid requiring soap requests coming into your application (in lieu of say, json) check out the wash_out gem.
I am using a Clear bit gem. How do I call the external API in the Rails application and send data back forth without the default database to store data.I need to build a form like the Clear bit form and send data back and forth.Do I need a controller and model for the same?
To call any external url, you should require rest-client gem.
url = "https://...."
body = RestClient.get(url)
JSON.parse(body)
You have to check the rest-client documentation
I've went through most of the beginner rails books and I want to try creating something on my own. For a start, I just want to create a few pages in rails that will get from Facebook's api and display something like username, likes, post. I've searched around and couldn't find an answer. My friend recommended that I use a gem called fb_graph, but reviewing the documentation, I have no clue how to use it.
Thanks stackoverflow!
You can query the Graph API directly. The responses will be in JSON which you can then parse into Ruby hash. See the Facebook Documentation for more details on to call specific and sample JSON responses. So here is general guide how to you can start playing around with this:-
Make a API Call to Facebook using Graph API
Explorer. Keep playing around with api until you get a response you want. Note the request params you passed to get that response & JSON you received from facebook.
Send a HTTP request containing those same params in rails using koala, 'fb_graph' or just plain NET:HTTP. It doesn't matter what client you use to sent the request, as long as you send same params as in step1, you will get that familar JSON as response.
Now, once you have the json, just have to parse it. Provided, if the client library is not already doing that as most fb gems will turn JSON into ruby objects/hashes. But if they don't, then you have to do it manually, its something like JSON.parse('JSON_RESPONSE_AS_STRING_GOES_HERE'). after this you will have a plain-old ruby hash which is you can save to db, display in view or whatever you want to do.
Hope it helps
How do I make an HTTP request in ruby on rails to get data from facebook. I am unsure of where to start to get data from the facebook API in json format.
I hope this question even makes sense.
If you are going to be dealing with FB in Rails you will want to take a look at mogli and facebooker2. If you can provide some more detail, people will be able to help you better but at least that's a good place to start.
If you really need JSON data, use rest-client.
https://github.com/archiloque/rest-client
I recommend use this instead of original rest-client gem, since original one doesn't force SSL certificate verification.
https://github.com/nov/restclient_with_cert
I'm new to Rails and trying to send a request to Chargify to cancel a subscription. Their API says I need to send the method DELETE to a xml URL. This isn't a Chargify based question but rather... how would I have a user click a button that then generates this request and sends it within my Rails app? You can view this url to see what I"m trying to do - http://docs.chargify.com/api-subscriptions#cancel. Also it's working fine when I run a command-line test so I know my code works, just now sure how to put it into my Rails app (view/controller). Thanks
Something like this should work using Net::HTTP in the Ruby Standard Library:
require 'net/http'
http = Net::HTTP.new('subdomain.chargify.com')
request = Net::HTTP::Delete.new('/subscriptions/1337.xml')
response = http.request(request)
You could include it in your controller's method, but unless you need to make sure the request finished before you send a response back, I recommend making the request to Chargify in a background job. Check out the delayed_job or resque libraries.
You probably want to use the Net::HTTP library. Also, checkout the source of some other ruby API bindings on Github to see how they use and structure this type of behavior (specifically, Twilio, Dropbox, and Flickraw).