marvelite 0.0.5 → 0.0.6.a

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 984423d6566dfc1729975c08cda31745a35afe55
4
- data.tar.gz: 4ad394d4c98726d62f5e465e5e7bd7898390febb
3
+ metadata.gz: 9f5021f591254b35d1aa7a672d428f10d7d6a027
4
+ data.tar.gz: ac7b2af321f54b2f7865af4d019c55784413f707
5
5
  SHA512:
6
- metadata.gz: 32bb4d940672d707a0ddb92ba322fafc3b6fa93796b8f7ee3bbe5f58657e3bf7572d6d425cd77a24913f939c82a9ea123f2e9778981132d4ca12b0bf22168a1d
7
- data.tar.gz: 90af92a8e7c9fd53aead7ec8c3eb8c34db2d1e2755afbce35ed5bfbb636da59e54c790deba64f259e5381d32f113b960d1c363e6c45792f783049e8c28eec5f4
6
+ metadata.gz: bd7170f1d3f353a2fb890e38d31d2d286728272df87cd1904aeb8d95eea39c1249423dc32967f63cf5ca076bc0a040110194a2301e51c07b269050b155304554
7
+ data.tar.gz: 7fabd1e5145ef5ebabfa04068fcc15be5bf18306a63e2d36154bbbc6e7e55a3a25ef6b493ca0ef132e76d7784de9590d03712fa63eb04f9b605c5a734e1b6cc3
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  ## Changelog
2
2
 
3
+ ### 0.0.6
4
+ * Rewrites `Marvelite::API::Client` to allow for self discovery of available methods, depending on the `Marvelite::API::Router` injected at initialization.
5
+ * Adds the following endpoints:
6
+ * retrieve series by connecting to the API's `/series` endpoint
7
+ * retieve a serie by connecting to the API's `/series/:id` enpoint
8
+ * retrieve serie characters by connecting to the API's `/series/:id/characters` endpoint.
9
+ * retrieve serie comics by connecting to the API's `/series/:id/comics` endpoint.
10
+ * retrieve serie creators by connecting to the API's `/series/:id/creators` endpoint.
11
+ * retrieve serie events by connecting to the API's `/series/:id/events` endpoint.
12
+ * retrieve serie stories by connecting to the API's `/series/:id/stories` endpoint.
13
+
14
+
3
15
  ### 0.0.5
4
16
  * Rewrites `Marvelite::API::Router` class to make flexible to future API versioning changes from Marvel.
5
17
  * Adds the following endpoints:
data/README.md CHANGED
@@ -22,7 +22,6 @@ Or install it yourself as:
22
22
  ## Contents
23
23
 
24
24
  * [Usage](#usage)
25
- * [Methods](#methods)
26
25
  * [Responses](#responses)
27
26
 
28
27
 
@@ -37,264 +36,56 @@ client = Marvelite::API::Client.new(
37
36
  :public_key => 'abcd1234',
38
37
  :private_key => '5678efgh'
39
38
  )
40
- ```
41
39
 
42
- ### Methods
43
-
44
- | Method | Description |
45
- | ------ | ----------- |
46
- | [#characters](#characters) | Fetches a list of comic characters. |
47
- | [#character](#character) | Fetches a single character resource. |
48
- | [#character_comics](#character_comics) | Fetches a list of comics containing a specific character. |
49
- | [#character_events](#character_events) | Fetches a list of events in which a specific character appears. |
50
- | [#character_series](#character_series) | Fetches a list of comic series in which a specific character appears. |
51
- | [#character_stories](#character_stories) | Fetches a list of comic stories featuring a specific character. |
52
- | [#comics](#comics) | Fetches a list of comics. |
53
- | [#comic](#comic) | Fetches a single comic resource. |
54
- | [#comic_characters](#comic_characters) | Fetches a list of characters which appear in a specific comic. |
55
- | [#comic_creators](#comic_creators) | Fetches a list of comic creators whose work appears in a specific comic. |
56
- | [#comic_events](#comic_events) | Fetches a list of events in which a comic appears. |
57
- | [#comic_stories](#comic_stories) | Fetches a list of comic stories in a specific comic issue. |
58
- | [#events](#events) | Fetches a list of events. |
59
- | [#event](#event) | Fetches a single event resource. |
60
- | [#event_characters](#event_characters) | Fetches a list of characters which appear in a specific event. |
61
- | [#event_comics](#event_comics) | Fetches a list of comics which take place during a specific event. |
62
- | [#event_creators](#event_creators) | Fetches a list of event creators whose work appears in a specific event. |
63
- | [#event_series](#event_series) | Fetches a list of comic series in which a specific event takes place. |
64
- | [#event_stories](#event_stories) | Fetches a list of comic stories from a specific event. |
65
-
66
-
67
- #### characters
68
- Fetches a list of comic characters. Can receive optional params.
69
- ```ruby
40
+ # fetch a list of characters
70
41
  client.characters
71
42
  client.characters(:name => 'Spider-Man')
72
43
  client.characters(:limit => 10, :offset => 400, :orderBy => 'name')
73
- ```
74
-
75
-
76
- See the [Marvel Comics Interactive API Tester](http://developer.marvel.com/docs#!/public/getCreatorCollection_get_0) for a complete list of params that you can pass to the `#characters` method.
77
-
78
- #### character
79
-
80
- Fetches a single character resource. Accepts an integer or string value as character id.
81
44
 
82
- ```ruby
45
+ # fetch a single character
83
46
  client.character(1009610)
84
47
  client.character('Spider-Man')
85
- ```
86
-
87
- #### character_comics
88
-
89
- Fetches a list of comics containing a specific character. Requires a character id value (integer or string). Accepts optional params.
90
-
91
- ```ruby
92
- client.character_comics(1009610)
93
- client.character_comics('Spider-Man')
94
- client.character_comics(
95
- 1009610,
96
- { :format => 'graphic novel', :limit => 10, :orderBy => 'title' }
97
- )
98
- client.character_comics(
99
- 'Spider-Man',
100
- { :format => 'graphic novel', :limit => 10, :orderBy => 'title' }
101
- )
102
- ```
103
-
104
- See the [Marvel Comics Interactive API Tester](http://developer.marvel.com/docs#!/public/getComicsCharacterCollection_get_2) for a complete list of params that you can pass to the `#character_comics` method.
105
-
106
- #### character_events
107
-
108
- Fetches a list of events in which a specific character appears. Requires a character id value (integer or string). Accepts optional params.
109
-
110
- ```ruby
111
- client.character_events(1009610)
112
- client.character_events('Spider-Man')
113
- client.character_events(
114
- 1009610,
115
- { :limit => 10, :orderBy => 'name' }
116
- )
117
- client.character_events(
118
- 'Spider-Man',
119
- { :limit => 10, :orderBy => 'name' }
120
- )
121
- ```
122
-
123
- See the [Marvel Comics Interactive API Tester](http://developer.marvel.com/docs#!/public/getCharacterEventsCollection_get_3) for a complete list of params that you can pass to the `#character_events` method.
124
-
125
-
126
- #### character_series
127
48
 
128
- Fetches a list of comic series in which a specific character appears. Requires a character id value (integer or string). Accepts optional params.
129
-
130
- ```ruby
131
- client.character_series(1009610)
132
- client.character_series('Spider-Man')
133
- client.character_series(
134
- 1009610,
135
- { :seriesType => 'ongoing', :limit => 10, :orderBy => 'title' }
136
- )
137
- client.character_series(
138
- 'Spider-Man',
139
- { :seriesType => 'ongoing', :limit => 10, :orderBy => 'title' }
140
- )
141
- ```
142
-
143
- See the [Marvel Comics Interactive API Tester](http://developer.marvel.com/docs#!/public/getCharacterSeriesCollection_get_4) for a complete list of params that you can pass to the `#character_series` method.
144
-
145
-
146
- #### character_stories
147
-
148
- Fetches a list of comic stories featuring a specific character. Requires a character id value (integer or string). Accepts optional params.
149
-
150
- ```ruby
151
- client.character_stories(1009610)
152
- client.character_stories('Spider-Man')
153
- client.character_stories(1009610, { :limit => 10, :offset => 20 })
154
- client.character_stories('Spider-Man', { :limit => 10, :offset => 20 })
155
- ```
156
-
157
- See the [Marvel Comics Interactive API Tester](http://developer.marvel.com/docs#!/public/getCharacterStoryCollection_get_5) for a complete list of params that you can pass to the `#character_stories` method.
158
-
159
-
160
- #### comics
161
-
162
- Fetches a list of comics. Accepts optional params.
163
-
164
- ```ruby
49
+ # fetch a list of comics
165
50
  client.comics
166
51
  client.comics(:format => 'graphic novel', :limit => 10, :offset => 20 })
167
- ```
168
-
169
- See the [Marvel Comics Interactive API Tester](http://developer.marvel.com/docs#!/public/getComicsCollection_get_6) for a complete list of params that you can pass to the `#comics` method.
170
-
171
- #### comic
172
52
 
173
- Fetches a single comic resource. Requires a comic id value (integer).
174
-
175
- ```ruby
53
+ # fetch a single comic
176
54
  client.comic(40128)
177
- ```
178
55
 
179
- #### comic_characters
180
-
181
- Fetches a list of characters which appear in a specific comic. Requires a comic id value (integer). Accepts optional params.
182
-
183
- ```ruby
56
+ # fetch a list of comic characters
184
57
  client.comic_characters(40128)
185
58
  client.comic_characters(40128, :orderBy => 'name', :limit => 30, :offset => 20)
186
- ```
187
-
188
- See the [Marvel Comics Interactive API Tester](http://developer.marvel.com/docs#!/public/getComicCharacterCollection_get_8) for a complete list of params that you can pass to the `#comic_characters` method.
189
-
190
- #### comic_creators
191
-
192
- Fetches a list of comic creators whose work appears in a specific comic. Requires a comic id value (integer). Accepts optional params.
193
-
194
- ```ruby
195
- client.comic_creators(40128)
196
- client.comic_creators(40128, :lastName => 'Romita')
197
- ```
198
-
199
- See the [Marvel Comics Interactive API Tester](http://developer.marvel.com/docs#!/public/getCreatorCollection_get_9) for a complete list of params that you can pass to the `#comic_creators` method.
200
-
201
- #### comic_events
202
-
203
- Fetches a list of events in which a comic appears. Requires a comic id value (integer). Accepts optional params.
204
-
205
- ```ruby
206
- client.comic_events(40128)
207
- client.comic_events(40128, :orderBy => 'name', :limit => 10)
208
- ```
209
-
210
- See the [Marvel Comics Interactive API Tester](http://developer.marvel.com/docs#!/public/getIssueEventsCollection_get_10) for a complete list of params that you can pass to the `#comic_events` method.
211
59
 
212
- #### comic_stories
213
-
214
- Fetches a list of comic stories in a specific comic issue. Requires a comic id value (integer). Accepts optional params.
215
-
216
- ```ruby
217
- client.comic_stories(40128)
218
- client.comic_stories(40128, :orderBy => 'name', :limit => 10)
219
- ```
220
-
221
- See the [Marvel Comics Interactive API Tester](http://developer.marvel.com/docs#!/public/getComicStoryCollection_get_11) for a complete list of params that you can pass to the `#comic_stories` method.
222
-
223
- #### events
224
-
225
- Fetches a list of events. Accepts optional params.
226
-
227
- ```ruby
60
+ # fetch a list of events
228
61
  client.events
229
62
  client.events(:name => 'Acts of Vengeance')
230
63
  client.events(:orderBy => 'name')
231
- ```
232
-
233
- See the [Marvel Comics Interactive API Tester](http://developer.marvel.com/docs#!/public/getEventsCollection_get_18) for a complete list of params that you can pass to the `#events` method.
234
-
235
- #### event
236
-
237
- Fetches a single comic resource. Requires an event id value (integer).
238
64
 
239
- ```ruby
65
+ # fetch a single event
240
66
  client.event(116)
241
- ```
242
-
243
- #### event_characters
244
-
245
- Fetches a list of characters which appear in a specific event. Requires an event id value (integer). Accepts optional params.
246
-
247
- ```ruby
248
- client.event_characters(116)
249
- client.event_characters(116, :orderBy => 'name', :limit => 30, :offset => 20)
250
- ```
251
-
252
- See the [Marvel Comics Interactive API Tester](http://developer.marvel.com/docs#!/public/getEventCharacterCollection_get_20) for a complete list of params that you can pass to the `#event_characters` method.
253
-
254
- #### event_creators
255
-
256
- Fetches a list of comic creators whose work appears in a specific event. Requires an event id value (integer). Accepts optional params.
257
-
258
- ```ruby
259
- client.event_creators(116)
260
- client.event_creators(116, :lastName => 'Romita')
261
- ```
262
-
263
- See the [Marvel Comics Interactive API Tester](http://developer.marvel.com/docs#!/public/getCreatorCollection_get_22) for a complete list of params that you can pass to the `#event_creators` method.
67
+ client.event('Acts of Vengeance!')
264
68
 
265
- #### event_comics
266
-
267
- Fetches a list of comics which take place during a specific event. Requires an event id value (integer). Accepts optional params.
268
-
269
- ```ruby
69
+ # fetch a list of comics in an event
270
70
  client.event_comics(116)
71
+ client.event_comics('Acts of Vengeance!')
271
72
  client.event_comics(116, :format => 'graphic novel', :orderBy => 'title', :limit => 10)
272
- ```
73
+ client.event_comics('Acts of Vengeance!', :format => 'graphic novel', :orderBy => 'title', :limit => 10)
273
74
 
274
- See the [Marvel Comics Interactive API Tester](http://developer.marvel.com/docs#!/public/getComicsCollection_get_21) for a complete list of params that you can pass to the `#event_comics` method.
75
+ # fetch a list of series
76
+ client.series
77
+ client.series(:title => 'Spider-Man')
78
+ client.series(:orderBy => 'title')
275
79
 
276
- #### event_series
80
+ # fetch a single serie
81
+ client.serie(2069)
277
82
 
278
- Fetches a list of comic series in which a specific event takes place. Requires an event id value (integer). Accepts optional params.
279
-
280
- ```ruby
281
- client.event_series(116)
282
- client.event_series(116, :orderBy => 'title', :limit => 10)
83
+ # fetch a list of comics in a serie
84
+ client.series_comics(2069)
85
+ client.series_comics(2069, :format => 'graphic novel', :orderBy => 'title', :limit => 10)
283
86
  ```
284
87
 
285
- See the [Marvel Comics Interactive API Tester](http://developer.marvel.com/docs#!/public/getCreatorSeriesCollection_get_23) for a complete list of params that you can pass to the `#event_series` method.
286
-
287
- #### event_stories
288
-
289
- Fetches a list of comic stories from a specific event. Requires an event id value (integer). Accepts optional params.
290
-
291
- ```ruby
292
- client.event_stories(116)
293
- client.event_stories(116, :limit => 10)
294
- ```
295
-
296
- See the [Marvel Comics Interactive API Tester](http://developer.marvel.com/docs#!/public/getEventStoryCollection_get_24) for a complete list of params that you can pass to the `#event_stories` method.
297
-
88
+ See the list of [available methods](https://github.com/antillas21/marvelite/wiki/Documentation) in the wiki.
298
89
 
299
90
 
300
91
  ## Responses
data/Rakefile CHANGED
@@ -3,4 +3,11 @@ require "rspec/core/rake_task"
3
3
 
4
4
  RSpec::Core::RakeTask.new("spec")
5
5
 
6
- task :default => :spec
6
+ task :default => :spec
7
+
8
+ task :console do
9
+ require 'pry'
10
+ require 'marvelite'
11
+ ARGV.clear
12
+ Pry.start
13
+ end
data/lib/marvelite.rb CHANGED
@@ -1,13 +1,10 @@
1
1
  require 'active_model'
2
- require 'digest'
2
+ require 'digest/md5'
3
3
  require 'httparty'
4
4
  require 'hashie'
5
5
 
6
6
  require "marvelite/version"
7
7
  require "marvelite/api/router"
8
- require "marvelite/api/character_methods"
9
- require "marvelite/api/comic_methods"
10
- require "marvelite/api/event_methods"
11
8
  require "marvelite/api/client"
12
9
  require "marvelite/api/response"
13
10
 
@@ -2,11 +2,6 @@ module Marvelite
2
2
  module API
3
3
  class Client
4
4
  include ActiveModel::Model
5
-
6
- include Marvelite::API::CharacterMethods
7
- include Marvelite::API::ComicMethods
8
- include Marvelite::API::EventMethods
9
-
10
5
  include HTTParty
11
6
  base_uri 'http://gateway.marvel.com'
12
7
 
@@ -19,6 +14,7 @@ module Marvelite
19
14
  super
20
15
  @api_version = attrs.fetch(:api_version) { 'v1' }
21
16
  @router = attrs.fetch(:router) { Marvelite.router(:api_version => @api_version) }
17
+ build_methods
22
18
  end
23
19
 
24
20
  private
@@ -45,6 +41,57 @@ module Marvelite
45
41
  ErrorResponse.new(response)
46
42
  end
47
43
  end
44
+
45
+ def find_by_name_or_title(endpoint, column, value)
46
+ response = self.send(endpoint, { column.to_sym => value })
47
+ return false unless response[:data][:count] > 0
48
+ response.id = response[:data][:results][0][:id]
49
+ response
50
+ end
51
+
52
+ def process_arguments(*args)
53
+ temp_id, temp_options = *args
54
+ if temp_id && temp_id.is_a?(Hash)
55
+ id = nil
56
+ options = temp_id || {}
57
+ elsif temp_id
58
+ id = temp_id
59
+ options = temp_options || {}
60
+ else
61
+ options = {}
62
+ end
63
+ { id: id, options: options}
64
+ end
65
+
66
+ def fetch_response(route, params_hash = {})
67
+ id = params_hash[:id]
68
+ options = params_hash[:options]
69
+
70
+ if id.nil?
71
+ self.class.get(router.send("#{route}_path".to_sym), :query => params(options))
72
+ else
73
+ id = fetch_resource_id(route, id) if id.is_a?(String)
74
+ self.class.get(router.send("#{route}_path".to_sym, {:id => id}), :query => params(options))
75
+ end
76
+ end
77
+
78
+ def fetch_resource_id(route, id)
79
+ endpoint = route.split("_")[0]+"s"
80
+ resource = find_by_name_or_title(endpoint.to_sym, :name, id)
81
+ return false unless resource
82
+ resource.id
83
+ end
84
+
85
+ def build_methods
86
+ @router.routes.each do |name, _|
87
+ self.class.send(:define_method, name) do |*args|
88
+ params = process_arguments(*args)
89
+ response = fetch_response(name, params)
90
+ build_response_object(response)
91
+ end
92
+ end
93
+ end
94
+
48
95
  end
49
96
  end
50
97
  end
@@ -54,4 +54,25 @@
54
54
  path: '/public/events/:id/stories'
55
55
  19:
56
56
  name: 'event_series'
57
- path: '/public/events/:id/series'
57
+ path: '/public/events/:id/series'
58
+ 20:
59
+ name: 'series'
60
+ path: '/public/series'
61
+ 21:
62
+ name: 'serie'
63
+ path: '/public/series/:id'
64
+ 22:
65
+ name: 'series_characters'
66
+ path: '/public/series/:id/characters'
67
+ 23:
68
+ name: 'series_comics'
69
+ path: '/public/series/:id/comics'
70
+ 24:
71
+ name: 'series_creators'
72
+ path: '/public/series/:id/creators'
73
+ 25:
74
+ name: 'series_events'
75
+ path: '/public/series/:id/events'
76
+ 26:
77
+ name: 'series_stories'
78
+ path: '/public/series/:id/stories'