marvelite 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -38,32 +38,185 @@ describe Marvelite::API::Client do
38
38
  end
39
39
  end
40
40
 
41
- describe '#ts' do
42
- let(:client) { Marvelite::API::Client.new(:public_key => '1234', :private_key => 'abcd') }
41
+ context "private methods" do
42
+ describe '#ts' do
43
+ let(:client) { Marvelite::API::Client.new(:public_key => '1234', :private_key => 'abcd') }
44
+
45
+ it 'calls Time.now' do
46
+ Time.should_receive(:now)
47
+ client.send(:ts)
48
+ end
43
49
 
44
- it 'calls Time.now' do
45
- Time.should_receive(:now)
46
- client.ts
50
+ it 'represents a timestamp converted to integer' do
51
+ expect(client.send(:ts)).to be_a(Integer)
52
+ end
47
53
  end
48
-
49
- it 'represents a timestamp converted to integer' do
50
- expect(client.ts).to be_a(Integer)
54
+
55
+ describe '#params' do
56
+ let(:client) { Marvelite::API::Client.new(:public_key => '1234', :private_key => 'abcd') }
57
+
58
+ it 'passes required API params to all requests' do
59
+ client.stub(:ts).and_return('1')
60
+ expect(client.send(:params)).to eq({:apikey => client.public_key, :ts => '1', :hash => 'ffd275c5130566a2916217b101f26150'})
61
+ end
51
62
  end
52
63
  end
53
64
 
54
- describe '#params' do
55
- let(:client) { Marvelite::API::Client.new(:public_key => '1234', :private_key => 'abcd') }
65
+ context "helper methods" do
66
+ describe '#find_character_by_name' do
67
+ let(:client) { marvelite_test_client }
68
+
69
+ before do
70
+ stub_get('characters?name=Spider-Man&apikey=123456&ts=1&hash=d4f1bab013916a533ef31e3ad5fb0887', 'character.json')
71
+ end
72
+
73
+ it 'retrieves a character through its name' do
74
+ response = client.send(:find_character_by_name, 'Spider-Man')
75
+ expect(response[:data][:results][0][:id]).to eq(1009610)
76
+ end
56
77
 
57
- it 'passes required API params to all requests' do
58
- expect(client.params).to eq('?apikey=1234&ts=1&hash=ffd275c5130566a2916217b101f26150')
78
+ it 'can call character.id to the response' do
79
+ character = client.send(:find_character_by_name, 'Spider-Man')
80
+ expect(character.id).to eq(1009610)
81
+ end
59
82
  end
60
83
  end
61
84
 
62
- describe '#characters' do
63
- let(:client) { Marvelite::API::Client.new(:public_key => '1234', :private_key => 'abcd') }
64
85
 
65
- it 'returns a JSON response from the characters endpoint' do
66
- expect(client.characters).to eq('http://gateway.marvel.com/v1/public/characters?apikey=1234&ts=1&hash=ffd275c5130566a2916217b101f26150')
86
+ context "Character Endpoints" do
87
+ let(:client) { marvelite_test_client }
88
+
89
+ describe '#characters' do
90
+ before do
91
+ stub_get('characters?apikey=123456&ts=1&hash=d4f1bab013916a533ef31e3ad5fb0887', 'characters.json')
92
+ end
93
+
94
+ it 'returns a Marvelite::API::Response object' do
95
+ expect(client.characters).to be_a(Marvelite::API::Response)
96
+ end
97
+
98
+ it 'Response object is populated with JSON from the characters endpoint' do
99
+ expect(client.characters["status"]).to eq("Ok")
100
+ expect(client.characters[:data][:results].size).to eq(20)
101
+ end
102
+ end
103
+
104
+ describe '#character' do
105
+ before do
106
+ stub_get('characters?name=Spider-Man&apikey=123456&ts=1&hash=d4f1bab013916a533ef31e3ad5fb0887', 'character.json')
107
+ stub_get('characters/1009610?apikey=123456&ts=1&hash=d4f1bab013916a533ef31e3ad5fb0887', 'character.json')
108
+ end
109
+ it 'returns a Marvelite::API::Response object' do
110
+ expect(client.character(1009610)).to be_a(Marvelite::API::Response)
111
+ end
112
+
113
+ it 'Response object is populated with JSON from the character endpoint' do
114
+ expect(client.character(1009610)[:data][:results][0][:name]).to eq('Spider-Man')
115
+ end
116
+
117
+ it 'accepts an Integer as character id' do
118
+ expect(client.character(1009610)[:data][:results][0][:name]).to eq('Spider-Man')
119
+ end
120
+
121
+ it 'accepts a String as character name' do
122
+ expect(client.character('Spider-Man')[:data][:results][0][:name]).to eq('Spider-Man')
123
+ end
124
+ end
125
+
126
+ describe '#character_comics' do
127
+ before do
128
+ stub_get('characters/1009610/comics?apikey=123456&ts=1&hash=d4f1bab013916a533ef31e3ad5fb0887', 'character_comics.json')
129
+ end
130
+
131
+ it 'returns a Marvelite::API::Response object' do
132
+ expect(client.character_comics(1009610)).to be_a(Marvelite::API::Response)
133
+ end
134
+
135
+ it 'Response object is populated with JSON from the characters endpoint' do
136
+ expect(client.character_comics(1009610)["status"]).to eq("Ok")
137
+ expect(client.character_comics(1009610)[:data][:results].size).to eq(20)
138
+ end
139
+
140
+ it 'accepts an Integer as character id' do
141
+ expect(client.character_comics(1009610)[:data][:results][0][:title]).to eq('Superior Spider-Man (2013) #22')
142
+ end
143
+
144
+ it 'accetps a String as character id' do
145
+ expect(client.character_comics('Spider-Man')["status"]).to eq("Ok")
146
+ expect(client.character_comics('Spider-Man')[:data][:results].size).to eq(20)
147
+ end
148
+ end
149
+
150
+ describe '#character_events' do
151
+ before do
152
+ stub_get('characters/1009610/events?apikey=123456&ts=1&hash=d4f1bab013916a533ef31e3ad5fb0887', 'character_events.json')
153
+ end
154
+
155
+ it 'returns a Marvelite::API::Response object' do
156
+ expect(client.character_events(1009610)).to be_a(Marvelite::API::Response)
157
+ end
158
+
159
+ it 'Response object is populated with JSON from the characters endpoint' do
160
+ expect(client.character_events(1009610)["status"]).to eq("Ok")
161
+ expect(client.character_events(1009610)[:data][:results].size).to eq(20)
162
+ end
163
+
164
+ it 'accepts an Integer as character id' do
165
+ expect(client.character_events(1009610)[:data][:results][0][:title]).to eq('Acts of Vengeance!')
166
+ end
167
+
168
+ it 'accetps a String as character id' do
169
+ expect(client.character_comics('Spider-Man')["status"]).to eq("Ok")
170
+ expect(client.character_comics('Spider-Man')[:data][:results].size).to eq(20)
171
+ end
172
+ end
173
+
174
+ describe '#character_series' do
175
+ before do
176
+ stub_get('characters/1009610/series?apikey=123456&ts=1&hash=d4f1bab013916a533ef31e3ad5fb0887', 'character_series.json')
177
+ end
178
+
179
+ it 'returns a Marvelite::API::Response object' do
180
+ expect(client.character_series(1009610)).to be_a(Marvelite::API::Response)
181
+ end
182
+
183
+ it 'Response object is populated with JSON from the characters endpoint' do
184
+ expect(client.character_series(1009610)["status"]).to eq("Ok")
185
+ expect(client.character_series(1009610)[:data][:results].size).to eq(20)
186
+ end
187
+
188
+ it 'accepts an Integer as character id' do
189
+ expect(client.character_series(1009610)[:data][:results][0][:title]).to eq('A+X (2012 - Present)')
190
+ end
191
+
192
+ it 'accetps a String as character id' do
193
+ expect(client.character_comics('Spider-Man')["status"]).to eq("Ok")
194
+ expect(client.character_comics('Spider-Man')[:data][:results].size).to eq(20)
195
+ end
196
+ end
197
+
198
+ describe '#character_stories' do
199
+ before do
200
+ stub_get('characters/1009610/stories?apikey=123456&ts=1&hash=d4f1bab013916a533ef31e3ad5fb0887', 'character_stories.json')
201
+ end
202
+
203
+ it 'returns a Marvelite::API::Response object' do
204
+ expect(client.character_stories(1009610)).to be_a(Marvelite::API::Response)
205
+ end
206
+
207
+ it 'Response object is populated with JSON from the characters endpoint' do
208
+ expect(client.character_stories(1009610)["status"]).to eq("Ok")
209
+ expect(client.character_stories(1009610)[:data][:results].size).to eq(20)
210
+ end
211
+
212
+ it 'accepts an Integer as character id' do
213
+ expect(client.character_stories(1009610)[:data][:results][0][:title]).to eq('Interior #483')
214
+ end
215
+
216
+ it 'accetps a String as character id' do
217
+ expect(client.character_comics('Spider-Man')["status"]).to eq("Ok")
218
+ expect(client.character_comics('Spider-Man')[:data][:results].size).to eq(20)
219
+ end
67
220
  end
68
221
  end
69
222
  end
data/spec/spec_helper.rb CHANGED
@@ -1,2 +1,37 @@
1
1
  require 'marvelite'
2
- require 'pry'
2
+ require 'pry'
3
+ require 'pathname'
4
+ require 'json'
5
+ require 'hashie'
6
+ require 'fakeweb'
7
+
8
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
9
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
10
+
11
+ RSpec.configure do |config|
12
+ FakeWeb.allow_net_connect = false
13
+
14
+ def marvel_url(url)
15
+ "http://gateway.marvel.com/v1/public/#{url}"
16
+ end
17
+
18
+ def marvelite_test_client
19
+ client = Marvelite::API::Client.new(:public_key => '123456', :private_key => 'abcdef')
20
+ client.stub(:ts).and_return('1')
21
+ client.stub(:hash).and_return('d4f1bab013916a533ef31e3ad5fb0887')
22
+ client
23
+ end
24
+
25
+ def json_response(filename)
26
+ file = Pathname("./spec/fixtures/#{filename}")
27
+ file.read
28
+ end
29
+
30
+ def stub_get(url, filename, options={})
31
+ opts = {
32
+ :body => json_response(filename),
33
+ :content_type => 'application/json; charset=utf-8'
34
+ }.merge(options)
35
+ FakeWeb.register_uri(:get, marvel_url(url), opts)
36
+ end
37
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marvelite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antonio Antillon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-03 00:00:00.000000000 Z
11
+ date: 2014-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: fakeweb
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '1.3'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: '1.3'
111
125
  description: Simple wrapper around the Marvel Comics API
112
126
  email:
113
127
  - antillas21@gmail.com
@@ -120,9 +134,16 @@ files:
120
134
  - lib/marvelite/api/router.rb
121
135
  - lib/marvelite/version.rb
122
136
  - lib/marvelite.rb
137
+ - spec/fixtures/character.json
138
+ - spec/fixtures/character_comics.json
139
+ - spec/fixtures/character_events.json
140
+ - spec/fixtures/character_series.json
141
+ - spec/fixtures/character_stories.json
142
+ - spec/fixtures/characters.json
123
143
  - spec/marvelite/api/client_spec.rb
124
144
  - spec/marvelite/api/router_spec.rb
125
145
  - spec/spec_helper.rb
146
+ - CHANGELOG.md
126
147
  - Gemfile
127
148
  - LICENSE.txt
128
149
  - Rakefile
@@ -152,6 +173,12 @@ signing_key:
152
173
  specification_version: 4
153
174
  summary: Simple wrapper around the Marvel Comics API
154
175
  test_files:
176
+ - spec/fixtures/character.json
177
+ - spec/fixtures/character_comics.json
178
+ - spec/fixtures/character_events.json
179
+ - spec/fixtures/character_series.json
180
+ - spec/fixtures/character_stories.json
181
+ - spec/fixtures/characters.json
155
182
  - spec/marvelite/api/client_spec.rb
156
183
  - spec/marvelite/api/router_spec.rb
157
184
  - spec/spec_helper.rb