thanos 0.0.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +15 -0
- data/.hound.yml +64 -0
- data/.rspec +2 -0
- data/.rubocop.yml +2 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +17 -18
- data/README.md +93 -16
- data/Rakefile +16 -0
- data/bin/console +13 -0
- data/bin/setup +7 -0
- data/lib/thanos.rb +9 -4
- data/lib/thanos/api/authentication.rb +19 -0
- data/lib/thanos/api/client.rb +26 -0
- data/lib/thanos/api/response.rb +16 -0
- data/lib/thanos/authentication.rb +5 -0
- data/lib/thanos/client.rb +21 -0
- data/lib/thanos/factories/character.rb +17 -0
- data/lib/thanos/factories/comic.rb +17 -0
- data/lib/thanos/factories/creator.rb +17 -0
- data/lib/thanos/factories/date.rb +17 -0
- data/lib/thanos/factories/event.rb +17 -0
- data/lib/thanos/factories/image.rb +17 -0
- data/lib/thanos/factories/item/character.rb +19 -0
- data/lib/thanos/factories/item/comic.rb +19 -0
- data/lib/thanos/factories/item/creator.rb +19 -0
- data/lib/thanos/factories/item/event.rb +23 -0
- data/lib/thanos/factories/item/series.rb +23 -0
- data/lib/thanos/factories/item/story.rb +19 -0
- data/lib/thanos/factories/price.rb +17 -0
- data/lib/thanos/factories/series.rb +17 -0
- data/lib/thanos/factories/story.rb +17 -0
- data/lib/thanos/factories/text_object.rb +17 -0
- data/lib/thanos/factories/thumbnail.rb +22 -0
- data/lib/thanos/factories/url.rb +17 -0
- data/lib/thanos/finders/character_finder.rb +28 -0
- data/lib/thanos/finders/comic_finder.rb +30 -0
- data/lib/thanos/finders/creator_finder.rb +31 -0
- data/lib/thanos/finders/event_finder.rb +26 -0
- data/lib/thanos/finders/finder_validator.rb +15 -0
- data/lib/thanos/finders/series_finder.rb +24 -0
- data/lib/thanos/finders/story_finder.rb +24 -0
- data/lib/thanos/mappers/character_data_mapper.rb +26 -0
- data/lib/thanos/mappers/comic_data_mapper.rb +41 -0
- data/lib/thanos/mappers/creator_data_mapper.rb +30 -0
- data/lib/thanos/mappers/event_data_mapper.rb +31 -0
- data/lib/thanos/mappers/mappable.rb +100 -0
- data/lib/thanos/mappers/series_data_mapper.rb +33 -0
- data/lib/thanos/mappers/story_data_mapper.rb +25 -0
- data/lib/thanos/resources/character.rb +19 -0
- data/lib/thanos/resources/comic.rb +27 -0
- data/lib/thanos/resources/creator.rb +13 -0
- data/lib/thanos/resources/date.rb +10 -0
- data/lib/thanos/resources/event.rb +26 -0
- data/lib/thanos/resources/image.rb +9 -0
- data/lib/thanos/resources/item/character.rb +20 -0
- data/lib/thanos/resources/item/comic.rb +20 -0
- data/lib/thanos/resources/item/creator.rb +19 -0
- data/lib/thanos/resources/item/event.rb +20 -0
- data/lib/thanos/resources/item/series.rb +18 -0
- data/lib/thanos/resources/item/story.rb +20 -0
- data/lib/thanos/resources/price.rb +10 -0
- data/lib/thanos/resources/series.rb +23 -0
- data/lib/thanos/resources/story.rb +18 -0
- data/lib/thanos/resources/text_object.rb +11 -0
- data/lib/thanos/resources/thumbnail.rb +11 -0
- data/lib/thanos/resources/url.rb +10 -0
- data/lib/thanos/response_holder.rb +10 -0
- data/lib/thanos/string_actions.rb +7 -0
- data/lib/thanos/version.rb +1 -1
- data/spikes/call_marvel_api.rb +50 -0
- data/spikes/call_marvel_via_thanos.rb +28 -0
- data/thanos.gemspec +44 -0
- metadata +171 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58c72c78f9641598e36bf626effe7083335a9474
|
4
|
+
data.tar.gz: c522ffb61ef7353312f52923632b477cba61970f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6ac2ec186937f8af4b389cf4b86ed6fc6e96ad6dd6285012d6749e607f3049447e7e0c29837ecaa6c964c0bf51c8cddd909da6545ac50ba0bd00d33a31cd039
|
7
|
+
data.tar.gz: 4a56a1814e30752f79d2bdcb267ee845799b9efd60b76b87905a1b66f823cd33f83a963a4341cbb7d178ae0937053e453dc688725fdb9364e8b7c08150aaced9
|
data/.gitignore
ADDED
data/.hound.yml
ADDED
@@ -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
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -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
data/LICENSE.txt
CHANGED
@@ -1,22 +1,21 @@
|
|
1
|
-
|
1
|
+
The MIT License (MIT)
|
2
2
|
|
3
|
-
|
3
|
+
Copyright (c) 2015 Jeff Nyman
|
4
4
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
OF
|
22
|
-
|
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
|
-
[
|
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
|
-
[
|
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
|
-
|
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
|
-
|
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
|
-
|
19
|
+
To get the latest code:
|
17
20
|
|
18
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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).
|
data/Rakefile
ADDED
@@ -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]
|
data/bin/console
ADDED
@@ -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
|
data/bin/setup
ADDED
data/lib/thanos.rb
CHANGED
@@ -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
|
-
|
6
|
-
|
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,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
|