class Aladin::Books

Attributes

per_page[RW]
ttb_key[RW]
error_code[RW]
error_msg[RW]
page[RW]
per_page[RW]
total[RW]

Public Class Methods

configure() { |self| ... } click to toggle source
# File lib/aladin/books.rb, line 6
def configure
  yield self
end
new(hash) click to toggle source
Calls superclass method
# File lib/aladin/books.rb, line 50
def initialize(hash)
  if hash["errorCode"]
    set_error(hash)
  else
    set_page_info(hash)

    super hash["item"].map {|i| Book.new(i)}
  end
end

Private Class Methods

default_params() click to toggle source
# File lib/aladin/books.rb, line 26
def default_params
  {
    :ttbkey => ttb_key,
    :QueryType => "Title",
    :SearchTarget => "Book",
    :output => "js"
  }
end
set_query(query, options = {}) click to toggle source
# File lib/aladin/books.rb, line 35
def set_query(query, options = {})
  options[:page] ||= 1
  options[:per_page] ||= per_page
  params = default_params.update(
    :Query => query,
    :start => 1 + (options[:page]-1)*options[:per_page],
    :MaxResults => options[:per_page]
  )

  uri.query = URI.encode_www_form(params)
end
uri() click to toggle source
# File lib/aladin/books.rb, line 22
def uri
  @uri ||= URI.parse('http://www.aladin.co.kr/ttb/api/ItemSearch.aspx')
end

Public Instance Methods

error?() click to toggle source
# File lib/aladin/books.rb, line 60
def error?
  @error_code.present?
end

Private Instance Methods

set_error(hash) click to toggle source
# File lib/aladin/books.rb, line 65
def set_error(hash)
  @error_code = hash["errorCode"]
  @error_msg = hash["errorMessage"]
end
set_page_info(hash) click to toggle source
# File lib/aladin/books.rb, line 70
def set_page_info(hash)
  @total = hash["totalResults"]
  @page = 1 + (hash["startIndex"]/hash["itemsPerPage"])
  @per_page = hash["itemsPerPage"]
end