Class: ComicVine::API
- Inherits:
-
Object
- Object
- ComicVine::API
- Defined in:
- lib/comic_vine.rb
Constant Summary collapse
- @@key =
nil
- @@types =
nil
- @@last_type_check =
nil
- @@API_BASE_URL =
"http://www.comicvine.com/api/"
Class Method Summary collapse
- .find_detail(type) ⇒ Object
- .find_list(type) ⇒ Object
- .get_details(item_type, id, opts = nil) ⇒ Object
- .get_details_by_url(url) ⇒ Object
- .get_list(list_type, opts = nil) ⇒ Object
- .key ⇒ Object
- .key=(key) ⇒ Object
- .method_missing(method_sym, *arguments, &block) ⇒ Object
- .search(res, query, opts = {}) ⇒ Object
- .types ⇒ Object
Class Method Details
.find_detail(type) ⇒ Object
31 32 33 |
# File 'lib/comic_vine.rb', line 31 def find_detail type types.find { |t| t['detail_resource_name'] == type } end |
.find_list(type) ⇒ Object
27 28 29 |
# File 'lib/comic_vine.rb', line 27 def find_list type types.find { |t| t['list_resource_name'] == type } end |
.get_details(item_type, id, opts = nil) ⇒ Object
66 67 68 69 |
# File 'lib/comic_vine.rb', line 66 def get_details item_type, id, opts=nil resp = hit_api(build_base_url("#{item_type}/#{id}"), build_query(opts)) ComicVine::CVObject.new(resp['results']) end |
.get_details_by_url(url) ⇒ Object
71 72 73 74 |
# File 'lib/comic_vine.rb', line 71 def get_details_by_url url resp = hit_api(url) ComicVine::CVObject.new(resp['results']) end |
.get_list(list_type, opts = nil) ⇒ Object
61 62 63 64 |
# File 'lib/comic_vine.rb', line 61 def get_list list_type, opts=nil resp = hit_api(build_base_url(list_type), build_query(opts)) ComicVine::CVObjectList.new(resp, list_type) end |
.key ⇒ Object
45 46 47 |
# File 'lib/comic_vine.rb', line 45 def key @@key end |
.key=(key) ⇒ Object
49 50 51 |
# File 'lib/comic_vine.rb', line 49 def key= key @@key = key end |
.method_missing(method_sym, *arguments, &block) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/comic_vine.rb', line 35 def method_missing(method_sym, *arguments, &block) if find_list(method_sym.to_s) get_list method_sym.to_s, arguments.first elsif find_detail(method_sym.to_s) get_details method_sym.to_s, *arguments elsif super end end |
.search(res, query, opts = {}) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/comic_vine.rb', line 20 def search res, query, opts={} opts[:resources] = res.gsub " ", "" opts[:query] = CGI::escape query resp = hit_api(build_base_url("search"), build_query(opts)) ComicVine::CVSearchList.new(resp, res, query) end |
.types ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/comic_vine.rb', line 53 def types if @@types.nil? || (@@last_type_check + (4 *60 *60)) < Time.now @@last_type_check = Time.now @@types = hit_api(build_base_url('types'))['results'] end @@types end |