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,17 @@
1
+ require 'thanos/resources/character'
2
+ require 'thanos/mappers/character_data_mapper'
3
+
4
+ module Thanos
5
+ module Factory
6
+ class Character
7
+ def initialize(results)
8
+ @results = results
9
+ end
10
+
11
+ def build
12
+ attributes = Thanos::CharacterDataMapper.new(@results).map
13
+ Thanos::Character.new(attributes: attributes)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ require 'thanos/mappers/comic_data_mapper'
2
+ require 'thanos/resources/comic'
3
+
4
+ module Thanos
5
+ module Factory
6
+ class Comic
7
+ def initialize(results)
8
+ @results = results
9
+ end
10
+
11
+ def build
12
+ attributes = Thanos::ComicDataMapper.new(@results).map
13
+ Thanos::Comic.new(attributes: attributes)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ require 'thanos/mappers/creator_data_mapper'
2
+ require 'thanos/resources/creator'
3
+
4
+ module Thanos
5
+ module Factory
6
+ class Creator
7
+ def initialize(results)
8
+ @results = results
9
+ end
10
+
11
+ def build
12
+ attributes = Thanos::CreatorDataMapper.new(@results).map
13
+ Thanos::Creator.new(attributes: attributes)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ require 'thanos/resources/date'
2
+
3
+ module Thanos
4
+ module Factory
5
+ class Date
6
+ def initialize(dates)
7
+ @dates = dates
8
+ end
9
+
10
+ def build
11
+ @dates.collect do |date|
12
+ Thanos::Date.new(date)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ require 'thanos/mappers/event_data_mapper'
2
+ require 'thanos/resources/event'
3
+
4
+ module Thanos
5
+ module Factory
6
+ class Event
7
+ def initialize(results)
8
+ @results = results
9
+ end
10
+
11
+ def build
12
+ attributes = Thanos::EventDataMapper.new(@results).map
13
+ Thanos::Event.new(attributes: attributes)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ require 'thanos/resources/image'
2
+
3
+ module Thanos
4
+ module Factory
5
+ class Image
6
+ def initialize(images)
7
+ @images = images
8
+ end
9
+
10
+ def build
11
+ @images.collect do |image|
12
+ Thanos::Image.new(image)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ require 'thanos/resources/item/character'
2
+
3
+ module Thanos
4
+ module Factory
5
+ module Item
6
+ class Character
7
+ def initialize(results)
8
+ @results = results
9
+ end
10
+
11
+ def build
12
+ @results.collect do |character|
13
+ Thanos::Item::Character.new(character)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require 'thanos/resources/item/comic'
2
+
3
+ module Thanos
4
+ module Factory
5
+ module Item
6
+ class Comic
7
+ def initialize(results)
8
+ @results = results
9
+ end
10
+
11
+ def build
12
+ @results.collect do |comic|
13
+ Thanos::Item::Comic.new(comic)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require 'thanos/resources/item/creator'
2
+
3
+ module Thanos
4
+ module Factory
5
+ module Item
6
+ class Creator
7
+ def initialize(results)
8
+ @results = results
9
+ end
10
+
11
+ def build
12
+ @results.collect do |comic|
13
+ Thanos::Item::Creator.new(comic)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ require 'thanos/resources/item/event'
2
+
3
+ module Thanos
4
+ module Factory
5
+ module Item
6
+ class Event
7
+ def initialize(results)
8
+ @results = results
9
+ end
10
+
11
+ def build
12
+ if @results.is_a?(Array)
13
+ @results.collect do |comic|
14
+ Thanos::Item::Event.new(comic)
15
+ end
16
+ else
17
+ [Thanos::Item::Event.new(@results)]
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ require 'thanos/resources/item/series'
2
+
3
+ module Thanos
4
+ module Factory
5
+ module Item
6
+ class Series
7
+ def initialize(results)
8
+ @results = results
9
+ end
10
+
11
+ def build
12
+ if @results.is_a?(Array)
13
+ @results.collect do |comic|
14
+ Thanos::Item::Series.new(comic)
15
+ end
16
+ else
17
+ [Thanos::Item::Series.new(@results)]
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,19 @@
1
+ require 'thanos/resources/item/story'
2
+
3
+ module Thanos
4
+ module Factory
5
+ module Item
6
+ class Story
7
+ def initialize(results)
8
+ @results = results
9
+ end
10
+
11
+ def build
12
+ @results.collect do |comic|
13
+ Thanos::Item::Story.new(comic)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ require 'thanos/resources/price'
2
+
3
+ module Thanos
4
+ module Factory
5
+ class Price
6
+ def initialize(prices)
7
+ @prices = prices
8
+ end
9
+
10
+ def build
11
+ @prices.collect do |price|
12
+ Thanos::Price.new(price)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ require 'thanos/mappers/series_data_mapper'
2
+ require 'thanos/resources/series'
3
+
4
+ module Thanos
5
+ module Factory
6
+ class Series
7
+ def initialize(results)
8
+ @results = results
9
+ end
10
+
11
+ def build
12
+ attributes = Thanos::SeriesDataMapper.new(@results).map
13
+ Thanos::Series.new(attributes: attributes)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ require 'thanos/mappers/story_data_mapper'
2
+ require 'thanos/resources/story'
3
+
4
+ module Thanos
5
+ module Factory
6
+ class Story
7
+ def initialize(results)
8
+ @results = results
9
+ end
10
+
11
+ def build
12
+ attributes = Thanos::StoryDataMapper.new(@results).map
13
+ Thanos::Story.new(attributes: attributes)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ require 'thanos/resources/text_object'
2
+
3
+ module Thanos
4
+ module Factory
5
+ class TextObject
6
+ def initialize(text_objects)
7
+ @text_objects = text_objects
8
+ end
9
+
10
+ def build
11
+ @text_objects.collect do |text_object|
12
+ Thanos::TextObject.new(text_object)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,22 @@
1
+ require 'thanos/resources/thumbnail'
2
+
3
+ module Thanos
4
+ module Factory
5
+ class Thumbnail
6
+ def initialize(thumbnails)
7
+ @thumbnails = thumbnails
8
+ end
9
+
10
+ def build
11
+ # TODO: Determine if an array is ever possible.
12
+ # If this is possible, I will need the following:
13
+ # if @thumbnails.is_a?(Array)
14
+ # @thumbnails.collect do |thumbnail|
15
+ # Thanos::Thumbnail.new(thumbnail)
16
+ # end
17
+ # else
18
+ Thanos::Thumbnail.new(@thumbnails)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,17 @@
1
+ require 'thanos/resources/url'
2
+
3
+ module Thanos
4
+ module Factory
5
+ class Url
6
+ def initialize(urls)
7
+ @urls = urls
8
+ end
9
+
10
+ def build
11
+ @urls.collect do |url|
12
+ Thanos::Url.new(url)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,28 @@
1
+ require 'thanos/response_holder'
2
+ require 'thanos/string_actions'
3
+ require 'thanos/api/client'
4
+ require 'thanos/factories/character'
5
+ require 'thanos/finders/finder_validator'
6
+
7
+ module Thanos
8
+ class CharacterFinder
9
+ ATTRIBUTES = [:name, :comics, :series, :events, :series,
10
+ :nameStartsWith, :modifiedSince]
11
+
12
+ ATTRIBUTES.each do |attribute|
13
+ parameter = StringActions.parameterize(attribute.to_s)
14
+ define_method("find_by_#{parameter}") do |attr|
15
+ find("#{attribute}".to_sym => attr)
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def find(attribute)
22
+ FinderValidator.validate(attribute, ATTRIBUTES)
23
+ response = Thanos::API::Client.new.get(:characters, attribute)
24
+ results = Thanos::ResponseHolder.new(response).results
25
+ Thanos::Factory::Character.new(results).build
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,30 @@
1
+ require 'thanos/api/client'
2
+ require 'thanos/response_holder'
3
+ require 'thanos/string_actions'
4
+ require 'thanos/factories/comic'
5
+ require 'thanos/finders/finder_validator'
6
+
7
+ module Thanos
8
+ class ComicFinder
9
+ ATTRIBUTES = [:title, :titleStarsWith, :format, :formatType, :upc, :isbn,
10
+ :issn, :ean, :noVariants, :digitalId, :hasDigitalIssue,
11
+ :issueNumber, :dateDescriptor, :dateRange, :startYear,
12
+ :modifiedSince, :diamondCode, :sharedAppearances,
13
+ :collaborators, :creators, :characters, :series, :events,
14
+ :stories]
15
+
16
+ ATTRIBUTES.each do |attribute|
17
+ parameter = StringActions.parameterize(attribute.to_s)
18
+ define_method("find_by_#{parameter}") do |attr|
19
+ find("#{attribute}".to_sym => attr)
20
+ end
21
+ end
22
+
23
+ def find(attribute)
24
+ FinderValidator.validate(attribute, ATTRIBUTES)
25
+ response = Thanos::API::Client.new.get(:comics, attribute)
26
+ results = Thanos::ResponseHolder.new(response).results
27
+ Thanos::Factory::Comic.new(results).build
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,31 @@
1
+ require 'thanos/response_holder'
2
+ require 'thanos/string_actions'
3
+ require 'thanos/api/client'
4
+ require 'thanos/factories/creator'
5
+ require 'thanos/finders/finder_validator'
6
+
7
+ module Thanos
8
+ class CreatorFinder
9
+ ATTRIBUTES = [:firstName, :middleName, :lastName, :suffix,
10
+ :nameStartsWith, :firstNameStartsWith,
11
+ :middleNameStartsWith, :lastNameStartsWith,
12
+ :modifiedSince, :comics, :series, :events,
13
+ :stories]
14
+
15
+ ATTRIBUTES.each do |attribute|
16
+ parameter = StringActions.parameterize(attribute.to_s)
17
+ define_method("find_by_#{parameter}") do |attr|
18
+ find("#{attribute}".to_sym => attr)
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def find(attribute)
25
+ FinderValidator.validate(attribute, ATTRIBUTES)
26
+ response = Thanos::API::Client.new.get(:creators, attribute)
27
+ results = Thanos::ResponseHolder.new(response).results
28
+ Thanos::Factory::Creator.new(results).build
29
+ end
30
+ end
31
+ end