galactus 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/.hound.yml +61 -0
- data/.rspec +1 -1
- data/.rubocop.yml +2 -0
- data/README.md +545 -6
- data/Rakefile +11 -1
- data/bin/console +4 -5
- data/galactus.gemspec +12 -4
- data/lib/galactus.rb +5 -0
- data/lib/galactus/client.rb +121 -0
- data/lib/galactus/config/v1.yml +117 -0
- data/lib/galactus/response.rb +40 -0
- data/lib/galactus/router.rb +55 -0
- data/lib/galactus/version.rb +1 -1
- data/spikes/call_marvel_api.rb +50 -0
- data/spikes/call_marvel_via_galactus.rb +19 -0
- metadata +99 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58b5b3aecfe031faf4b900744ed4d20a6c7eb7a2
|
4
|
+
data.tar.gz: 554573e2e6dd89c8bcb89a66e84f5e27856d2081
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8020c45d56b4c4807d029c7b630621bc747f767edd92da93318329d8e8152ef96f027ba6b99f2d620b64eeecbd61dcbd168d79717c402abf8213fbd3779d2470
|
7
|
+
data.tar.gz: 24dd3580b6b32ef13654f6d8254151af1f549977a2dd518618d94df9cf7240b324a37b506c696ce0a3e4d3d3fdbd814f33f4eb528b7aaebea7ba5b5ec08ebf93
|
data/.gitignore
CHANGED
data/.hound.yml
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- galactus.gemspec
|
4
|
+
- spikes/*.rb
|
5
|
+
- spec/**/*
|
6
|
+
|
7
|
+
# C: Missing top-level module documentation comment.
|
8
|
+
Style/Documentation:
|
9
|
+
Enabled: false
|
10
|
+
|
11
|
+
# C: Prefer reduce over inject.
|
12
|
+
Style/CollectionMethods:
|
13
|
+
PreferredMethods:
|
14
|
+
reduce: 'inject'
|
15
|
+
|
16
|
+
# C: Use each_with_object instead of inject.
|
17
|
+
Style/EachWithObject:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
# C: Removing the preference for string single quotes
|
21
|
+
Style/StringLiterals:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
#C: Prefer fail over raise
|
25
|
+
Style/SignalException:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
Style/TrailingComma:
|
29
|
+
EnforcedStyleForMultiline: comma
|
30
|
+
|
31
|
+
# This never works for validations
|
32
|
+
Style/AlignHash:
|
33
|
+
EnforcedLastArgumentHashStyle: ignore_implicit
|
34
|
+
|
35
|
+
# align multi-line params with previous line
|
36
|
+
Style/AlignParameters:
|
37
|
+
EnforcedStyle: with_fixed_indentation
|
38
|
+
|
39
|
+
# indent `when` clause one step from `case`
|
40
|
+
Style/CaseIndentation:
|
41
|
+
IndentOneStep: true
|
42
|
+
|
43
|
+
# don't force crappy var names for reduce/inject loops...
|
44
|
+
Style/SingleLineBlockParams:
|
45
|
+
Enabled: false
|
46
|
+
|
47
|
+
# for method chains, keep the dot with the method name
|
48
|
+
Style/DotPosition:
|
49
|
+
EnforcedStyle: leading
|
50
|
+
|
51
|
+
# stop nesting so hard.
|
52
|
+
Metrics/BlockNesting:
|
53
|
+
Max: 2
|
54
|
+
|
55
|
+
# short methods, man...
|
56
|
+
Metrics/MethodLength:
|
57
|
+
Max: 15
|
58
|
+
|
59
|
+
# fewer parameters
|
60
|
+
Metrics/ParameterLists:
|
61
|
+
Max: 3
|
data/.rspec
CHANGED
data/.rubocop.yml
ADDED
data/README.md
CHANGED
@@ -1,31 +1,570 @@
|
|
1
|
+
![Galactus](http://static.comicvine.com/uploads/square_medium/3/31666/3230561-tumblr_mqd1qnuvu71qknht2o2_1280.jpg)
|
2
|
+
|
1
3
|
# Galactus
|
2
4
|
|
3
|
-
|
5
|
+
On 31 January 2014 Marvel Comics [put out a press release](http://marvel.com/news/comics/21871/marvel_announces_the_release_of_the_api_program) announcing an API connecting to Marvel's database of comics, characters, and creators.
|
6
|
+
|
7
|
+
Galactus provides a very simple wrapper for the [Marvel API](http://developer.marvel.com/) and attempts to make that API easily queryable by providing qualifier objects that allows a consumer of the API to drill down into specific details.
|
8
|
+
|
9
|
+
Galactus is a [Marvel super-villain](https://en.wikipedia.org/wiki/Galactus) who was apparently the sole survivor of a universe that existed before the 'Big Bang' that created our own universe. As accomplishments go, that's moderately impressive, to say the least.
|
4
10
|
|
5
11
|
## Installation
|
6
12
|
|
7
|
-
|
13
|
+
To get the latest stable release, add this line to your application's Gemfile:
|
8
14
|
|
9
15
|
```ruby
|
10
16
|
gem 'galactus'
|
11
17
|
```
|
12
18
|
|
13
|
-
|
19
|
+
To get the latest code:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
gem 'galactus', git: https://github.com/jnyman/galactus
|
23
|
+
```
|
24
|
+
|
25
|
+
After doing one of the above, execute the following command:
|
14
26
|
|
15
27
|
$ bundle
|
16
28
|
|
17
|
-
|
29
|
+
You can, of course, just install the gem directly like this:
|
18
30
|
|
19
31
|
$ gem install galactus
|
20
32
|
|
33
|
+
## Contents
|
34
|
+
|
35
|
+
* [Usage](#usage)
|
36
|
+
* [Endpoints](#endpoints)
|
37
|
+
|
21
38
|
## Usage
|
22
39
|
|
23
|
-
|
40
|
+
### Setting Up the Client
|
41
|
+
|
42
|
+
You need API credentials, which is a public and private key pair. You can get yours at the [Marvel Developer Portal](http://developer.marvel.com). These are required to configure and instantiate a Galactus client.
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
require 'galactus'
|
46
|
+
|
47
|
+
client = Galactus::Client.new(
|
48
|
+
public_api_key: 'your public api key',
|
49
|
+
private_api_key: 'your private api key')
|
50
|
+
```
|
51
|
+
|
52
|
+
Make sure you put in your own public and private keys that you were assigned. The `client` variable will now hold a `Galactus::Client` instance that you can call endpoint methods on.
|
53
|
+
|
54
|
+
## Endpoints
|
55
|
+
|
56
|
+
Most requests to the API, return a `Galactus::Response` object if there was a successful response or a `Galactus::ErrorResponse` if API response returns an error. These objects are the raw API response enhanced with Hashie methods.
|
57
|
+
|
58
|
+
Just about all endpoints can receive optional parameters to narrow down results and those will be documented below. Each endpoint described below links to the associated call in Marvel's interactive API tester. That link will show you a complete list of the parameters that you can pass to the relevant method.
|
59
|
+
|
60
|
+
### Character Endpoints
|
61
|
+
|
62
|
+
#### Characters
|
63
|
+
|
64
|
+
Allows you to get a list of comic characters.
|
65
|
+
|
66
|
+
See [`GET /v1/public/characters`](http://developer.marvel.com/docs#!/public/getCreatorCollection_get_0).
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
client.characters
|
70
|
+
client.characters(name: 'Spider-Man')
|
71
|
+
client.characters(limit: 10, offset: 400, orderBy: 'name')
|
72
|
+
client.characters(name: 'Thanos')
|
73
|
+
client.characters(nameStartsWith: 'Th', orderBy: 'modified')
|
74
|
+
```
|
75
|
+
|
76
|
+
#### Character
|
77
|
+
|
78
|
+
Allows you to get a single character resource. This endpoint accepts an integer or string value as the character id.
|
79
|
+
|
80
|
+
See [`GET /v1/public/characters/{characterId}`](http://developer.marvel.com/docs#!/public/getCharacterIndividual_get_1).
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
client.character(1009610)
|
84
|
+
client.character('Spider-Man')
|
85
|
+
```
|
86
|
+
|
87
|
+
#### Character Comics
|
88
|
+
|
89
|
+
Allows you to get a list of comics containing a specific character. This endpoint requires a character id value (integer or string).
|
90
|
+
|
91
|
+
See [`GET /v1/public/characters/{characterId}/comics`](http://developer.marvel.com/docs#!/public/getComicsCharacterCollection_get_2).
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
client.character_comics(1009610)
|
95
|
+
client.character_comics('Spider-Man')
|
96
|
+
client.character_comics(1009610, { format: 'graphic novel', limit: 10, orderBy: 'title' })
|
97
|
+
client.character_comics('Spider-Man', { format: 'graphic novel', limit:, orderBy: 'title' } )
|
98
|
+
client.character_comics(1009652, titleStartsWith: 'Infinity', hasDigitalIssue: true)
|
99
|
+
```
|
100
|
+
|
101
|
+
#### Character Events
|
102
|
+
|
103
|
+
Allows you to get a list of events in which a specific character appears. This endpoint requires a character id value (integer or string).
|
104
|
+
|
105
|
+
See [`GET /v1/public/characters/{characterId}/events`](http://developer.marvel.com/docs#!/public/getCharacterEventsCollection_get_3).
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
client.character_events(1009610)
|
109
|
+
client.character_events('Spider-Man')
|
110
|
+
client.character_events(1009610, { limit: 10, orderBy: 'name' })
|
111
|
+
client.character_events('Spider-Man', { limit: 10, orderBy: 'name' })
|
112
|
+
client.character_events(1009652, name: 'Infinity Gauntlet')
|
113
|
+
```
|
114
|
+
|
115
|
+
#### Character Series
|
116
|
+
|
117
|
+
Allows you to get a list of comic series in which a specific character appears. This endpoint requires a character id value (integer or string).
|
118
|
+
|
119
|
+
See [`GET /v1/public/characters/{characterId}/series`](http://developer.marvel.com/docs#!/public/getCharacterSeriesCollection_get_4).
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
client.character_series(1009610)
|
123
|
+
client.character_series('Spider-Man')
|
124
|
+
client.character_series(1009610, { seriesType: 'ongoing', limit: 10, orderBy: 'title' })
|
125
|
+
client.character_series('Spider-Man', { seriesType: 'ongoing', limit: 10, orderBy: 'title' }
|
126
|
+
client.character_series(1009652, contains: 'hardcover')
|
127
|
+
```
|
128
|
+
|
129
|
+
#### Character Stories
|
130
|
+
|
131
|
+
Allows you to get a list of comic stories featuring a specific character. This endpoint requires a character id value (integer or string).
|
132
|
+
|
133
|
+
See [`GET /v1/public/characters/{characterId}/stories`](http://developer.marvel.com/docs#!/public/getCharacterStoryCollection_get_5).
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
client.character_stories(1009610)
|
137
|
+
client.character_stories('Spider-Man')
|
138
|
+
client.character_stories(1009610, { limit: 10, offset: 20 })
|
139
|
+
client.character_stories('Spider-Man', { limit:, offset: 20 })
|
140
|
+
client.character_stories(1009652, limit: 50)
|
141
|
+
```
|
142
|
+
|
143
|
+
### Comic Endpoints
|
144
|
+
|
145
|
+
#### Comics
|
146
|
+
|
147
|
+
Allows you to get a list of comics.
|
148
|
+
|
149
|
+
See [`GET /v1/public/comics`](http://developer.marvel.com/docs#!/public/getComicsCollection_get_6).
|
150
|
+
|
151
|
+
```ruby
|
152
|
+
client.comics
|
153
|
+
client.comics(format: 'graphic novel', limit: 10, offset: 20 })
|
154
|
+
client.comics(title: 'Daredevil')
|
155
|
+
client.comics(startYear: 1950, issueNumber: 1)
|
156
|
+
```
|
157
|
+
|
158
|
+
#### Comic
|
159
|
+
|
160
|
+
Allows you to get a a single comic resource. This endpoint requires a comic id value, which must be an integer.
|
161
|
+
|
162
|
+
See [`GET /v1/public/comics/{comicId}`](http://developer.marvel.com/docs#!/public/getComicIndividual_get_7).
|
163
|
+
|
164
|
+
```ruby
|
165
|
+
client.comic(40128)
|
166
|
+
```
|
167
|
+
|
168
|
+
#### Comic Characters
|
169
|
+
|
170
|
+
Allows you to get a list of characters which appear in a specific comic. This endpoint requires a comic id value, which must be an integer.
|
171
|
+
|
172
|
+
See [`GET /v1/public/comics/{comicId}/characters`](http://developer.marvel.com/docs#!/public/getComicCharacterCollection_get_8).
|
173
|
+
|
174
|
+
```ruby
|
175
|
+
client.comic_characters(40128)
|
176
|
+
client.comic_characters(40128, orderBy: 'name', limit:, offset: 20)
|
177
|
+
client.comic_characters(34249, orderBy: 'name')
|
178
|
+
```
|
179
|
+
|
180
|
+
#### Comic Creators
|
181
|
+
|
182
|
+
Allows you to get a list of comic creators whose work appears in a specific comic. This endpoint requires a comic id value, which must be an integer.
|
183
|
+
|
184
|
+
See [`GET /v1/public/comics/{comicId}/creators`](http://developer.marvel.com/docs#!/public/getCreatorCollection_get_9).
|
185
|
+
|
186
|
+
```ruby
|
187
|
+
client.comic_creators(40128)
|
188
|
+
client.comic_creators(40128, lastName: 'Romita')
|
189
|
+
client.comic_creators(34249, lastNameStartsWith: 'V')
|
190
|
+
```
|
191
|
+
|
192
|
+
#### Comic Events
|
193
|
+
|
194
|
+
Allows you to get a list of events in which a comic appears. This endpoint requires a comic id value, which must be an integer.
|
195
|
+
|
196
|
+
See [`GET /v1/public/comics/{comicId}/events`](http://developer.marvel.com/docs#!/public/getIssueEventsCollection_get_10).
|
197
|
+
|
198
|
+
```ruby
|
199
|
+
client.comic_events(40128)
|
200
|
+
client.comic_events(40128, orderBy: 'name', limit: 10)
|
201
|
+
client.comic_events(27272, orderBy: '-startDate')
|
202
|
+
```
|
203
|
+
|
204
|
+
#### Comic Stories
|
205
|
+
|
206
|
+
Allows you to get a list of comic stories in a specific comic issue. This endpoint requires a comic id value, which must be an integer.
|
207
|
+
|
208
|
+
See [`GET /v1/public/comics/{comicId}/stories`](http://developer.marvel.com/docs#!/public/getComicStoryCollection_get_11).
|
209
|
+
|
210
|
+
```ruby
|
211
|
+
client.comic_stories(40128)
|
212
|
+
client.comic_stories(40128, orderBy: 'name', limit: 10)
|
213
|
+
client.comic_stories(27272, creators: [600, 801])
|
214
|
+
```
|
215
|
+
|
216
|
+
### Creator Endpoints
|
217
|
+
|
218
|
+
#### Creators
|
219
|
+
|
220
|
+
Allows you to get a lists of creators.
|
221
|
+
|
222
|
+
See [`GET /v1/public/creators`](http://developer.marvel.com/docs#!/public/getCreatorCollection_get_12).
|
223
|
+
|
224
|
+
```ruby
|
225
|
+
client.creators
|
226
|
+
client.creators(firstName: 'Frank', lastName: 'Miller')
|
227
|
+
client.creators(lastNameStartsWith: 'Mo', limit: 20, offset: 20)
|
228
|
+
```
|
229
|
+
|
230
|
+
#### Creator
|
231
|
+
|
232
|
+
Allows you to get a single creator resource. This endpoint requires a creator id value, which must be an integer.
|
233
|
+
|
234
|
+
See [`GET /v1/public/creators/{creatorId}`](http://developer.marvel.com/docs#!/public/getCreatorIndividual_get_13).
|
235
|
+
|
236
|
+
```ruby
|
237
|
+
client.creator(15)
|
238
|
+
```
|
239
|
+
|
240
|
+
### Creator Comics
|
241
|
+
|
242
|
+
Allows you to get a list of comics from a given creator. This endpoint requires a creator id value, which must be an integer.
|
243
|
+
|
244
|
+
See [`GET /v1/public/creators/{creatorId}/comics`](http://developer.marvel.com/docs#!/public/getComicsCollection_get_14).
|
245
|
+
|
246
|
+
```ruby
|
247
|
+
client.creator_comics(15)
|
248
|
+
client.creator_comics(15, format: 'trade paperback')
|
249
|
+
```
|
250
|
+
|
251
|
+
#### Creator Events
|
252
|
+
|
253
|
+
Allows you to get a list of events from a given creator. This endpoint requires a creator id value, which must be an integer.
|
254
|
+
|
255
|
+
See [`GET /v1/public/creators/{creatorId}/events`](http://developer.marvel.com/docs#!/public/getCreatorEventsCollection_get_15).
|
256
|
+
|
257
|
+
```ruby
|
258
|
+
client.creator_events(30)
|
259
|
+
client.creator_events(30, nameStartsWith: 'Civil')
|
260
|
+
```
|
261
|
+
|
262
|
+
#### Creator Series
|
263
|
+
|
264
|
+
Allows you to get a list of series from a given creator. This endpoint requires a creator id value, which must be an integer.
|
265
|
+
|
266
|
+
See [`GET /v1/public/creators/{creatorId}/series`](http://developer.marvel.com/docs#!/public/getCreatorSeriesCollection_get_16).
|
267
|
+
|
268
|
+
```ruby
|
269
|
+
client.creator_series(30)
|
270
|
+
client.creator_series(30, seriesType: 'limited')
|
271
|
+
```
|
272
|
+
|
273
|
+
#### Creator Stories
|
274
|
+
|
275
|
+
Allows you to get a list of stories from a given creator. This endpoint requires a creator id value, which must be an integer.
|
276
|
+
|
277
|
+
See [`GET /v1/public/creators/{creatorId}/stories`](http://developer.marvel.com/docs#!/public/getCreatorStoryCollection_get_17).
|
278
|
+
|
279
|
+
```ruby
|
280
|
+
client.creator_stories(30)
|
281
|
+
client.creator_stories(30, limit: 40, offset: 7750)
|
282
|
+
```
|
283
|
+
|
284
|
+
### Event Endpoints
|
285
|
+
|
286
|
+
#### Events
|
287
|
+
|
288
|
+
Allows you to get a list of events.
|
289
|
+
|
290
|
+
See [`GET /v1/public/events`](http://developer.marvel.com/docs#!/public/getEventsCollection_get_18).
|
291
|
+
|
292
|
+
```ruby
|
293
|
+
client.events
|
294
|
+
client.events(name: 'Acts of Vengeance')
|
295
|
+
client.events(orderBy: 'name')
|
296
|
+
client.events(name: 'Infinity Gauntlet')
|
297
|
+
client.events(characters: [1009156, 1009652])
|
298
|
+
```
|
299
|
+
|
300
|
+
#### Event
|
301
|
+
|
302
|
+
Allows you to get a single comic resource. This endpoint requires an event id value (integer or string).
|
303
|
+
|
304
|
+
See [`GET /v1/public/events/{eventId}`](http://developer.marvel.com/docs#!/public/getEventIndividual_get_19).
|
305
|
+
|
306
|
+
```ruby
|
307
|
+
client.event(116)
|
308
|
+
client.event('Acts of Vengeance!')
|
309
|
+
```
|
310
|
+
|
311
|
+
#### Event Characters
|
312
|
+
|
313
|
+
Allows you to get a list of characters which appear in a specific event. This endpoint requires an event id value (integer or string).
|
314
|
+
|
315
|
+
See [`GET /v1/public/events/{eventId}/characters`](http://developer.marvel.com/docs#!/public/getEventCharacterCollection_get_20).
|
316
|
+
|
317
|
+
```ruby
|
318
|
+
client.event_characters(116)
|
319
|
+
client.event_characters('Acts of Vengeance!')
|
320
|
+
client.event_characters(116, orderBy: 'name', limit: 30, offset: 20)
|
321
|
+
client.event_characters('Acts of Vengeance!', orderBy: 'name', limit: 30, offset: 20)
|
322
|
+
client.event_characters(227, modifiedSince: '2014-04-29')
|
323
|
+
```
|
324
|
+
|
325
|
+
#### Event Comics
|
326
|
+
|
327
|
+
Allows you to get a list of comics which take place during a specific event. This endpoint requires an event id value (integer or string).
|
328
|
+
|
329
|
+
See [`GET /v1/public/events/{eventId}/comics`](http://developer.marvel.com/docs#!/public/getComicsCollection_get_21).
|
330
|
+
|
331
|
+
```ruby
|
332
|
+
client.event_comics(116)
|
333
|
+
client.event_comics('Acts of Vengeance!')
|
334
|
+
client.event_comics(116, format: 'graphic novel', orderBy: 'title', limit: 10)
|
335
|
+
client.event_comics('Acts of Vengeance!', format: 'graphic novel', orderBy: 'title', limit: 10)
|
336
|
+
client.event_comics(227, hasDigitalIssue: true, orderBy: 'onsaleDate')
|
337
|
+
```
|
338
|
+
|
339
|
+
#### Event Creators
|
340
|
+
|
341
|
+
Allows you to get a list of comic creators whose work appears in a specific event. This endpoint requires an event id value (integer or string).
|
342
|
+
|
343
|
+
See [`GET /v1/public/events/{eventId}/creators`](http://developer.marvel.com/docs#!/public/getCreatorCollection_get_22).
|
344
|
+
|
345
|
+
```ruby
|
346
|
+
client.event_creators(116)
|
347
|
+
client.event_creators('Acts of Vengeance!')
|
348
|
+
client.event_creators(116, lastName: 'Albrecht')
|
349
|
+
client.event_creators('Acts of Vengeance!', lastName: 'Albrecht')
|
350
|
+
client.event_creators(227, lastNameStartsWith: 'Lar')
|
351
|
+
```
|
352
|
+
|
353
|
+
#### Event Series
|
354
|
+
|
355
|
+
Allows you to get a list of comic series in which a specific event takes place. This endpoint requires an event id value (integer or string).
|
356
|
+
|
357
|
+
See [`GET /v1/public/events/{eventId}/series`](http://developer.marvel.com/docs#!/public/getEventSeriesCollection_get_23).
|
358
|
+
|
359
|
+
```ruby
|
360
|
+
client.event_series(116)
|
361
|
+
client.event_series('Acts of Vengeance!')
|
362
|
+
client.event_series(116, orderBy: 'title', limit: 10)
|
363
|
+
client.event_series('Acts of Vengeance!', orderBy: 'title', limit: 10)
|
364
|
+
client.event_series(227, startYear: 1995, seriesType: 'limited')
|
365
|
+
```
|
366
|
+
|
367
|
+
#### Event Stories
|
368
|
+
|
369
|
+
Allows you to get a list of comic stories from a specific event. This endpoint requires an event id value (integer or string).
|
370
|
+
|
371
|
+
See [`GET /v1/public/events/{eventId}/stories`](http://developer.marvel.com/docs#!/public/getEventStoryCollection_get_24).
|
372
|
+
|
373
|
+
```ruby
|
374
|
+
client.event_stories(116)
|
375
|
+
client.event_stories(116, limit: 10)
|
376
|
+
client.event_stories('Acts of Vengeance!')
|
377
|
+
client.event_stories('Acts of Vengeance!', limit: 10)
|
378
|
+
client.event_stories(227, orderBy: 'id', limit: 30, offset: 20)
|
379
|
+
```
|
380
|
+
|
381
|
+
### Series Endpoints
|
382
|
+
|
383
|
+
#### Series
|
384
|
+
|
385
|
+
Allows you to get a list of series.
|
386
|
+
|
387
|
+
See [`GET /v1/public/series`](http://developer.marvel.com/docs#!/public/getSeriesCollection_get_25).
|
388
|
+
|
389
|
+
```ruby
|
390
|
+
client.series
|
391
|
+
client.series(name: 'Spider-Man')
|
392
|
+
client.series(orderBy: 'title')
|
393
|
+
client.series(title: 'Uncanny X-Men')
|
394
|
+
client.series(titleStartsWith: 'Astonishing', orderBy: 'startDate', limit: 100)
|
395
|
+
```
|
396
|
+
|
397
|
+
#### Serie
|
398
|
+
|
399
|
+
Do note the particular spelling here!
|
400
|
+
|
401
|
+
Allows you to get a single series resource. This endpoint requires an serie id value (integer).
|
402
|
+
|
403
|
+
See [`GET /v1/public/series/{seriesId}`](http://developer.marvel.com/docs#!/public/getSeriesIndividual_get_26).
|
404
|
+
|
405
|
+
```ruby
|
406
|
+
client.serie(2069)
|
407
|
+
```
|
408
|
+
|
409
|
+
#### Series Characters
|
410
|
+
|
411
|
+
Allows you to get a list of characters which appear in a specific series. This endpoint requires an serie id value (integer).
|
412
|
+
|
413
|
+
See [`GET /v1/public/series/{seriesId}/characters`](http://developer.marvel.com/docs#!/public/getSeriesCharacterWrapper_get_27).
|
414
|
+
|
415
|
+
```ruby
|
416
|
+
client.series_characters(2069)
|
417
|
+
client.series_characters(2069, orderBy: 'name', limit: 30, offset: 20)
|
418
|
+
client.series_characters(354, nameStartsWith: 'Iron')
|
419
|
+
```
|
420
|
+
|
421
|
+
#### Series Comics
|
422
|
+
|
423
|
+
Allows you to get a list of comics which are published as part of a specific series. This endpoint requires an serie id value (integer).
|
424
|
+
|
425
|
+
See [`GET /v1/public/series/{seriesId}/comics`](http://developer.marvel.com/docs#!/public/getComicsCollection_get_28).
|
426
|
+
|
427
|
+
```ruby
|
428
|
+
client.series_comics(2069)
|
429
|
+
client.series_comics(2069, format: 'graphic novel', orderBy: 'title', limit: 10)
|
430
|
+
client.series_comics(354, issueNumber: 1)
|
431
|
+
```
|
432
|
+
|
433
|
+
#### Series Creators
|
434
|
+
|
435
|
+
Allows you to get a list of comic creators whose work appears in a specific series. This endpoint requires an serie id value (integer).
|
436
|
+
|
437
|
+
See [`GET /v1/public/series/{seriesId}/creators`](http://developer.marvel.com/docs#!/public/getCreatorCollection_get_29).
|
438
|
+
|
439
|
+
```ruby
|
440
|
+
client.series_creators(354)
|
441
|
+
client.series_creators(354, lastName: 'Kirby')
|
442
|
+
```
|
443
|
+
|
444
|
+
#### Series Events
|
445
|
+
|
446
|
+
Allows you to get a list of comic events which occur in a specific series. This endpoint requires an serie id value (integer).
|
447
|
+
|
448
|
+
See [`GET /v1/public/series/{seriesId}/events`](http://developer.marvel.com/docs#!/public/getEventsCollection_get_30).
|
449
|
+
|
450
|
+
```ruby
|
451
|
+
client.series_events(2069)
|
452
|
+
client.series_events(2069, orderBy: 'name', limit: 10)
|
453
|
+
client.series_events(354, orderBy: 'startDate')
|
454
|
+
```
|
455
|
+
|
456
|
+
#### Series Stories
|
457
|
+
|
458
|
+
Allows you to get a list of comic stories from a specific series. This endpoint requires an serie id value (integer).
|
459
|
+
|
460
|
+
See [`GET /v1/public/series/{seriesId}/stories`](http://developer.marvel.com/docs#!/public/getSeriesStoryCollection_get_31).
|
461
|
+
|
462
|
+
```ruby
|
463
|
+
client.series_stories(2069)
|
464
|
+
client.series_stories(2069, limit: 10)
|
465
|
+
client.series_stories(354, modifiedSince: '2013-06-01')
|
466
|
+
```
|
467
|
+
|
468
|
+
### Story Endpoints
|
469
|
+
|
470
|
+
#### Stories
|
471
|
+
|
472
|
+
Allows you to get a list of stories.
|
473
|
+
|
474
|
+
See [`GET /v1/public/stories`](http://developer.marvel.com/docs#!/public/getStoryCollection_get_32).
|
475
|
+
|
476
|
+
```ruby
|
477
|
+
client.stories
|
478
|
+
client.stories(limit: 50, offset: 100)
|
479
|
+
client.stories(orderBy: 'id')
|
480
|
+
client.stories(creators: 15)
|
481
|
+
client.stories(characters: [1009156, 1009652], orderBy: '-modified')
|
482
|
+
```
|
483
|
+
|
484
|
+
#### Story
|
485
|
+
|
486
|
+
Allows you to get a single story resource. This endpoint requires an story id value (integer).
|
487
|
+
|
488
|
+
See [`GET /v1/public/stories/{storyId}`](http://developer.marvel.com/docs#!/public/getStoryIndividual_get_33).
|
489
|
+
|
490
|
+
```ruby
|
491
|
+
client.story(2210)
|
492
|
+
```
|
493
|
+
|
494
|
+
#### Story Characters
|
495
|
+
|
496
|
+
Allows you to get a list of characters which appear in a specific story. This endpoint requires a story id value (integer).
|
497
|
+
|
498
|
+
See [`GET /v1/public/stories/{storyId}/characters`](http://developer.marvel.com/docs#!/public/getCreatorCollection_get_34).
|
499
|
+
|
500
|
+
```ruby
|
501
|
+
client.story_characters(2210)
|
502
|
+
client.story_characters(2210, orderBy: 'name', limit: 30, offset: 20)
|
503
|
+
client.story_characters(14410, nameStartsWith: 'D')
|
504
|
+
```
|
505
|
+
|
506
|
+
#### Story Comics
|
507
|
+
|
508
|
+
Allows you to get a list of comics in which a specific story appears. This endpoint requires an story id value (integer).
|
509
|
+
|
510
|
+
See [`GET /v1/public/stories/{storyId}/comics`](http://developer.marvel.com/docs#!/public/getComicsCollection_get_35).
|
511
|
+
|
512
|
+
```ruby
|
513
|
+
client.story_comics(2210)
|
514
|
+
client.story_comics(2210, format: 'graphic novel', orderBy: 'title', limit: 10)
|
515
|
+
client.story_comics(126, format: 'trade paperback')
|
516
|
+
```
|
517
|
+
|
518
|
+
#### Story Creators
|
519
|
+
|
520
|
+
Allows you to get a list of comic creators whose work appears in a specific story. This endpoint requires an story id value (integer).
|
521
|
+
|
522
|
+
See [`GET /v1/public/stories/{storyId}/creators`](http://developer.marvel.com/docs#!/public/getCreatorCollection_get_36).
|
523
|
+
|
524
|
+
```ruby
|
525
|
+
client.story_creators(2210)
|
526
|
+
client.story_creators(2210, lastName: 'Albrecht')
|
527
|
+
client.story_creators(126, lastNameStartsWith: 'S')
|
528
|
+
```
|
529
|
+
|
530
|
+
#### Story Events
|
531
|
+
|
532
|
+
Allows you to get a list of comic events in which a specific story appears. This endpoint requires an story id value (integer).
|
533
|
+
|
534
|
+
See [`GET /v1/public/stories/{storyId}/events`](http://developer.marvel.com/docs#!/public/getEventsCollection_get_37).
|
535
|
+
|
536
|
+
```ruby
|
537
|
+
client.story_events(2210)
|
538
|
+
client.story_events(2210, orderBy: 'name', limit: 10)
|
539
|
+
```
|
540
|
+
|
541
|
+
#### Story Series
|
542
|
+
|
543
|
+
Allows you to get a list of comic series in which the specified story takes place. This endpoint requires a story id value (integer).
|
544
|
+
|
545
|
+
See [`GET /v1/public/stories/{storyId}/series`](http://developer.marvel.com/docs#!/public/getStorySeriesCollection_get_38).
|
546
|
+
|
547
|
+
```ruby
|
548
|
+
client.story_series(2210)
|
549
|
+
client.story_series(2210, orderBy: 'title', limit: 10)
|
550
|
+
client.story_series(126, titleStartsWith: 'Infinity')
|
551
|
+
```
|
24
552
|
|
25
553
|
## Contributing
|
26
554
|
|
27
|
-
Bug reports and pull requests are welcome on GitHub at [https://github.com/jnyman/galactus](https://github.com/jnyman/galactus).
|
555
|
+
Bug reports and pull requests are welcome on GitHub at [https://github.com/jnyman/galactus](https://github.com/jnyman/galactus). Just as superheroes try to work together for the better good, this project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
556
|
+
|
557
|
+
To contribute to Galactus:
|
558
|
+
|
559
|
+
1. [Fork the project](http://gun.io/blog/how-to-github-fork-branch-and-pull-request/).
|
560
|
+
2. Create a feature branch. (`git checkout -b my-new-feature`)
|
561
|
+
3. Commit your changes. (`git commit -am 'new feature'`)
|
562
|
+
4. Push the branch. (`git push origin my-new-feature`)
|
563
|
+
5. Create a new [pull request](https://help.github.com/articles/using-pull-requests).
|
564
|
+
|
565
|
+
## Author
|
28
566
|
|
567
|
+
* [Jeff Nyman](http://testerstories.com)
|
29
568
|
|
30
569
|
## License
|
31
570
|
|
data/Rakefile
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
|
+
require 'rdoc/task'
|
3
|
+
require 'rubocop/rake_task'
|
2
4
|
require 'rspec/core/rake_task'
|
3
5
|
|
6
|
+
RuboCop::RakeTask.new
|
4
7
|
RSpec::Core::RakeTask.new(:spec)
|
5
8
|
|
6
|
-
|
9
|
+
Rake::RDocTask.new do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'doc'
|
11
|
+
rdoc.main = 'README.md'
|
12
|
+
rdoc.title = "Galactus #{Galactus::VERSION}"
|
13
|
+
rdoc.rdoc_files.include('README*', 'lib/**/*.rb')
|
14
|
+
end
|
15
|
+
|
16
|
+
task default: [:spec, :rubocop]
|
data/bin/console
CHANGED
@@ -6,9 +6,8 @@ require 'galactus'
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
# Pry.start
|
9
|
+
require 'pry'
|
10
|
+
Pry.start
|
12
11
|
|
13
|
-
require 'irb'
|
14
|
-
IRB.start
|
12
|
+
# require 'irb'
|
13
|
+
# IRB.start
|
data/galactus.gemspec
CHANGED
@@ -9,12 +9,13 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ['Jeff Nyman']
|
10
10
|
spec.email = ['jeffnyman@gmail.com']
|
11
11
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
Galactus
|
12
|
+
spec.summary = 'Marvel Comics API Entity Wrapper'
|
13
|
+
spec.description = '
|
14
|
+
Just as Galactus consumes planets in the comics, the galactus
|
15
|
+
gem allows you to consume the API provided by the Marvel
|
15
16
|
development team, querying on various aspects of the entire
|
16
17
|
Marvel universe.
|
17
|
-
|
18
|
+
'
|
18
19
|
spec.homepage = 'https://github.com/jnyman/galactus'
|
19
20
|
spec.license = 'MIT'
|
20
21
|
|
@@ -28,6 +29,13 @@ Gem::Specification.new do |spec|
|
|
28
29
|
spec.add_development_dependency 'bundler', '~> 1.10'
|
29
30
|
spec.add_development_dependency 'rake', '~> 10.0'
|
30
31
|
spec.add_development_dependency 'rspec'
|
32
|
+
spec.add_development_dependency 'pry'
|
33
|
+
spec.add_development_dependency 'rubocop'
|
34
|
+
spec.add_development_dependency 'simplecov'
|
35
|
+
spec.add_development_dependency 'fakeweb'
|
36
|
+
|
37
|
+
spec.add_runtime_dependency 'httparty'
|
38
|
+
spec.add_runtime_dependency 'hashie'
|
31
39
|
|
32
40
|
spec.post_install_message = %{
|
33
41
|
(::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::)
|
data/lib/galactus.rb
CHANGED
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'digest/md5'
|
3
|
+
|
4
|
+
require 'galactus/response'
|
5
|
+
|
6
|
+
module Galactus
|
7
|
+
class Client
|
8
|
+
include HTTParty
|
9
|
+
|
10
|
+
class InvalidClientError < StandardError; end
|
11
|
+
|
12
|
+
attr_accessor :api_version, :router
|
13
|
+
attr_reader :public_api_key, :private_api_key
|
14
|
+
|
15
|
+
base_uri 'http://gateway.marvel.com'
|
16
|
+
|
17
|
+
def initialize(settings)
|
18
|
+
validate_client(settings)
|
19
|
+
@public_api_key = settings[:public_api_key]
|
20
|
+
@private_api_key = settings[:private_api_key]
|
21
|
+
@api_version = settings[:api_version] || 'v1'
|
22
|
+
@router = settings[:router] || Galactus.router(api_version: api_version)
|
23
|
+
provide_endpoint_methods
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def validate_client(settings)
|
29
|
+
[:public_api_key, :private_api_key].each do |param|
|
30
|
+
unless settings[param]
|
31
|
+
raise InvalidClientError, "A :#{param} parameter must be specified."
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def provide_endpoint_methods
|
37
|
+
router.routes.each do |_route_path, route_info|
|
38
|
+
name = route_info[:name]
|
39
|
+
self.class.send(:define_method, name) do |*args|
|
40
|
+
params, headers = process_parameters(*args)
|
41
|
+
response = fetch_response(name, params, headers)
|
42
|
+
Response.create(response)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def process_parameters(*args)
|
48
|
+
id_holder, options_holder = *args
|
49
|
+
|
50
|
+
if id_holder && id_holder.is_a?(Hash)
|
51
|
+
id = nil
|
52
|
+
options = id_holder || {}
|
53
|
+
elsif id_holder
|
54
|
+
id = id_holder
|
55
|
+
options = options_holder || {}
|
56
|
+
else
|
57
|
+
options = {}
|
58
|
+
end
|
59
|
+
|
60
|
+
params, headers = pull_headers(options)
|
61
|
+
|
62
|
+
[{ id: id, options: params }, headers]
|
63
|
+
end
|
64
|
+
|
65
|
+
def fetch_response(name, params = {}, headers = {})
|
66
|
+
id = params[:id]
|
67
|
+
options = params[:options]
|
68
|
+
path = find_path(name, id)
|
69
|
+
|
70
|
+
self.class.get(path, query: marvel_api_params(options), headers: headers)
|
71
|
+
end
|
72
|
+
|
73
|
+
def fetch_resource_id(name, id)
|
74
|
+
endpoint = name.split('_')[0] + 's'
|
75
|
+
resource = find_by_name_or_title(endpoint.to_sym, :name, id)
|
76
|
+
return false unless resource
|
77
|
+
resource[:id]
|
78
|
+
end
|
79
|
+
|
80
|
+
def pull_headers(options)
|
81
|
+
headers = options.delete(:headers) || {}
|
82
|
+
unless headers['Accept-Encoding']
|
83
|
+
headers.merge!('Accept-Encoding' => 'gzip')
|
84
|
+
end
|
85
|
+
[options, headers]
|
86
|
+
end
|
87
|
+
|
88
|
+
def find_by_name_or_title(endpoint, column, value)
|
89
|
+
response = send(endpoint, column.to_sym => value)
|
90
|
+
return false unless response[:data][:count] > 0
|
91
|
+
response[:id] = response[:data][:results][0][:id]
|
92
|
+
response
|
93
|
+
end
|
94
|
+
|
95
|
+
def find_path(name, id)
|
96
|
+
if id.nil?
|
97
|
+
router.send("#{name}_path".to_sym)
|
98
|
+
else
|
99
|
+
id = fetch_resource_id(name, id) if id.is_a?(String)
|
100
|
+
router.send("#{name}_path".to_sym, id: id)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def marvel_api_params(params = {})
|
105
|
+
base_hash = {
|
106
|
+
apikey: public_api_key,
|
107
|
+
ts: timestamp,
|
108
|
+
hash: api_request_hash }
|
109
|
+
|
110
|
+
params.merge(base_hash)
|
111
|
+
end
|
112
|
+
|
113
|
+
def timestamp
|
114
|
+
Time.now.to_i
|
115
|
+
end
|
116
|
+
|
117
|
+
def api_request_hash
|
118
|
+
Digest::MD5.hexdigest("#{timestamp}#{private_api_key}#{public_api_key}")
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
1:
|
2
|
+
name: 'characters'
|
3
|
+
path: '/public/characters'
|
4
|
+
2:
|
5
|
+
name: 'character'
|
6
|
+
path: '/public/characters/:id'
|
7
|
+
3:
|
8
|
+
name: 'character_comics'
|
9
|
+
path: '/public/characters/:id/comics'
|
10
|
+
4:
|
11
|
+
name: 'character_events'
|
12
|
+
path: '/public/characters/:id/events'
|
13
|
+
5:
|
14
|
+
name: 'character_series'
|
15
|
+
path: '/public/characters/:id/series'
|
16
|
+
6:
|
17
|
+
name: 'character_stories'
|
18
|
+
path: '/public/characters/:id/stories'
|
19
|
+
7:
|
20
|
+
name: 'comics'
|
21
|
+
path: '/public/comics'
|
22
|
+
8:
|
23
|
+
name: 'comic'
|
24
|
+
path: '/public/comics/:id'
|
25
|
+
9:
|
26
|
+
name: 'comic_characters'
|
27
|
+
path: '/public/comics/:id/characters'
|
28
|
+
10:
|
29
|
+
name: 'comic_creators'
|
30
|
+
path: '/public/comics/:id/creators'
|
31
|
+
11:
|
32
|
+
name: 'comic_events'
|
33
|
+
path: '/public/comics/:id/events'
|
34
|
+
12:
|
35
|
+
name: 'comic_stories'
|
36
|
+
path: '/public/comics/:id/stories'
|
37
|
+
13:
|
38
|
+
name: 'creators'
|
39
|
+
path: '/public/creators'
|
40
|
+
14:
|
41
|
+
name: 'creator'
|
42
|
+
path: '/public/creators/:id'
|
43
|
+
15:
|
44
|
+
name: 'creator_comics'
|
45
|
+
path: '/public/creators/:id/comics'
|
46
|
+
16:
|
47
|
+
name: 'creator_events'
|
48
|
+
path: '/public/creators/:id/events'
|
49
|
+
17:
|
50
|
+
name: 'creator_series'
|
51
|
+
path: '/public/creators/:id/series'
|
52
|
+
18:
|
53
|
+
name: 'creator_stories'
|
54
|
+
path: '/public/creators/:id/stories'
|
55
|
+
19:
|
56
|
+
name: 'events'
|
57
|
+
path: '/public/events'
|
58
|
+
20:
|
59
|
+
name: 'event'
|
60
|
+
path: '/public/events/:id'
|
61
|
+
21:
|
62
|
+
name: 'event_characters'
|
63
|
+
path: '/public/events/:id/characters'
|
64
|
+
22:
|
65
|
+
name: 'event_creators'
|
66
|
+
path: '/public/events/:id/creators'
|
67
|
+
23:
|
68
|
+
name: 'event_comics'
|
69
|
+
path: '/public/events/:id/comics'
|
70
|
+
24:
|
71
|
+
name: 'event_stories'
|
72
|
+
path: '/public/events/:id/stories'
|
73
|
+
25:
|
74
|
+
name: 'event_series'
|
75
|
+
path: '/public/events/:id/series'
|
76
|
+
26:
|
77
|
+
name: 'series'
|
78
|
+
path: '/public/series'
|
79
|
+
27:
|
80
|
+
name: 'serie'
|
81
|
+
path: '/public/series/:id'
|
82
|
+
28:
|
83
|
+
name: 'series_characters'
|
84
|
+
path: '/public/series/:id/characters'
|
85
|
+
29:
|
86
|
+
name: 'series_comics'
|
87
|
+
path: '/public/series/:id/comics'
|
88
|
+
30:
|
89
|
+
name: 'series_creators'
|
90
|
+
path: '/public/series/:id/creators'
|
91
|
+
31:
|
92
|
+
name: 'series_events'
|
93
|
+
path: '/public/series/:id/events'
|
94
|
+
32:
|
95
|
+
name: 'series_stories'
|
96
|
+
path: '/public/series/:id/stories'
|
97
|
+
33:
|
98
|
+
name: 'stories'
|
99
|
+
path: '/public/stories'
|
100
|
+
34:
|
101
|
+
name: 'story'
|
102
|
+
path: '/public/stories/:id'
|
103
|
+
35:
|
104
|
+
name: 'story_characters'
|
105
|
+
path: '/public/stories/:id/characters'
|
106
|
+
36:
|
107
|
+
name: 'story_comics'
|
108
|
+
path: '/public/stories/:id/comics'
|
109
|
+
37:
|
110
|
+
name: 'story_creators'
|
111
|
+
path: '/public/stories/:id/creators'
|
112
|
+
38:
|
113
|
+
name: 'story_events'
|
114
|
+
path: '/public/stories/:id/events'
|
115
|
+
39:
|
116
|
+
name: 'story_series'
|
117
|
+
path: '/public/stories/:id/series'
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'hashie'
|
2
|
+
|
3
|
+
module Galactus
|
4
|
+
class Response < Hash
|
5
|
+
include Hashie::Extensions::MergeInitializer
|
6
|
+
include Hashie::Extensions::MethodAccess
|
7
|
+
include Hashie::Extensions::IndifferentAccess
|
8
|
+
include Hashie::Extensions::KeyConversion
|
9
|
+
|
10
|
+
attr_reader :raw_response
|
11
|
+
|
12
|
+
def self.create(response)
|
13
|
+
case response.code
|
14
|
+
when 200
|
15
|
+
Response.new(response)
|
16
|
+
when 304
|
17
|
+
NotModifiedResponse.new(response)
|
18
|
+
else
|
19
|
+
ErrorResponse.new(response)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(response)
|
24
|
+
@raw_response = response
|
25
|
+
super(response)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class ErrorResponse < Response; end
|
30
|
+
|
31
|
+
class NotModifiedResponse < Response
|
32
|
+
def initialize(response)
|
33
|
+
super({
|
34
|
+
status: 'Not Modified',
|
35
|
+
code: 304,
|
36
|
+
data: {},
|
37
|
+
etag: response.headers['etag'] })
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Galactus
|
2
|
+
class Router
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
attr_accessor :api_version
|
6
|
+
attr_reader :routes
|
7
|
+
|
8
|
+
def initialize(settings = {})
|
9
|
+
@routes = {}
|
10
|
+
@api_version = settings[:api_version] || 'v1'
|
11
|
+
load_api_routes("#{api_version}.yml")
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def load_api_routes(file)
|
17
|
+
api_routes_path = check_for_api_file(file)
|
18
|
+
contents = YAML.load(File.read(api_routes_path))
|
19
|
+
|
20
|
+
contents.each do |_route_id, route_info|
|
21
|
+
add_api_route(route_info['name'], route_info['path'])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def add_api_route(name, path)
|
26
|
+
routes["#{name}_path".to_sym] = { name: name, endpoint: path }
|
27
|
+
end
|
28
|
+
|
29
|
+
def check_for_api_file(file)
|
30
|
+
script_path = current_script_path
|
31
|
+
file_path = File.join(script_path, 'config', file)
|
32
|
+
return file_path if File.exist?(file_path)
|
33
|
+
file_path = File.join(File.dirname(__FILE__), 'config', file)
|
34
|
+
file_path if File.exist?(file_path)
|
35
|
+
end
|
36
|
+
|
37
|
+
def current_script_path
|
38
|
+
File.expand_path(File.dirname(File.expand_path $PROGRAM_NAME))
|
39
|
+
end
|
40
|
+
|
41
|
+
def method_missing(method, *args)
|
42
|
+
return unless routes.keys.include?(method)
|
43
|
+
endpoint = "#{routes[method][:endpoint]}"
|
44
|
+
params = *args
|
45
|
+
|
46
|
+
if params.any?
|
47
|
+
params[0].each do |p_key, p_value|
|
48
|
+
endpoint.gsub!(":#{p_key}", p_value.to_s)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
"/#{api_version}#{endpoint}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/galactus/version.rb
CHANGED
@@ -0,0 +1,50 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
require 'net/http'
|
5
|
+
require 'digest/md5'
|
6
|
+
|
7
|
+
# http://developer.marvel.com/documentation/authorization
|
8
|
+
# Requests on the server side must be of the form:
|
9
|
+
# http://gateway.marvel.com/v1/comics/?ts=1&apikey=1234&hash=ffd275c5130566a2916217b101f26150
|
10
|
+
|
11
|
+
# `ts` is a timestamp, but it can apparently just be some string which can
|
12
|
+
# change on a request-by-request basis.
|
13
|
+
# `apikey` is the public API key
|
14
|
+
# `hash` is an md5 digest of the timestamp parameter, the private key and
|
15
|
+
# the public key.
|
16
|
+
|
17
|
+
# This test file requires an api_key.yml file with the following:
|
18
|
+
# public_api_key: value
|
19
|
+
# private_api_key: value
|
20
|
+
# This file will not be placed in version control since it will contain the
|
21
|
+
# private key.
|
22
|
+
|
23
|
+
api_key_file = "#{File.dirname(__FILE__)}/api_keys.yml"
|
24
|
+
|
25
|
+
marvel_public_key = YAML.load_file(api_key_file)['public_api_key']
|
26
|
+
marvel_private_key = YAML.load_file(api_key_file)['private_api_key']
|
27
|
+
|
28
|
+
endpoint = 'http://gateway.marvel.com/v1/public/'
|
29
|
+
|
30
|
+
timestamp = '1'
|
31
|
+
|
32
|
+
ts_param = '&ts='
|
33
|
+
hash_param = '&hash='
|
34
|
+
api_param = '&apikey='
|
35
|
+
|
36
|
+
search_term = 'characters?name=Spider-Man'
|
37
|
+
|
38
|
+
url = endpoint + search_term + ts_param + timestamp + api_param + marvel_public_key + hash_param
|
39
|
+
|
40
|
+
hash = timestamp + marvel_private_key + marvel_public_key
|
41
|
+
digest = Digest::MD5.hexdigest(hash)
|
42
|
+
|
43
|
+
url += digest
|
44
|
+
|
45
|
+
puts url
|
46
|
+
|
47
|
+
response = Net::HTTP.get_response(URI.parse(url))
|
48
|
+
response_text = response.body
|
49
|
+
|
50
|
+
puts response_text
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
+
|
5
|
+
require 'yaml'
|
6
|
+
require 'galactus'
|
7
|
+
|
8
|
+
api_key_file = "#{File.dirname(__FILE__)}/api_keys.yml"
|
9
|
+
|
10
|
+
public_key = YAML.load_file(api_key_file)['public_api_key']
|
11
|
+
private_key = YAML.load_file(api_key_file)['private_api_key']
|
12
|
+
|
13
|
+
client = Galactus::Client.new(public_api_key: public_key, private_api_key: private_key)
|
14
|
+
|
15
|
+
#puts client.characters['status']
|
16
|
+
#puts client.characters[:data][:results].size
|
17
|
+
|
18
|
+
#puts client.character(1009652)
|
19
|
+
puts client.character('Spider-Man')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: galactus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Nyman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,9 +52,93 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
|
56
|
-
|
57
|
-
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: fakeweb
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: httparty
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: hashie
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: "\n Just as Galactus consumes planets in the comics, the galactus\n
|
140
|
+
\ gem allows you to consume the API provided by the Marvel\n development team,
|
141
|
+
querying on various aspects of the entire\n Marvel universe.\n "
|
58
142
|
email:
|
59
143
|
- jeffnyman@gmail.com
|
60
144
|
executables: []
|
@@ -62,7 +146,9 @@ extensions: []
|
|
62
146
|
extra_rdoc_files: []
|
63
147
|
files:
|
64
148
|
- ".gitignore"
|
149
|
+
- ".hound.yml"
|
65
150
|
- ".rspec"
|
151
|
+
- ".rubocop.yml"
|
66
152
|
- ".travis.yml"
|
67
153
|
- CODE_OF_CONDUCT.md
|
68
154
|
- Gemfile
|
@@ -73,13 +159,19 @@ files:
|
|
73
159
|
- bin/setup
|
74
160
|
- galactus.gemspec
|
75
161
|
- lib/galactus.rb
|
162
|
+
- lib/galactus/client.rb
|
163
|
+
- lib/galactus/config/v1.yml
|
164
|
+
- lib/galactus/response.rb
|
165
|
+
- lib/galactus/router.rb
|
76
166
|
- lib/galactus/version.rb
|
167
|
+
- spikes/call_marvel_api.rb
|
168
|
+
- spikes/call_marvel_via_galactus.rb
|
77
169
|
homepage: https://github.com/jnyman/galactus
|
78
170
|
licenses:
|
79
171
|
- MIT
|
80
172
|
metadata: {}
|
81
173
|
post_install_message: "\n(::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::)\n\n
|
82
|
-
\ Galactus 0.
|
174
|
+
\ Galactus 0.2.0 has been installed.\n\n(::) (::) (::) (::) (::) (::) (::) (::)
|
83
175
|
(::) (::) (::) (::)\n "
|
84
176
|
rdoc_options: []
|
85
177
|
require_paths:
|
@@ -99,5 +191,5 @@ rubyforge_project:
|
|
99
191
|
rubygems_version: 2.4.8
|
100
192
|
signing_key:
|
101
193
|
specification_version: 4
|
102
|
-
summary:
|
194
|
+
summary: Marvel Comics API Entity Wrapper
|
103
195
|
test_files: []
|