thanos 0.0.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +15 -0
  3. data/.hound.yml +64 -0
  4. data/.rspec +2 -0
  5. data/.rubocop.yml +2 -0
  6. data/.travis.yml +4 -0
  7. data/CODE_OF_CONDUCT.md +13 -0
  8. data/Gemfile +4 -0
  9. data/LICENSE.txt +17 -18
  10. data/README.md +93 -16
  11. data/Rakefile +16 -0
  12. data/bin/console +13 -0
  13. data/bin/setup +7 -0
  14. data/lib/thanos.rb +9 -4
  15. data/lib/thanos/api/authentication.rb +19 -0
  16. data/lib/thanos/api/client.rb +26 -0
  17. data/lib/thanos/api/response.rb +16 -0
  18. data/lib/thanos/authentication.rb +5 -0
  19. data/lib/thanos/client.rb +21 -0
  20. data/lib/thanos/factories/character.rb +17 -0
  21. data/lib/thanos/factories/comic.rb +17 -0
  22. data/lib/thanos/factories/creator.rb +17 -0
  23. data/lib/thanos/factories/date.rb +17 -0
  24. data/lib/thanos/factories/event.rb +17 -0
  25. data/lib/thanos/factories/image.rb +17 -0
  26. data/lib/thanos/factories/item/character.rb +19 -0
  27. data/lib/thanos/factories/item/comic.rb +19 -0
  28. data/lib/thanos/factories/item/creator.rb +19 -0
  29. data/lib/thanos/factories/item/event.rb +23 -0
  30. data/lib/thanos/factories/item/series.rb +23 -0
  31. data/lib/thanos/factories/item/story.rb +19 -0
  32. data/lib/thanos/factories/price.rb +17 -0
  33. data/lib/thanos/factories/series.rb +17 -0
  34. data/lib/thanos/factories/story.rb +17 -0
  35. data/lib/thanos/factories/text_object.rb +17 -0
  36. data/lib/thanos/factories/thumbnail.rb +22 -0
  37. data/lib/thanos/factories/url.rb +17 -0
  38. data/lib/thanos/finders/character_finder.rb +28 -0
  39. data/lib/thanos/finders/comic_finder.rb +30 -0
  40. data/lib/thanos/finders/creator_finder.rb +31 -0
  41. data/lib/thanos/finders/event_finder.rb +26 -0
  42. data/lib/thanos/finders/finder_validator.rb +15 -0
  43. data/lib/thanos/finders/series_finder.rb +24 -0
  44. data/lib/thanos/finders/story_finder.rb +24 -0
  45. data/lib/thanos/mappers/character_data_mapper.rb +26 -0
  46. data/lib/thanos/mappers/comic_data_mapper.rb +41 -0
  47. data/lib/thanos/mappers/creator_data_mapper.rb +30 -0
  48. data/lib/thanos/mappers/event_data_mapper.rb +31 -0
  49. data/lib/thanos/mappers/mappable.rb +100 -0
  50. data/lib/thanos/mappers/series_data_mapper.rb +33 -0
  51. data/lib/thanos/mappers/story_data_mapper.rb +25 -0
  52. data/lib/thanos/resources/character.rb +19 -0
  53. data/lib/thanos/resources/comic.rb +27 -0
  54. data/lib/thanos/resources/creator.rb +13 -0
  55. data/lib/thanos/resources/date.rb +10 -0
  56. data/lib/thanos/resources/event.rb +26 -0
  57. data/lib/thanos/resources/image.rb +9 -0
  58. data/lib/thanos/resources/item/character.rb +20 -0
  59. data/lib/thanos/resources/item/comic.rb +20 -0
  60. data/lib/thanos/resources/item/creator.rb +19 -0
  61. data/lib/thanos/resources/item/event.rb +20 -0
  62. data/lib/thanos/resources/item/series.rb +18 -0
  63. data/lib/thanos/resources/item/story.rb +20 -0
  64. data/lib/thanos/resources/price.rb +10 -0
  65. data/lib/thanos/resources/series.rb +23 -0
  66. data/lib/thanos/resources/story.rb +18 -0
  67. data/lib/thanos/resources/text_object.rb +11 -0
  68. data/lib/thanos/resources/thumbnail.rb +11 -0
  69. data/lib/thanos/resources/url.rb +10 -0
  70. data/lib/thanos/response_holder.rb +10 -0
  71. data/lib/thanos/string_actions.rb +7 -0
  72. data/lib/thanos/version.rb +1 -1
  73. data/spikes/call_marvel_api.rb +50 -0
  74. data/spikes/call_marvel_via_thanos.rb +28 -0
  75. data/thanos.gemspec +44 -0
  76. metadata +171 -26
@@ -0,0 +1,26 @@
1
+ require 'thanos/api/client'
2
+ require 'thanos/response_holder'
3
+ require 'thanos/factories/event'
4
+
5
+ module Thanos
6
+ class EventFinder
7
+ ATTRIBUTES = [:name, :nameStartsWith, :modifiedSince, :creators, :series,
8
+ :comics, :stories, :characters, :orderBy, :limit, :offset]
9
+
10
+ ATTRIBUTES.each do |attribute|
11
+ parameter = StringActions.parameterize(attribute.to_s)
12
+ define_method("find_by_#{parameter}") do |attr|
13
+ find("#{attribute}".to_sym => attr)
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def find(attribute)
20
+ FinderValidator.validate(attribute, ATTRIBUTES)
21
+ response = Thanos::API::Client.new.get(:events, attribute)
22
+ results = Thanos::ResponseHolder.new(response).results
23
+ Thanos::Factory::Event.new(results).build
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,15 @@
1
+ module Thanos
2
+ class FinderValidator
3
+ class << self
4
+ def validate(params, allowed_params)
5
+ not_allowed = params.keys - allowed_params
6
+ unless not_allowed.empty?
7
+ raise InvalidParamsError, "Invalid parameters: #{not_allowed}"
8
+ end
9
+ true
10
+ end
11
+ end
12
+ end
13
+
14
+ class InvalidParamsError < Exception; end
15
+ end
@@ -0,0 +1,24 @@
1
+ require 'thanos/api/client'
2
+ require 'thanos/response_holder'
3
+ require 'thanos/factories/series'
4
+
5
+ module Thanos
6
+ class SeriesFinder
7
+ ATTRIBUTES = [:name, :modifiedSince, :creators, :characters, :series,
8
+ :comics, :stories, :orderBy, :limit, :offset]
9
+
10
+ ATTRIBUTES.each do |attribute|
11
+ parameter = StringActions.parameterize(attribute.to_s)
12
+ define_method("find_by_#{parameter}") do |attr|
13
+ find("#{attribute}".to_sym => attr)
14
+ end
15
+ end
16
+
17
+ def find(attribute)
18
+ FinderValidator.validate(attribute, ATTRIBUTES)
19
+ response = Thanos::API::Client.new.get(:series, attribute)
20
+ results = Thanos::ResponseHolder.new(response).results
21
+ Thanos::Factory::Series.new(results).build
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ require 'thanos/api/client'
2
+ require 'thanos/response_holder'
3
+ require 'thanos/factories/story'
4
+
5
+ module Thanos
6
+ class StoryFinder
7
+ ATTRIBUTES = [:modifiedSince, :comics, :series, :events, :creators,
8
+ :characters]
9
+
10
+ ATTRIBUTES.each do |attribute|
11
+ parameter = StringActions.parameterize(attribute.to_s)
12
+ define_method("find_by_#{parameter}") do |attr|
13
+ find("#{attribute}".to_sym => attr)
14
+ end
15
+ end
16
+
17
+ def find(attribute)
18
+ FinderValidator.validate(attribute, ATTRIBUTES)
19
+ response = Thanos::API::Client.new.get(:stories, attribute)
20
+ results = Thanos::ResponseHolder.new(response).results
21
+ Thanos::Factory::Story.new(results).build
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,26 @@
1
+ require 'thanos/mappers/mappable'
2
+
3
+ module Thanos
4
+ class CharacterDataMapper
5
+ include Thanos::Mappable
6
+
7
+ def initialize(results)
8
+ @results = results
9
+ end
10
+
11
+ def map
12
+ {
13
+ id: @results['id'],
14
+ name: @results['name'],
15
+ description: @results['description'],
16
+ resource_uri: @results['resourceURI'],
17
+ urls: urls,
18
+ thumbnail: thumbnail,
19
+ comics: comics,
20
+ stories: stories,
21
+ events: events,
22
+ series: series,
23
+ }
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,41 @@
1
+ require 'thanos/mappers/mappable'
2
+
3
+ module Thanos
4
+ class ComicDataMapper
5
+ include Thanos::Mappable
6
+
7
+ def initialize(results)
8
+ @results = results
9
+ end
10
+
11
+ def map
12
+ {
13
+ id: @results['id'],
14
+ title: @results['title'],
15
+ description: @results['description'],
16
+ resource_uri: @results['resourceURI'],
17
+ format: @results['format'],
18
+ digital_id: @results['digitalId'],
19
+ issue_number: @results['issueNumber'],
20
+ variant_description: @results['variantDescription'],
21
+ isbn: @results['isbn'],
22
+ upc: @results['upc'],
23
+ diamond_code: @results['diamondCode'],
24
+ ean: @results['ean'],
25
+ issn: @results['issn'],
26
+ page_count: @results['pageCount'],
27
+ urls: urls,
28
+ thumbnail: thumbnail,
29
+ stories: stories,
30
+ events: events,
31
+ series: series,
32
+ creators: creators,
33
+ characters: characters,
34
+ prices: prices,
35
+ dates: dates,
36
+ images: images,
37
+ text_objects: text_objects,
38
+ }
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,30 @@
1
+ require 'thanos/mappers/mappable'
2
+
3
+ module Thanos
4
+ class CreatorDataMapper
5
+ include Thanos::Mappable
6
+
7
+ def initialize(results)
8
+ @results = results
9
+ end
10
+
11
+ def map
12
+ {
13
+ id: @results['id'],
14
+ first_name: @results['firstName'],
15
+ middle_name: @results['middleName'],
16
+ last_name: @results['lastName'],
17
+ suffix: @results['suffix'],
18
+ full_name: @results['fullName'],
19
+ description: @results['description'],
20
+ resource_uri: @results['resourceURI'],
21
+ urls: urls,
22
+ thumbnail: thumbnail,
23
+ series: series,
24
+ stories: stories,
25
+ comics: comics,
26
+ events: events,
27
+ }
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,31 @@
1
+ require 'thanos/mappers/mappable'
2
+
3
+ module Thanos
4
+ class EventDataMapper
5
+ include Thanos::Mappable
6
+
7
+ def initialize(results)
8
+ @results = results
9
+ end
10
+
11
+ def map
12
+ {
13
+ id: @results['id'],
14
+ title: @results['title'],
15
+ description: @results['description'],
16
+ resource_uri: @results['resourceURI'],
17
+ start: start_date,
18
+ end: end_date,
19
+ urls: urls,
20
+ thumbnail: thumbnail,
21
+ creators: creators,
22
+ characters: characters,
23
+ series: series,
24
+ stories: stories,
25
+ comics: comics,
26
+ next: next_event,
27
+ previous: previous_event,
28
+ }
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,100 @@
1
+ require 'thanos/factories/url'
2
+ require 'thanos/factories/thumbnail'
3
+ require 'thanos/factories/price'
4
+ require 'thanos/factories/date'
5
+ require 'thanos/factories/image'
6
+ require 'thanos/factories/text_object'
7
+
8
+ require 'thanos/factories/item/comic'
9
+ require 'thanos/factories/item/story'
10
+ require 'thanos/factories/item/event'
11
+ require 'thanos/factories/item/series'
12
+ require 'thanos/factories/item/character'
13
+ require 'thanos/factories/item/creator'
14
+
15
+ module Thanos
16
+ module Mappable
17
+ private
18
+
19
+ def urls
20
+ Thanos::Factory::Url.new(@results['urls']).build
21
+ end
22
+
23
+ def thumbnail
24
+ # TODO: Determine if I should just create the resource thumbnail directly.
25
+ # The rationale is that thumbnails may never have more than one
26
+ # entry, in which case using the factory to build a collection is
27
+ # not necessary.
28
+ # Thanos::Thumbnail.new(@results['thumbnail']) if @results['thumbnail']
29
+
30
+ return unless @results['thumbnail']
31
+ Thanos::Factory::Thumbnail.new(@results['thumbnail']).build
32
+ end
33
+
34
+ def start_date
35
+ DateTime.parse(@results['start'])
36
+ end
37
+
38
+ def end_date
39
+ DateTime.parse(@results['end'])
40
+ end
41
+
42
+ def comics
43
+ Thanos::Factory::Item::Comic.new(@results['comics']['items']).build
44
+ end
45
+
46
+ def stories
47
+ Thanos::Factory::Item::Story.new(@results['stories']['items']).build
48
+ end
49
+
50
+ def events
51
+ Thanos::Factory::Item::Event.new(@results['events']['items']).build
52
+ end
53
+
54
+ def series
55
+ Thanos::Factory::Item::Series.new(
56
+ @results['series']['items'] || @results['series']).build
57
+ end
58
+
59
+ def creators
60
+ Thanos::Factory::Item::Creator.new(@results['creators']['items']).build
61
+ end
62
+
63
+ def characters
64
+ Thanos::Factory::Item::Character.new(
65
+ @results['characters']['items']).build
66
+ end
67
+
68
+ def prices
69
+ Thanos::Factory::Price.new(@results['prices']).build
70
+ end
71
+
72
+ def dates
73
+ Thanos::Factory::Date.new(@results['dates']).build
74
+ end
75
+
76
+ def images
77
+ Thanos::Factory::Image.new(@results['images']).build
78
+ end
79
+
80
+ def text_objects
81
+ Thanos::Factory::TextObject.new(@results['textObjects']).build
82
+ end
83
+
84
+ def next_event
85
+ Thanos::Factory::Item::Event.new(@results['next']).build.first
86
+ end
87
+
88
+ def previous_event
89
+ Thanos::Factory::Item::Event.new(@results['previous']).build.first
90
+ end
91
+
92
+ def next_series
93
+ Thanos::Factory::Item::Series.new(@results['next']).build
94
+ end
95
+
96
+ def previous_series
97
+ Thanos::Factory::Item::Series.new(@results['previous']).build
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,33 @@
1
+ require 'thanos/mappers/mappable'
2
+
3
+ module Thanos
4
+ class SeriesDataMapper
5
+ include Thanos::Mappable
6
+
7
+ def initialize(results)
8
+ @results = results
9
+ end
10
+
11
+ def map
12
+ {
13
+ id: @results['id'],
14
+ title: @results['title'],
15
+ description: @results['description'],
16
+ resource_uri: @results['resourceURI'],
17
+ start_year: @results['startYear'],
18
+ end_year: @results['endYear'],
19
+ rating: @results['rating'],
20
+ type: @results['type'],
21
+ urls: urls,
22
+ thumbnail: thumbnail,
23
+ comics: comics,
24
+ stories: stories,
25
+ events: events,
26
+ creators: creators,
27
+ characters: characters,
28
+ next: next_series.first,
29
+ previous: previous_series.first,
30
+ }
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,25 @@
1
+ require 'thanos/mappers/mappable'
2
+
3
+ module Thanos
4
+ class StoryDataMapper
5
+ include Thanos::Mappable
6
+
7
+ def initialize(results)
8
+ @results = results
9
+ end
10
+
11
+ def map
12
+ {
13
+ title: @results['title'],
14
+ description: @results['description'],
15
+ type: @results['type'],
16
+ resource_uri: @results['resourceURI'],
17
+ characters: characters,
18
+ creators: creators,
19
+ events: events,
20
+ series: series,
21
+ comics: comics,
22
+ }
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,19 @@
1
+ module Thanos
2
+ class Character
3
+ attr_reader :id, :name, :description, :resource_uri, :urls, :thumbnail,
4
+ :comics, :stories, :events, :series
5
+
6
+ def initialize(args)
7
+ @comics = args[:comics]
8
+ @series = args[:series]
9
+ @events = args[:events]
10
+ @stories = args[:stories]
11
+ @urls = args[:urls]
12
+ @thumbnail = args[:thumbnail]
13
+
14
+ args[:attributes].each do |attribute, value|
15
+ instance_variable_set("@#{attribute}", value)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,27 @@
1
+ module Thanos
2
+ class Comic
3
+ attr_reader :id, :title, :description, :format, :resource_uri,
4
+ :issue_number, :ean, :isbn, :upc, :issn, :page_count,
5
+ :digital_id, :diamond_code, :variant_description, :dates,
6
+ :urls, :thumbnail, :text_objects, :images, :prices,
7
+ :stories, :creators, :series, :events, :characters
8
+
9
+ def initialize(args)
10
+ @series = args[:series]
11
+ @stories = args[:stories]
12
+ @creators = args[:creators]
13
+ @events = args[:events]
14
+ @characters = args[:characters]
15
+ @urls = args[:urls]
16
+ @prices = args[:prices]
17
+ @images = args[:images]
18
+ @thumbnail = args[:thumbnail]
19
+ @text_objects = args[:text_objects]
20
+ @dates = args[:dates]
21
+
22
+ args[:attributes].each do |attribute, value|
23
+ instance_variable_set("@#{attribute}", value)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,13 @@
1
+ module Thanos
2
+ class Creator
3
+ attr_reader :id, :first_name, :middle_name, :last_name, :suffix,
4
+ :full_name, :description, :resource_uri, :urls, :thumbnail,
5
+ :series, :stories, :comics, :events
6
+
7
+ def initialize(args)
8
+ args[:attributes].each do |attribute, value|
9
+ instance_variable_set("@#{attribute}", value)
10
+ end
11
+ end
12
+ end
13
+ end