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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b1c377d5692ad359f53e9f189dd022cc56dbca64
4
- data.tar.gz: 1546b50f176cdf9a2ef0cafa2b25fa5e00042357
3
+ metadata.gz: 58c72c78f9641598e36bf626effe7083335a9474
4
+ data.tar.gz: c522ffb61ef7353312f52923632b477cba61970f
5
5
  SHA512:
6
- metadata.gz: 0ecf2d60e2474e27b6a50323e36d9aafc13a9b6ad51525a427bf1b1e513e92d0d8566af07a21fdc452bee814bb6372bb9cd0a2ac9b44c9818c591a3042fe436a
7
- data.tar.gz: f8c681752bdce3d10c0b07d57888c0b84c0f1e120f50a1794a7303844aae35728ee77c22bb46e4a1242f4140d9e9cdf2ecdc2b069462aa4b35ea2f1e5664da09
6
+ metadata.gz: c6ac2ec186937f8af4b389cf4b86ed6fc6e96ad6dd6285012d6749e607f3049447e7e0c29837ecaa6c964c0bf51c8cddd909da6545ac50ba0bd00d33a31cd039
7
+ data.tar.gz: 4a56a1814e30752f79d2bdcb267ee845799b9efd60b76b87905a1b66f823cd33f83a963a4341cbb7d178ae0937053e453dc688725fdb9364e8b7c08150aaced9
@@ -0,0 +1,15 @@
1
+ /.idea/
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /rdoc/
9
+ /pkg/
10
+ /spikes/api_keys.yml
11
+ /spikes/test_thanos.rb
12
+ /spec/examples.txt
13
+ /spec/reports/
14
+ /tmp/
15
+ .DS_Store
@@ -0,0 +1,64 @@
1
+ AllCops:
2
+ Exclude:
3
+ - thanos.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
+ Enabled: false
58
+
59
+ # fewer parameters
60
+ Metrics/ParameterLists:
61
+ Max: 3
62
+
63
+ Metrics/AbcSize:
64
+ Enabled: false
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,2 @@
1
+ inherit_from:
2
+ - .hound.yml
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in thanos.gemspec
4
+ gemspec
@@ -1,22 +1,21 @@
1
- Copyright (c) 2013 Jeff Nyman
1
+ The MIT License (MIT)
2
2
 
3
- MIT License
3
+ Copyright (c) 2015 Jeff Nyman
4
4
 
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
12
11
 
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
15
14
 
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,36 +1,113 @@
1
+ ![Thanos](http://testerstories.com/files/Thanos.Show.Me.jpg)
2
+
1
3
  # Thanos
2
4
 
3
- [![Build Status](https://secure.travis-ci.org/jnyman/thanos.png)](http://travis-ci.org/jnyman/thanos)
4
- [![Coverage Status](https://coveralls.io/repos/jnyman/thanos/badge.png?branch=master)](https://coveralls.io/r/jnyman/thanos?branch=master)
5
- [![Code Climate](https://codeclimate.com/github/jnyman/thanos.png)](https://codeclimate.com/github/jnyman/thanos)
6
- [![Dependency Status](https://gemnasium.com/jnyman/thanos.png)](https://gemnasium.com/jnyman/thanos)
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.
7
6
 
8
- [![endorse](https://api.coderwall.com/jnyman/endorsecount.png)](https://coderwall.com/jnyman)
7
+ Thanos 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 allow a consumer of the API to drill down into specific details.
9
8
 
10
- TODO: Write a gem description
9
+ Thanos is a [Marvel super-villain](https://en.wikipedia.org/wiki/Thanos) and plays a large role in the current [Marvel cinematic universe](http://marvelcinematicuniverse.wikia.com/wiki/Thanos). Thanos has routinely teamed up with Death in order to achieve universe-wide domination. As accomplishments go, that's moderately impressive, to say the least.
11
10
 
12
11
  ## Installation
13
12
 
14
- Add this line to your application's Gemfile:
13
+ To get the latest stable release, add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'thanos'
17
+ ```
15
18
 
16
- gem 'thanos'
19
+ To get the latest code:
17
20
 
18
- And then execute:
21
+ ```ruby
22
+ gem 'thanos', git: https://github.com/jnyman/thanos
23
+ ```
24
+
25
+ After doing one of the above, execute the following command:
19
26
 
20
27
  $ bundle
21
28
 
22
- Or install it yourself as:
29
+ You can, of course, just install the gem directly like this:
23
30
 
24
31
  $ gem install thanos
25
32
 
26
33
  ## Usage
27
34
 
28
- TODO: Write usage instructions here
35
+ ### Setting Up the Client
36
+
37
+ 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 Thanos client.
38
+
39
+ ```ruby
40
+ require 'thanos'
41
+
42
+ Thanos.authenticate do |key|
43
+ key.public_api_key = 'your public key'
44
+ key.private_api_key = 'your private key'
45
+ end
46
+
47
+ client = Thanos::Client.new
48
+ ```
49
+
50
+ Make sure you put in your own public and private keys that you were assigned. The `client` variable will now hold a `Thanos::Client` instance that you can call endpoint methods on.
51
+
52
+ ## API Access
53
+
54
+ Thanos is a wrapper around the API resources and is designed to provide a simple interface that allows you to communicate with the API without having to know the structure of the information returned by the API.
55
+
56
+ Here is a full example of getting information about a character, assuming you have a `client` instance as shown above:
57
+
58
+ ```ruby
59
+ hulk = client.characters.find_by_name 'Hulk'
60
+
61
+ puts hulk.id
62
+ puts hulk.name
63
+ puts hulk.description
64
+ puts hulk.resource_uri
65
+ puts hulk.thumbnail.path
66
+ puts hulk.thumbnail.extension
67
+ puts hulk.thumbnail.full_path
68
+
69
+ puts hulk.urls.first.url
70
+ puts hulk.urls.first.type
71
+
72
+ hulk.urls.each do |link|
73
+ puts "Url: #{link.url}"
74
+ end
75
+
76
+ hulk.comics.each do |comic|
77
+ puts "Comic: #{comic.name}"
78
+ end
79
+
80
+ hulk.stories.each do |story|
81
+ puts "Story: #{story.name}"
82
+ end
83
+
84
+ hulk.events.each do |event|
85
+ puts "Event: #{event.name}"
86
+ end
87
+
88
+ hulk.series.each do |series|
89
+ puts "Series: #{series.name}"
90
+ end
91
+ ```
92
+
93
+ This shows you that you can call various attributes of the resource -- in this case a `character` -- and display information about the resource (such as `name` and `description`) as well as information related to the resource, such as a list of `events` or `series` that the character was involved in.
29
94
 
30
95
  ## Contributing
31
96
 
32
- 1. Fork it
33
- 2. Create your feature branch (`git checkout -b my-new-feature`)
34
- 3. Commit your changes (`git commit -am 'Add some feature'`)
35
- 4. Push to the branch (`git push origin my-new-feature`)
36
- 5. Create new Pull Request
97
+ Bug reports and pull requests are welcome on GitHub at [https://github.com/jnyman/thanos](https://github.com/jnyman/thanos). While Thanos wants to create a universe of death, despair and destruction, this project is intended to be a safe, welcoming space for collaboration. As such, contributors are very much welcome but are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
98
+
99
+ To contribute to Thanos:
100
+
101
+ 1. [Fork the project](http://gun.io/blog/how-to-github-fork-branch-and-pull-request/).
102
+ 2. Create a feature branch. (`git checkout -b my-new-feature`)
103
+ 3. Commit your changes. (`git commit -am 'new feature'`)
104
+ 4. Push the branch. (`git push origin my-new-feature`)
105
+ 5. Create a new [pull request](https://help.github.com/articles/using-pull-requests).
106
+
107
+ ## Author
108
+
109
+ * [Jeff Nyman](http://testerstories.com)
110
+
111
+ ## License
112
+
113
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,16 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rdoc/task'
3
+ require 'rubocop/rake_task'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RuboCop::RakeTask.new
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ Rake::RDocTask.new do |rdoc|
10
+ rdoc.rdoc_dir = 'doc'
11
+ rdoc.main = 'README.md'
12
+ rdoc.title = "Thanos #{Thanos::VERSION}"
13
+ rdoc.rdoc_files.include('README*', 'lib/**/*.rb')
14
+ end
15
+
16
+ task default: [:spec, :rubocop]
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'thanos'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ require 'pry'
10
+ Pry.start
11
+
12
+ # require 'irb'
13
+ # IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -1,9 +1,14 @@
1
1
  require 'thanos/version'
2
+ require 'thanos/authentication'
3
+ require 'thanos/client'
2
4
 
3
5
  module Thanos
4
-
5
- def self.version
6
- "Thanos v#{Thanos::VERSION}"
6
+ class << self
7
+ attr_accessor :authentication
8
+
9
+ def authenticate
10
+ self.authentication ||= Authentication.new
11
+ yield(authentication)
12
+ end
7
13
  end
8
-
9
14
  end
@@ -0,0 +1,19 @@
1
+ require 'digest/md5'
2
+ require 'thanos/authentication'
3
+
4
+ module Thanos
5
+ module API
6
+ class Authentication
7
+ class << self
8
+ def get
9
+ public_api_key = Thanos.authentication.public_api_key
10
+ private_api_key = Thanos.authentication.private_api_key
11
+ timestamp = Time.now.to_i.to_s
12
+ hash = Digest::MD5.hexdigest(
13
+ timestamp + private_api_key + public_api_key)
14
+ { ts: timestamp, apikey: public_api_key, hash: hash }
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,26 @@
1
+ require 'rest_client'
2
+ require 'thanos/api/response'
3
+ require 'thanos/api/authentication'
4
+
5
+ module Thanos
6
+ module API
7
+ class Client
8
+ API_VERSION = 'v1'
9
+ API_ENDPOINT = 'http://gateway.marvel.com'
10
+
11
+ def get(resource, options)
12
+ url = "#{endpoint}/#{resource}"
13
+ response = RestClient.get(url, params: options.merge(authentication))
14
+ Thanos::API::Response.new(response)
15
+ end
16
+
17
+ def endpoint
18
+ "#{API_ENDPOINT}/#{API_VERSION}/public"
19
+ end
20
+
21
+ def authentication
22
+ Authentication.get
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,16 @@
1
+ require 'json'
2
+
3
+ module Thanos
4
+ module API
5
+ class Response
6
+ attr_reader :code, :status, :data
7
+
8
+ def initialize(raw_response)
9
+ response = JSON.parse(raw_response)
10
+ @code = response['code'].to_i
11
+ @status = response['status']
12
+ @data = response['data']
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ module Thanos
2
+ class Authentication
3
+ attr_accessor :public_api_key, :private_api_key
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ require 'thanos/finders/character_finder'
2
+ require 'thanos/finders/series_finder'
3
+ require 'thanos/finders/event_finder'
4
+ require 'thanos/finders/comic_finder'
5
+ require 'thanos/finders/story_finder'
6
+ require 'thanos/finders/creator_finder'
7
+
8
+ module Thanos
9
+ class Client
10
+ attr_reader :characters, :series, :events, :comics, :stories, :creators
11
+
12
+ def initialize
13
+ @characters = Thanos::CharacterFinder.new
14
+ @series = Thanos::SeriesFinder.new
15
+ @events = Thanos::EventFinder.new
16
+ @comics = Thanos::ComicFinder.new
17
+ @stories = Thanos::StoryFinder.new
18
+ @creators = Thanos::CreatorFinder.new
19
+ end
20
+ end
21
+ end