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
Related
I was working on Postman.
But now I want to hit an URL, get the response along with cookies and set it, to send it to consecutive URLs.
How to do this in Ruby Rails?
You can use libraries like Faraday (https://github.com/lostisland/faraday) or httparty (https://github.com/jnunemaker/httparty) to achieve what you want. There is also a library built in ruby language net/http https://ruby-doc.org/stdlib-3.1.0/libdoc/net/http/rdoc/Net/HTTP.html
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 working on real time data visualization project that consumes twitter streaming api
s'.For processing tweets in a server side that is based on rails Framework.
With twitter ruby gem, i can able to fetch the stream tweets
topics = ["coffee", "tea"]
client.filter(:track => topics.join(",")) do |tweet|
puts tweet.text
end
With this i need to build a JSON API in Rails.
UPDATE: With JSON API, need to integrate with AngularJS. For building API at real-time, whether i need to store it any database or not needed.
I suggest you consider Sinatra to build the API, but you can certainly do it in Rails. Simply when a client makes a REST call to the endpoint defined in routes.rb, the controller method will itself make a REST call to Twitter and then transform and serialize their result to JSON to return to your client.
Just remember that your clients need to send the CSRF token with their requests to your services for Rails to let them through and maintain session.
In JQuery it might look something like this:
$.ajaxSetup({
beforeSend: function(xhr) {
xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'));
}
});
As for memory concerns with the volume of data, that depends on how much data you are retrieving, what you are doing with it, the power of your machine, etc. I wouldn't worry if you aren't hitting the Firehose. Let's worry about a memory issue later if it happens. There are always things you can do like caching results, etc. without using a database.
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.
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).