Class: Alibris::Search
Instance Method Summary collapse
- #books(search_term = nil, author = nil, title = nil, topic = nil, options = {}) ⇒ Object
- #books_by_author(author, options = {}) ⇒ Object
- #books_by_title(title, options = {}) ⇒ Object
- #books_by_topic(topic, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Search
constructor
A new instance of Search.
- #music(search_term = nil, author = nil, title = nil, topic = nil, options = {}) ⇒ Object
- #music_by_author(author, options = {}) ⇒ Object
- #music_by_title(title, options = {}) ⇒ Object
- #music_by_topic(topic, options = {}) ⇒ Object
- #videos(search_term = nil, author = nil, title = nil, topic = nil, options = {}) ⇒ Object
- #videos_by_author(author, options = {}) ⇒ Object
- #videos_by_title(title, options = {}) ⇒ Object
- #videos_by_topic(topic, options = {}) ⇒ Object
- #works(search_term = nil, author = nil, title = nil, topic = nil, options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Search
Returns a new instance of Search.
11 12 13 14 15 |
# File 'lib/alibris.rb', line 11 def initialize( = {}) @api_key = [:api_key] # required @output_type = [:output_type] # optional, valid values ['json', 'xml'], defaults to xml @num_results = [:num_results] # optional, number of results returned, defaults to 25 end |
Instance Method Details
#books(search_term = nil, author = nil, title = nil, topic = nil, options = {}) ⇒ Object
35 36 37 38 |
# File 'lib/alibris.rb', line 35 def books(search_term=nil, =nil, title=nil, topic=nil, ={}) opts = .merge({:mtype => 'B'}) works(search_term, , title, topic, opts) end |
#books_by_author(author, options = {}) ⇒ Object
39 40 41 |
# File 'lib/alibris.rb', line 39 def (, ={}) books(nil, , nil, nil, ) end |
#books_by_title(title, options = {}) ⇒ Object
42 43 44 |
# File 'lib/alibris.rb', line 42 def books_by_title(title, ={}) books(nil, nil, title, nil, ) end |
#books_by_topic(topic, options = {}) ⇒ Object
45 46 47 |
# File 'lib/alibris.rb', line 45 def books_by_topic(topic, ={}) books(nil, nil, nil, topic, ) end |
#music(search_term = nil, author = nil, title = nil, topic = nil, options = {}) ⇒ Object
48 49 50 51 |
# File 'lib/alibris.rb', line 48 def music(search_term=nil, =nil, title=nil, topic=nil, ={}) opts = .merge({:mtype => 'M'}) works(search_term, , title, topic, opts) end |
#music_by_author(author, options = {}) ⇒ Object
52 53 54 |
# File 'lib/alibris.rb', line 52 def (, ={}) music(nil, , nil, nil, ) end |
#music_by_title(title, options = {}) ⇒ Object
55 56 57 |
# File 'lib/alibris.rb', line 55 def music_by_title(title, ={}) music(nil, nil, title, nil, ) end |
#music_by_topic(topic, options = {}) ⇒ Object
58 59 60 |
# File 'lib/alibris.rb', line 58 def music_by_topic(topic, ={}) music(nil, nil, nil, topic, ) end |
#videos(search_term = nil, author = nil, title = nil, topic = nil, options = {}) ⇒ Object
61 62 63 64 |
# File 'lib/alibris.rb', line 61 def videos(search_term=nil, =nil, title=nil, topic=nil, ={}) opts = .merge({:mtype => 'V'}) works(search_term, , title, topic, opts) end |
#videos_by_author(author, options = {}) ⇒ Object
65 66 67 |
# File 'lib/alibris.rb', line 65 def (, ={}) videos(nil, , nil, nil, ) end |
#videos_by_title(title, options = {}) ⇒ Object
68 69 70 |
# File 'lib/alibris.rb', line 68 def videos_by_title(title, ={}) videos(nil, nil, title, nil, ) end |
#videos_by_topic(topic, options = {}) ⇒ Object
71 72 73 |
# File 'lib/alibris.rb', line 71 def videos_by_topic(topic, ={}) videos(nil, nil, nil, topic, ) end |
#works(search_term = nil, author = nil, title = nil, topic = nil, options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/alibris.rb', line 17 def works(search_term=nil, =nil, title=nil, topic=nil, ={}) if @api_key.nil? # TODO: Create a custom exception raise Exception.new("An API Key is required to use the Alibris API. Get a key from http://developer.alibris.com") end if (.nil? && title.nil? && topic.nil? && search_term.nil?) raise Exception.new("You either need to pass an author, a title, a topic or a search term, to perform searches.") end path = "/" .merge!({:apikey => @api_key}) unless @api_key.nil? .merge!({:outputtype => @output_type}) unless @output_type.nil? .merge!({:wauth => }) unless .nil? .merge!({:wtit => title}) unless title.nil? .merge!({:wtopic => topic}) unless topic.nil? .merge!({:wquery => search_term}) unless search_term.nil? .merge!({:chunk => @num_results}) unless @num_results.nil? Hashie::Mash.new Alibris::Search.get(path, :query => ) end |