L
L
lavezzi12015-08-22 02:42:46
Ruby on Rails
lavezzi1, 2015-08-22 02:42:46

Extracting information from services, how does it work?

Hello. I want to make it so that a person enters into the field (in my application) the id of a book with goodreads and after saving, create a book in my database with a title and information, such as how many pages. Goodreads has a gem https://github.com/sosedoff/goodreads
I would like to know which way to dig in order to implement this? It after all by means of helpers is implemented?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Jeiwan, 2015-08-22
@Jeiwan

No, helpers are needed only to simplify layout in views.
We connect the gem, create a minimal service:

#app/services/goodreads_service.rb
class GoodreadsService
  API_KEY = 'api-ключ' (или брать из ENV или использовать rails_config)
  API_SECRET = 'секрет'

  def initialize
    Goodreads.new(api_key: API_KEY, api_secret: API_SECRET)
  end
end

Then anywhere in the controller or model (preferably) we can call GoodreadsService.new.book('31337') and get the book by id.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question