Firstly I know I have some reading to do with this but I was looking to see what would be a rails way of going about this
I am going to build a simple book library where you can add books, but rather than manually input all the info via a long form, it would be nice if i can just enter the ISBN number and retrieve all the info via an api. I believe Google data has such an api? or does anyone use anything else? This will be my first time using an api so any advice/resources that would assist me would be greatly appreciated
There seems to be a service providing exactly what you are looking for - http://isbndb.com/docs/api/20-structure.html
Rails Code:
require 'open-uri'
class BookController < ApplicationController
def searchbook
resp = open("http://isbndb.com/api/books.xml?access_key=#{YOUR_API_KEY}&results=details&index1=isbn&value1=#{params[:isbn]}")
doc = Nokogiri.XML(resp.read)
# ... process response here
end
end
Read about nokogiri's parsing capabilities here
As for what an api actually is and how it works i think this is a good starting point.
Related
Can anyone help with using the Twitter API to upload a profile banner using the account/update_profile_banner? I have been searching on Google for so long and can't find any solution, thanks in advance
Based on https://gist.github.com/hayesdavis/97756
It looks like the docs are misleading, unless you are uploading a really small image, I expect it is critical to use multi part form data instead of encoding data in the query params.
Post your example code though, it's bad stackoverflow form to just say it doesn't work without showing the code and errors you are getting.
I do not find any way in order to modify the behaviour of the existing methods in rails_admin. I am using rails 3.2 and integrated with PostgreSql.
I want to modify the behaviour of one of my method during the edit. I have a model of shipment_quotes and model has a charges column, by default this field is blank and I want if admin add any amount in this field then after submitting the form a mail will be shoot to particular user.
But I have not found any way to modify the admin methods.
Also I want to create new actions for particular model.
Please help me I really fed up with this. After so much googling I do not find any thing relevant.
Any help will be really appreciated...
Rails Admin wouldn't do this for you. You might as well create a callback method for shipment_quotes after create. I think something like this would help
class ShipmentModel < ActiveRecord::Base
after_create :verify_charges
private
def verify_charges
if !charges.blank?
# Then shoot an email
end
end
end
Rails admin would then just handle your CRUD.
Is there any software I can install that will give me information about my API usage in Rails? I see some API management services but they are all VERY expensive and very complex. I want something to give me basic information about my API.
Also, log analysis seems a way to go. However, I'd like to know if this is the solution that is most used by companies right now. They must use something?
Thanks
if your users already have API key, you can track the activity by following code:
#applications_controller.rb (controller)
after_filter :track_api_usage
private
def track_api_usage
current_user.api_tracking(params) if params[:api_key]
end
#user.rb (model)
has_many :trackings
def api_tracking(params)
trackings.create(self.id, params)
end
Why not add an API key which users of your api need to register for, like google maps. Make it as easy as possible otherwise they wont use your api. Having a key for your API means you can prevent usage abuse of your API. I.e. if there is too much traffic from a registered address then you can cut them off.
I'm trying to write some tests for emails generated with a mailer class using rspec and email_spec (Ruby on Rails 3.0.7)
I would like to check if the layout used for rendering the email is the layout that was specified in the mailer class.
Any idea on how to do this? I've spent 3 hours searching for a solution but couldn't find anything.
Thanks!
(I realize this is a pretty late response. You've probably found a solution already)
I won't be able to update this answer much, but does this page help? It describes how to check if a layout was rendered. You could make a get request with parameters (example here) then check if the result renders the layout you want it to render.
This is cheating a little bit, since you're not really checking which template got generated...
However, I just wanted to perform a quick sanity check that the right email is (probably) being generated - so this was good enough for my needs:
# In RSpec:
expect(ActionMailer::Base.deliveries.last.subject)
.to eq I18n.t("name.of.email.subject")
# In MiniTest:
assert_equal I18n.t("name.of.email.subject"),
ActionMailer::Base.deliveries.last.subject
I want to create a google reader application that for an user(google account)I need to get all its subscriptions, for each subscription all the feeds and for each feed all its items.
Please help me with some urls in order to create the post requests for grabbing this information.
Since the google reader api is not yet released I could not find any documentation for this. I have readed this article http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI but there is not specified how to get these.
I kindly appreciate any help.
This is the best PHP class written that I have seen and used. http://code.google.com/p/greader-library/source/browse/trunk/greader.class.php?r=3
Just add your username and password then call the function "listAll" that will list all the posts that are unread. You will need to write a few functions in order to do what you want.