comic_vine 0.0.8 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/comic_vine.gemspec +2 -0
- data/lib/comic_vine/version.rb +1 -1
- data/lib/comic_vine.rb +1 -1
- data/spec/comic_vine_spec.rb +115 -4
- data/spec/spec_helper.rb +21 -1
- metadata +28 -8
- data/spec/cv_object_spec.rb +0 -10
data/.gitignore
CHANGED
data/comic_vine.gemspec
CHANGED
data/lib/comic_vine/version.rb
CHANGED
data/lib/comic_vine.rb
CHANGED
@@ -50,7 +50,7 @@ module ComicVine
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def types
|
53
|
-
if @@types.nil? || (@@last_type_check + (4 *60 *60))
|
53
|
+
if @@types.nil? || (@@last_type_check + (4 *60 *60)) < Time.now
|
54
54
|
@@last_type_check = Time.now
|
55
55
|
@@types = hit_api(build_base_url('types'))['results']
|
56
56
|
end
|
data/spec/comic_vine_spec.rb
CHANGED
@@ -1,11 +1,122 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
describe ComicVine do
|
3
|
-
|
3
|
+
before(:all) do
|
4
4
|
ComicVine::API.key = "some_api_key"
|
5
|
-
ComicVine::API.key.should == "some_api_key"
|
6
5
|
end
|
7
6
|
|
8
|
-
|
9
|
-
|
7
|
+
specify { ComicVine::API.key.should == "some_api_key" }
|
8
|
+
|
9
|
+
context "when has invalid api key" do
|
10
|
+
it "should get a CVError" do
|
11
|
+
WebMock.allow_net_connect!
|
12
|
+
lambda { ComicVine::API.issues }.should raise_error(ComicVine::CVError)
|
13
|
+
WebMock.disable_net_connect!
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when has valid api key" do
|
18
|
+
before { stub_request(:get, "http://api.comicvine.com/types/").with(:query => {:format => 'json', :api_key => ComicVine::API.key}, :headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).to_return(:status => 200, :body => TYPES_BODY, :headers => {}) }
|
19
|
+
|
20
|
+
describe "invalid method" do
|
21
|
+
it "should raise NoMethodError" do
|
22
|
+
lambda { ComicVine::API.something }.should raise_error(NoMethodError)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "types_detail" do
|
27
|
+
before { @types_detail = ComicVine::API.find_detail "issue" }
|
28
|
+
subject { @types_detail }
|
29
|
+
|
30
|
+
specify { @types_detail["list_resource_name"].should == "issues" }
|
31
|
+
specify { @types_detail["detail_resource_name"].should == "issue" }
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "types_list" do
|
35
|
+
before { @types_list = ComicVine::API.find_list "issues" }
|
36
|
+
subject { @types_list }
|
37
|
+
|
38
|
+
specify { @types_list["list_resource_name"].should == "issues" }
|
39
|
+
specify { @types_list["detail_resource_name"].should == "issue" }
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "ComicVine search" do
|
43
|
+
before do
|
44
|
+
stub_request(:get, "http://api.comicvine.com/search/").with(:query => {:format => 'json', :api_key => ComicVine::API.key, :limit => 1, :resources => "volume", :query => "gizmo"}, :headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).to_return(:status => 200, :body => SEARCH_BODY_1, :headers => {})
|
45
|
+
stub_request(:get, "http://api.comicvine.com/search/").with(:query => {:format => 'json', :api_key => ComicVine::API.key, :limit => 1, :offset => 0, :resources => "volume", :query => "gizmo"}, :headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).to_return(:status => 200, :body => SEARCH_BODY_1, :headers => {})
|
46
|
+
stub_request(:get, "http://api.comicvine.com/search/").with(:query => {:format => 'json', :api_key => ComicVine::API.key, :limit => 1, :offset => 1, :resources => "volume", :query => "gizmo"}, :headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).to_return(:status => 200, :body => SEARCH_BODY_2, :headers => {})
|
47
|
+
@results = ComicVine::API.search "volume", "gizmo", {:limit => 1}
|
48
|
+
end
|
49
|
+
subject { @results }
|
50
|
+
|
51
|
+
it { should be_a_kind_of ComicVine::CVSearchList }
|
52
|
+
it { should respond_to("total_count", "offset", "limit", "resource", "query")}
|
53
|
+
specify { @results.first.should be_a_kind_of ComicVine::CVSearchObject }
|
54
|
+
specify { @results.first.should == @results.last }
|
55
|
+
specify { @results.prev_page.should be_nil }
|
56
|
+
|
57
|
+
context "when on last page" do
|
58
|
+
before { @results.next_page }
|
59
|
+
|
60
|
+
specify { @results.should be_a_kind_of ComicVine::CVSearchList }
|
61
|
+
specify { @results.next_page.should be_nil }
|
62
|
+
it "should update the list on prev_page" do
|
63
|
+
@results.prev_page
|
64
|
+
@results.should be_a_kind_of ComicVine::CVSearchList
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should fetch the full CVObject" do
|
69
|
+
stub_request(:get, "http://api.comicvine.com/volume/24708/").with(:query => {:format => 'json', :api_key => ComicVine::API.key}, :headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).to_return(:status => 200, :body => VOLUME_BODY, :headers => {})
|
70
|
+
vol = @results.first.fetch
|
71
|
+
vol.should be_a_kind_of ComicVine::CVObject
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "ComicVine list" do
|
76
|
+
before do
|
77
|
+
stub_request(:get, "http://api.comicvine.com/issues/").with(:query => {:format => 'json', :api_key => ComicVine::API.key}, :headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).to_return(:status => 200, :body => ISSUES_BODY_1, :headers => {})
|
78
|
+
stub_request(:get, "http://api.comicvine.com/issues/").with(:query => {:format => 'json', :api_key => ComicVine::API.key, :limit => 2, :offset => 0}, :headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).to_return(:status => 200, :body => ISSUES_BODY_1, :headers => {})
|
79
|
+
stub_request(:get, "http://api.comicvine.com/issues/").with(:query => {:format => 'json', :api_key => ComicVine::API.key, :limit => 2, :offset => 2}, :headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).to_return(:status => 200, :body => ISSUES_BODY_2, :headers => {})
|
80
|
+
@issues = ComicVine::API.issues
|
81
|
+
end
|
82
|
+
subject { @issues }
|
83
|
+
|
84
|
+
it { should be_a_kind_of ComicVine::CVList }
|
85
|
+
it { should respond_to("total_count", "offset", "limit", "resource")}
|
86
|
+
specify { @issues.prev_page.should be_nil }
|
87
|
+
|
88
|
+
context "when on last page" do
|
89
|
+
before { @issues.next_page }
|
90
|
+
|
91
|
+
specify { @issues.should be_a_kind_of ComicVine::CVList }
|
92
|
+
specify { @issues.next_page.should be_nil }
|
93
|
+
it "should update the list on prev_page" do
|
94
|
+
@issues.prev_page
|
95
|
+
@issues.should be_a_kind_of ComicVine::CVList
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "ComicVine detail" do
|
101
|
+
before do
|
102
|
+
stub_request(:get, "http://api.comicvine.com/issue/145830/").with(:query => {:format => 'json', :api_key => ComicVine::API.key}, :headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).to_return(:status => 200, :body => ISSUE_BODY, :headers => {})
|
103
|
+
@issue = ComicVine::API.issue 145830
|
104
|
+
end
|
105
|
+
subject { @issue }
|
106
|
+
|
107
|
+
it { should be_a_kind_of ComicVine::CVObject }
|
108
|
+
it { should respond_to("site_detail_url", "publish_year")}
|
109
|
+
specify { lambda { @issue.something }.should raise_error(NoMethodError) }
|
110
|
+
specify { lambda { @issue.get_something }.should raise_error(NoMethodError) }
|
111
|
+
|
112
|
+
it "should have a detail and list association" do
|
113
|
+
stub_request(:get, "http://api.comicvine.com/volume/24708/").with(:query => {:format => 'json', :api_key => ComicVine::API.key}, :headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).to_return(:status => 200, :body => VOLUME_BODY, :headers => {})
|
114
|
+
vol = @issue.get_volume
|
115
|
+
vol.should be_a_kind_of ComicVine::CVObject
|
116
|
+
iss = vol.get_issues
|
117
|
+
iss.should be_a_kind_of Array
|
118
|
+
iss.first.should be_a_kind_of ComicVine::CVObject
|
119
|
+
end
|
120
|
+
end
|
10
121
|
end
|
11
122
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,11 +4,31 @@
|
|
4
4
|
# loaded once.
|
5
5
|
#
|
6
6
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
require 'simplecov'
|
8
|
+
SimpleCov.start
|
7
9
|
|
8
10
|
require 'comic_vine'
|
11
|
+
#require 'webmock'
|
12
|
+
require 'webmock/rspec'
|
13
|
+
|
9
14
|
|
10
15
|
RSpec.configure do |config|
|
11
16
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
12
17
|
config.run_all_when_everything_filtered = true
|
13
|
-
config.filter_run :focus
|
18
|
+
#config.filter_run :focus
|
14
19
|
end
|
20
|
+
|
21
|
+
TYPES_BODY = '{"number_of_page_results": 17, "status_code": 1, "error": "OK", "results": [{"detail_resource_name": "issue", "id": 37, "list_resource_name": "issues"}, {"detail_resource_name": "volume", "id": 49, "list_resource_name": "volumes"}], "limit": 17, "offset": 0, "number_of_total_results": 17}'
|
22
|
+
|
23
|
+
ISSUE_BODY = '{"number_of_page_results": 1, "status_code": 1, "error": "OK", "results": {"site_detail_url": "http://www.comicvine.com/gizmo-/37-145830/", "id": 145830, "volume": {"api_detail_url": "http://api.comicvine.com/volume/24708/", "id": 24708, "name": "Gizmo"}, "publish_year": null}, "limit": 1, "offset": 0, "number_of_total_results": 1}'
|
24
|
+
|
25
|
+
ISSUES_BODY_1 = '{"number_of_page_results": 2, "status_code": 1, "error": "OK", "results": [{"api_detail_url": "http://api.comicvine.com/issue/6/", "site_detail_url": "http://www.comicvine.com/chamber-of-chills-magazine-man-in-the-hood-the-lost-race-the-man-germ-the-things/37-6/", "description": "", "deck": "", "aliases": "", "issue_number": "13.00", "publish_year": 1952, "has_staff_review": false, "date_added": "2008-06-06 11:10:16", "publish_day": null, "publish_month": 10, "id": 6, "name": "Man In the Hood; The Lost Race; The Man Germ; The Things; "}, {"api_detail_url": "http://api.comicvine.com/issue/7/", "site_detail_url": "http://www.comicvine.com/fighting-fronts-/37-7/", "description": "", "deck": "", "aliases": "", "issue_number": "3.00", "publish_year": 0, "has_staff_review": false, "date_added": "2008-06-06 11:10:16", "publish_day": null, "publish_month": 0, "id": 7, "name": ""}], "limit": 2, "offset": 0, "number_of_total_results": 4}'
|
26
|
+
|
27
|
+
ISSUES_BODY_2 = '{"number_of_page_results": 2, "status_code": 1, "error": "OK", "results": [{"api_detail_url": "http://api.comicvine.com/issue/6/", "site_detail_url": "http://www.comicvine.com/chamber-of-chills-magazine-man-in-the-hood-the-lost-race-the-man-germ-the-things/37-6/", "description": "", "deck": "", "aliases": "", "date_last_updated": "2009-01-27 12:47:44", "volume": {"api_detail_url": "http://api.comicvine.com/volume/1487/", "id": 1487, "name": "Chamber of Chills Magazine"}, "issue_number": "13.00", "publish_year": 1952, "has_staff_review": false, "date_added": "2008-06-06 11:10:16", "publish_day": null, "publish_month": 10, "id": 6, "name": "Man In the Hood; The Lost Race; The Man Germ; The Things; "}, {"api_detail_url": "http://api.comicvine.com/issue/7/", "site_detail_url": "http://www.comicvine.com/fighting-fronts-/37-7/", "description": "", "deck": "", "aliases": "", "date_last_updated": "2008-06-06 11:32:53", "volume": {"api_detail_url": "http://api.comicvine.com/volume/1488/", "id": 1488, "name": "Fighting Fronts!"}, "issue_number": "3.00", "publish_year": 0, "has_staff_review": false, "date_added": "2008-06-06 11:10:16", "publish_day": null, "publish_month": 0, "id": 7, "name": ""}], "limit": 2, "offset": 2, "number_of_total_results": 4}'
|
28
|
+
|
29
|
+
VOLUME_BODY = '{"number_of_page_results": 1, "status_code": 1, "error": "OK", "results": {"id": 24708, "issues": [{"api_detail_url": "http://api.comicvine.com/issue/145830/", "issue_number": "1.00", "id": 145830, "name": " "}]}, "limit": 1, "offset": 0, "number_of_total_results": 1}'
|
30
|
+
|
31
|
+
|
32
|
+
SEARCH_BODY_1 = '{"number_of_page_results": 1, "status_code": 1, "error": "OK", "results": [{"publisher": {"api_detail_url": "http://api.comicvine.com/publisher/517/", "id": 517, "name": "Mirage"}, "start_year": 1985, "description": "", "deck": "", "last_issue": null, "date_last_updated": "2010-07-04 20:51:17", "first_issue": null, "api_detail_url": "http://api.comicvine.com/volume/24708/", "count_of_issues": 6, "id": 24708, "date_added": "2008-12-12 16:58:16", "aliases": "", "site_detail_url": "http://www.comicvine.com/gizmo/49-24708/", "resource_type": "volume", "name": "Gizmo"}], "limit": 1, "offset": 0, "number_of_total_results": 2}'
|
33
|
+
|
34
|
+
SEARCH_BODY_2 = '{"number_of_page_results": 1, "status_code": 1, "error": "OK", "results": [{"publisher": {"api_detail_url": "http://api.comicvine.com/publisher/517/", "id": 517, "name": "Mirage"}, "start_year": null, "description": "", "deck": "Mirage volume starring Fugitoid and Gizmo", "last_issue": null, "date_last_updated": "2010-04-28 14:24:46", "first_issue": null, "api_detail_url": "http://api.comicvine.com/volume/32839/", "count_of_issues": 2, "id": 32839, "date_added": "2010-04-28 14:22:46", "aliases": "", "site_detail_url": "http://www.comicvine.com/gizmo-and-the-fugitoid/49-32839/", "resource_type": "volume", "name": "Gizmo and the Fugitoid"}], "limit": 1, "offset": 1, "number_of_total_results": 2}'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: comic_vine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-24 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
16
|
-
requirement: &
|
16
|
+
requirement: &70268024176560 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70268024176560
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70268024175620 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,29 @@ dependencies:
|
|
32
32
|
version: 2.0.0
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70268024175620
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: webmock
|
38
|
+
requirement: &70268024174900 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70268024174900
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: simplecov
|
49
|
+
requirement: &70268024174020 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70268024174020
|
36
58
|
description: Simple api interface to Comic Vine. Allows for searches and returning
|
37
59
|
specific information on resources.
|
38
60
|
email: jakanapes@gmail.com
|
@@ -53,7 +75,6 @@ files:
|
|
53
75
|
- lib/comic_vine/cv_object.rb
|
54
76
|
- lib/comic_vine/version.rb
|
55
77
|
- spec/comic_vine_spec.rb
|
56
|
-
- spec/cv_object_spec.rb
|
57
78
|
- spec/spec_helper.rb
|
58
79
|
homepage: https://github.com/Jakanapes/ComicVine
|
59
80
|
licenses: []
|
@@ -81,5 +102,4 @@ specification_version: 3
|
|
81
102
|
summary: Interface to ComicVine API
|
82
103
|
test_files:
|
83
104
|
- spec/comic_vine_spec.rb
|
84
|
-
- spec/cv_object_spec.rb
|
85
105
|
- spec/spec_helper.rb
|
data/spec/cv_object_spec.rb
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
describe ComicVine::CVObject do
|
3
|
-
it "should inialize instance variables from a hash" do
|
4
|
-
h = {'something' => 'something', 'blah' => 'blah', 'number' => 100}
|
5
|
-
cvo = ComicVine::CVObject.new h
|
6
|
-
cvo.something.should == 'something'
|
7
|
-
cvo.blah.should == 'blah'
|
8
|
-
cvo.number.should == 100
|
9
|
-
end
|
10
|
-
end
|