Class: Saber::Book

Inherits:
Object
  • Object
show all
Defined in:
lib/saber/book.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBook

Returns a new instance of Book.



13
14
15
16
17
18
19
20
# File 'lib/saber/book.rb', line 13

def initialize
  @client = Faraday.new(url: Rc.api_url) {|c|
    c.response :follow_redirects
    c.response :json, :content_type => /\bjson$/

    c.adapter Faraday.default_adapter
  }
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



11
12
13
# File 'lib/saber/book.rb', line 11

def client
  @client
end

Class Method Details

.populate(*args) ⇒ Object

delegate to #populate



7
8
9
# File 'lib/saber/book.rb', line 7

def self.populate(*args)
  new.populate(*args)
end

Instance Method Details

#populate(isbn, filename) ⇒ Hash

Returns data.

Returns:



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/saber/book.rb', line 23

def populate(isbn, filename)
  params = {}
  rep = client.get("/books/#{isbn}", params)
  data = rep.body

  if data["status"] == 0
    data["tracker"]
  else
    Saber.ui.error "Can't populate book -- #{isbn} #{filename}."
    {}
  end
end