marvelite 0.0.4 → 0.0.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5869a9c08209ca2f9f7e12da466a094c90896c8b
4
- data.tar.gz: 223abc8115a7c6f52e49f336ab552dfede7bdd2f
3
+ metadata.gz: 984423d6566dfc1729975c08cda31745a35afe55
4
+ data.tar.gz: 4ad394d4c98726d62f5e465e5e7bd7898390febb
5
5
  SHA512:
6
- metadata.gz: ecea6aebd6822352fc79508ec0871782276fe4e8296d43f97686a274e37bd4316a06eb2be6324c1c7aa47409de0faa29e61cd6003034d2288974f45a54871dff
7
- data.tar.gz: e8b51d2cc3bdd8f347b081a1e0837a755a41052c9a1064003f7b44c9c8d5fcfaa1dcd49a0f8a70c6132def107c10d93ade4ecc80640f95bffd71069b2afff8ef
6
+ metadata.gz: 32bb4d940672d707a0ddb92ba322fafc3b6fa93796b8f7ee3bbe5f58657e3bf7572d6d425cd77a24913f939c82a9ea123f2e9778981132d4ca12b0bf22168a1d
7
+ data.tar.gz: 90af92a8e7c9fd53aead7ec8c3eb8c34db2d1e2755afbce35ed5bfbb636da59e54c790deba64f259e5381d32f113b960d1c363e6c45792f783049e8c28eec5f4
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  ## Changelog
2
2
 
3
+ ### 0.0.5
4
+ * Rewrites `Marvelite::API::Router` class to make flexible to future API versioning changes from Marvel.
5
+ * Adds the following endpoints:
6
+ * retrieve events by connecting to the API's `/events` endpoint
7
+ * retieve a event by connecting to the API's `/events/:id` enpoint
8
+ * retrieve event characters by connecting to the API's `/events/:id/characters` endpoint.
9
+ * retrieve event comics by connecting to the API's `/events/:id/comics` endpoint.
10
+ * retrieve event creators by connecting to the API's `/events/:id/creators` endpoint.
11
+ * retrieve event series by connecting to the API's `/events/:id/series` endpoint.
12
+ * retrieve event stories by connecting to the API's `/events/:id/stories` endpoint.
13
+ * Adds helper method to retrieve event sub-resources passing an event name instead of a numeric id.
14
+
15
+
3
16
  ### 0.0.4
4
17
  * Adds the following endpoints:
5
18
  * retrieve comics by connecting to the API's `/comics` endpoint
data/README.md CHANGED
@@ -55,6 +55,13 @@ client = Marvelite::API::Client.new(
55
55
  | [#comic_creators](#comic_creators) | Fetches a list of comic creators whose work appears in a specific comic. |
56
56
  | [#comic_events](#comic_events) | Fetches a list of events in which a comic appears. |
57
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. |
58
65
 
59
66
 
60
67
  #### characters
@@ -213,6 +220,82 @@ client.comic_stories(40128, :orderBy => 'name', :limit => 10)
213
220
 
214
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.
215
222
 
223
+ #### events
224
+
225
+ Fetches a list of events. Accepts optional params.
226
+
227
+ ```ruby
228
+ client.events
229
+ client.events(:name => 'Acts of Vengeance')
230
+ 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
+
239
+ ```ruby
240
+ 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.
264
+
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
270
+ client.event_comics(116)
271
+ client.event_comics(116, :format => 'graphic novel', :orderBy => 'title', :limit => 10)
272
+ ```
273
+
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.
275
+
276
+ #### event_series
277
+
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)
283
+ ```
284
+
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
+
298
+
216
299
 
217
300
  ## Responses
218
301
 
data/lib/marvelite.rb CHANGED
@@ -7,11 +7,12 @@ require "marvelite/version"
7
7
  require "marvelite/api/router"
8
8
  require "marvelite/api/character_methods"
9
9
  require "marvelite/api/comic_methods"
10
+ require "marvelite/api/event_methods"
10
11
  require "marvelite/api/client"
11
12
  require "marvelite/api/response"
12
13
 
13
14
  module Marvelite
14
- def self.router
15
- Marvelite::API::Router.new
15
+ def self.router(attrs = {})
16
+ Marvelite::API::Router.new(attrs)
16
17
  end
17
18
  end
@@ -2,7 +2,7 @@ module Marvelite
2
2
  module API
3
3
  module CharacterMethods
4
4
  def characters(query_params = {})
5
- response = self.class.get("/#{api_version}/#{router.characters_path}", :query => params(query_params))
5
+ response = self.class.get(router.characters_path, :query => params(query_params))
6
6
  build_response_object(response)
7
7
  end
8
8
 
@@ -11,7 +11,7 @@ module Marvelite
11
11
  response = if by_name
12
12
  find_character_by_name(value)
13
13
  else
14
- self.class.get("/#{api_version}/#{router.character_path(value)}", :query => params)
14
+ self.class.get(router.character_path(:id => value), :query => params)
15
15
  end
16
16
 
17
17
  build_response_object(response)
@@ -24,7 +24,7 @@ module Marvelite
24
24
  id = character.id
25
25
  end
26
26
 
27
- response = self.class.get("/#{api_version}/#{router.character_comics_path(id)}", :query => params(query_params))
27
+ response = self.class.get(router.character_comics_path(:id => id), :query => params(query_params))
28
28
  build_response_object(response)
29
29
  end
30
30
 
@@ -34,7 +34,7 @@ module Marvelite
34
34
  return false unless character
35
35
  id = character.id
36
36
  end
37
- response = self.class.get("/#{api_version}/#{router.character_events_path(id)}", :query => params(query_params))
37
+ response = self.class.get(router.character_events_path(:id => id), :query => params(query_params))
38
38
  build_response_object(response)
39
39
  end
40
40
 
@@ -44,7 +44,7 @@ module Marvelite
44
44
  return false unless character
45
45
  id = character.id
46
46
  end
47
- response = self.class.get("/#{api_version}/#{router.character_series_path(id)}", :query => params(query_params))
47
+ response = self.class.get(router.character_series_path(:id => id), :query => params(query_params))
48
48
  build_response_object(response)
49
49
  end
50
50
 
@@ -54,9 +54,17 @@ module Marvelite
54
54
  return false unless character
55
55
  id = character.id
56
56
  end
57
- response = self.class.get("/#{api_version}/#{router.character_stories_path(id)}", :query => params(query_params))
57
+ response = self.class.get(router.character_stories_path(:id => id), :query => params(query_params))
58
58
  build_response_object(response)
59
59
  end
60
+
61
+ def find_character_by_name(name)
62
+ response = self.characters(:name => name)
63
+ return false unless response[:data][:results].size > 0
64
+
65
+ response.id = response[:data][:results][0][:id]
66
+ response
67
+ end
60
68
  end
61
69
  end
62
70
  end
@@ -5,6 +5,7 @@ module Marvelite
5
5
 
6
6
  include Marvelite::API::CharacterMethods
7
7
  include Marvelite::API::ComicMethods
8
+ include Marvelite::API::EventMethods
8
9
 
9
10
  include HTTParty
10
11
  base_uri 'http://gateway.marvel.com'
@@ -16,8 +17,8 @@ module Marvelite
16
17
 
17
18
  def initialize(attrs)
18
19
  super
19
- @router = attrs.fetch(:router) { Marvelite.router }
20
20
  @api_version = attrs.fetch(:api_version) { 'v1' }
21
+ @router = attrs.fetch(:router) { Marvelite.router(:api_version => @api_version) }
21
22
  end
22
23
 
23
24
  private
@@ -36,14 +37,6 @@ module Marvelite
36
37
  end
37
38
  end
38
39
 
39
- def find_character_by_name(name)
40
- response = self.characters(:name => name)
41
- return false unless response[:data][:results].size > 0
42
-
43
- response.id = response[:data][:results][0][:id]
44
- response
45
- end
46
-
47
40
  def build_response_object(response)
48
41
  case response["code"]
49
42
  when 200
@@ -2,32 +2,32 @@ module Marvelite
2
2
  module API
3
3
  module ComicMethods
4
4
  def comics(query_params = {})
5
- response = self.class.get("/#{api_version}/#{router.comics_path}", :query => params(query_params))
5
+ response = self.class.get(router.comics_path, :query => params(query_params))
6
6
  build_response_object(response)
7
7
  end
8
8
 
9
9
  def comic(id)
10
- response = self.class.get("/#{api_version}/#{router.comic_path(id)}", :query => params)
10
+ response = self.class.get(router.comic_path(:id => id), :query => params)
11
11
  build_response_object(response)
12
12
  end
13
13
 
14
14
  def comic_characters(id, query_params = {})
15
- response = self.class.get("/#{api_version}/#{router.comic_characters_path(id)}", :query => params(query_params))
15
+ response = self.class.get(router.comic_characters_path(:id => id), :query => params(query_params))
16
16
  build_response_object(response)
17
17
  end
18
18
 
19
19
  def comic_events(id, query_params = {})
20
- response = self.class.get("/#{api_version}/#{router.comic_events_path(id)}", :query => params(query_params))
20
+ response = self.class.get(router.comic_events_path(:id => id), :query => params(query_params))
21
21
  build_response_object(response)
22
22
  end
23
23
 
24
24
  def comic_creators(id, query_params = {})
25
- response = self.class.get("/#{api_version}/#{router.comic_creators_path(id)}", :query => params(query_params))
25
+ response = self.class.get(router.comic_creators_path(:id => id), :query => params(query_params))
26
26
  build_response_object(response)
27
27
  end
28
28
 
29
29
  def comic_stories(id, query_params = {})
30
- response = self.class.get("/#{api_version}/#{router.comic_stories_path(id)}", :query => params(query_params))
30
+ response = self.class.get(router.comic_stories_path(:id => id), :query => params(query_params))
31
31
  build_response_object(response)
32
32
  end
33
33
  end
@@ -0,0 +1,57 @@
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: 'events'
39
+ path: '/public/events'
40
+ 14:
41
+ name: 'event'
42
+ path: '/public/events/:id'
43
+ 15:
44
+ name: 'event_characters'
45
+ path: '/public/events/:id/characters'
46
+ 16:
47
+ name: 'event_creators'
48
+ path: '/public/events/:id/creators'
49
+ 17:
50
+ name: 'event_comics'
51
+ path: '/public/events/:id/comics'
52
+ 18:
53
+ name: 'event_stories'
54
+ path: '/public/events/:id/stories'
55
+ 19:
56
+ name: 'event_series'
57
+ path: '/public/events/:id/series'
@@ -0,0 +1,80 @@
1
+ module Marvelite
2
+ module API
3
+ module EventMethods
4
+ def events(query_params = {})
5
+ response = self.class.get(router.events_path, :query => params(query_params))
6
+ build_response_object(response)
7
+ end
8
+
9
+ def event(id)
10
+ by_name = id.is_a?(String) ? true : false
11
+ response = if by_name
12
+ find_event_by_name(id)
13
+ else
14
+ # self.class.get(router.character_path(:id => value), :query => params)
15
+ self.class.get(router.event_path(:id => id), :query => params)
16
+ end
17
+ build_response_object(response)
18
+ end
19
+
20
+ def event_characters(id, query_params = {})
21
+ if id.is_a?(String)
22
+ event = find_event_by_name(id)
23
+ return false unless event
24
+ id = event.id
25
+ end
26
+ response = self.class.get(router.event_characters_path(:id => id), :query => params(query_params))
27
+ build_response_object(response)
28
+ end
29
+
30
+ def event_comics(id, query_params = {})
31
+ if id.is_a?(String)
32
+ event = find_event_by_name(id)
33
+ return false unless event
34
+ id = event.id
35
+ end
36
+ response = self.class.get(router.event_comics_path(:id => id), :query => params(query_params))
37
+ build_response_object(response)
38
+ end
39
+
40
+ def event_creators(id, query_params = {})
41
+ if id.is_a?(String)
42
+ event = find_event_by_name(id)
43
+ return false unless event
44
+ id = event.id
45
+ end
46
+ response = self.class.get(router.event_creators_path(:id => id), :query => params(query_params))
47
+ build_response_object(response)
48
+ end
49
+
50
+ def event_series(id, query_params = {})
51
+ if id.is_a?(String)
52
+ event = find_event_by_name(id)
53
+ return false unless event
54
+ id = event.id
55
+ end
56
+ response = self.class.get(router.event_series_path(:id => id), :query => params(query_params))
57
+ build_response_object(response)
58
+ end
59
+
60
+ def event_stories(id, query_params = {})
61
+ if id.is_a?(String)
62
+ event = find_event_by_name(id)
63
+ return false unless event
64
+ id = event.id
65
+ end
66
+ response = self.class.get(router.event_stories_path(:id => id), :query => params(query_params))
67
+ build_response_object(response)
68
+ end
69
+
70
+ protected
71
+ def find_event_by_name(name)
72
+ response = self.events(:name => name)
73
+ return false unless response[:data][:results].size > 0
74
+
75
+ response.id = response[:data][:results][0][:id]
76
+ response
77
+ end
78
+ end
79
+ end
80
+ end
@@ -1,52 +1,47 @@
1
1
  module Marvelite
2
2
  module API
3
3
  class Router
4
- def characters_path
5
- 'public/characters'
6
- end
7
-
8
- def character_path(id)
9
- "public/characters/#{id}"
10
- end
11
-
12
- def character_comics_path(id)
13
- "public/characters/#{id}/comics"
14
- end
15
-
16
- def character_events_path(id)
17
- "public/characters/#{id}/events"
18
- end
19
-
20
- def character_series_path(id)
21
- "public/characters/#{id}/series"
22
- end
23
-
24
- def character_stories_path(id)
25
- "public/characters/#{id}/stories"
26
- end
4
+ require 'yaml'
5
+ attr_accessor :api_version
27
6
 
28
- def comics_path
29
- "public/comics"
7
+ def initialize(attrs = {})
8
+ @api_version = attrs.fetch(:api_version) { 'v1' }
9
+ @routes = []
10
+ load_routes_from_file("#{api_version}.yml")
11
+ map_routes
30
12
  end
31
13
 
32
- def comic_path(id)
33
- "public/comics/#{id}"
14
+ def inspect
15
+ "#<#{self.class}:#{self.object_id}>"
34
16
  end
35
17
 
36
- def comic_characters_path(id)
37
- "public/comics/#{id}/characters"
18
+ def load_routes_from_file(filename)
19
+ file_path = File.join(File.dirname(__FILE__), "config", filename)
20
+ f = YAML.load(File.read(file_path))
21
+ f.each do |_, route|
22
+ add_route(route['name'], route['path'])
23
+ end
38
24
  end
39
25
 
40
- def comic_creators_path(id)
41
- "public/comics/#{id}/creators"
26
+ def routes
27
+ @routes
42
28
  end
43
29
 
44
- def comic_events_path(id)
45
- "public/comics/#{id}/events"
30
+ def add_route(name, endpoint)
31
+ route = [name, endpoint]
32
+ routes << route
46
33
  end
47
34
 
48
- def comic_stories_path(id)
49
- "public/comics/#{id}/stories"
35
+ def map_routes
36
+ routes.each do |name, endpoint|
37
+ self.class.send(:define_method, "#{name}_path") do |params = {}|
38
+ params
39
+ params.each do |p_key, p_value|
40
+ endpoint.gsub!(":#{p_key.to_s}", p_value.to_s)
41
+ end
42
+ "/#{api_version}#{endpoint}"
43
+ end
44
+ end
50
45
  end
51
46
  end
52
47
  end