uatu-marvel 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +80 -0
- data/Rakefile +11 -0
- data/lib/uatu.rb +17 -0
- data/lib/uatu/base.rb +70 -0
- data/lib/uatu/configuration.rb +31 -0
- data/lib/uatu/connection.rb +80 -0
- data/lib/uatu/error.rb +15 -0
- data/lib/uatu/resource.rb +63 -0
- data/lib/uatu/response.rb +27 -0
- data/lib/uatu/version.rb +3 -0
- data/test/helper.rb +9 -0
- data/test/uatu/base_test.rb +51 -0
- data/test/uatu/configuration_test.rb +19 -0
- data/test/uatu/connection_test.rb +31 -0
- data/test/uatu/resource_test.rb +33 -0
- data/test/uatu/uatu_test.rb +9 -0
- data/uatu.gemspec +32 -0
- metadata +183 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5467565dfd8c16603dab4c904943fe68edcd0759
|
4
|
+
data.tar.gz: 5fb9cb670502a600cc699f0bf6420833da7c14a2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6a1aab0447f70ea74b1c7508ee61892d87087ce487b180e434257a73f8e5ac1dcac0d8d01b59d66cae96cda308cd0faacfee1684fedf2a86ff760a0c08b6e408
|
7
|
+
data.tar.gz: 9f5148ef548b688b61155e77c6821611046487d0cdea73992bede0e86eb33f3c59dc815b8220f1363efaa6b575186c61762e9b7c20a60fc2753bd9abe4d2f48e
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Victor
|
2
|
+
|
3
|
+
MIT License
|
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:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# Uatu
|
2
|
+
|
3
|
+
Uatu is a Wrapper for the Marvel API. See [the API](http://developer.marvel.com) for more details. It relies on OpenStruct to build ruby objects with the API response.
|
4
|
+
|
5
|
+
Uatu is [also](http://en.wikipedia.org/wiki/Uatu) a member of The Watchers, that nice extraterrestrial race who monitor life of other species.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
To get the latest stable:
|
10
|
+
|
11
|
+
gem 'uatu-marvel'
|
12
|
+
|
13
|
+
To get the latest code:
|
14
|
+
|
15
|
+
gem 'uatu-marvel', git: https://github.com/eltercero/uatu
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'uatu'
|
25
|
+
|
26
|
+
# You can also have them in your env.
|
27
|
+
Uatu.configure do |config|
|
28
|
+
config.public_key = 'your_api_key'
|
29
|
+
config.private_key = 'your_private_api_key'
|
30
|
+
end
|
31
|
+
|
32
|
+
watcher = Uatu::Base.new
|
33
|
+
|
34
|
+
# Examples
|
35
|
+
#####################################################
|
36
|
+
# Searching by characters return an Array of results
|
37
|
+
character = watcher.characters(name: 'Daredevil').first
|
38
|
+
character.name
|
39
|
+
=> 'Daredevil'
|
40
|
+
character.description
|
41
|
+
=> "Abandoned by his mother, Matt Murdock was raised by his father, boxer \"Battling Jack\" Murdock, in Hell's Kitchen. Realizing that rules were needed to prevent people from behaving badly, young Matt decided to study law; however, when he saved a man from an oncoming truck, it spilled a radioactive cargo that rendered Matt blind while enhancing his remaining senses. Under the harsh tutelage of blind martial arts master Stick, Matt mastered his heightened senses and became a formidable fighter."
|
42
|
+
|
43
|
+
random_hero = watcher.characters(limit: 1, offset: rand(1000)).first.name
|
44
|
+
=> "Dreaming Celestial"
|
45
|
+
random_heroes_team = watcher.characters(limit: 20, offset: rand(1000)).map(&:name)
|
46
|
+
=> ["Rumiko Fujikawa", "Runaways", "Russian", "S.H.I.E.L.D.", "Sabra", "Sabretooth", "Sabretooth (Age of Apocalypse)", "Sabretooth (House of M)", "Sabretooth (Ultimate)", "Sage", "Salem's Seven (Ultimate)", "Sally Floyd", "Salo", "Sandman", "Santa Claus", "Saracen (Muzzafar Lambert)", "Sasquatch (Walter Langkowski)", "Satana", "Sauron", "Scalphunter"]
|
47
|
+
|
48
|
+
# Parameters are in ruby style. This means no camel case like firstName
|
49
|
+
irish_fella = watcher.creators(first_name: 'Garth', last_name: 'Ennis').first
|
50
|
+
irish_fella.comics.available
|
51
|
+
=> 103
|
52
|
+
|
53
|
+
#You can also search by id
|
54
|
+
character = watcher.character(1009262)
|
55
|
+
character.thumbnail
|
56
|
+
=> "http://i.annihil.us/u/prod/marvel/i/mg/d/50/50febb79985ee.jpg"
|
57
|
+
|
58
|
+
#There is also a handy method for checking out the last url you requested
|
59
|
+
watcher.last_request_url
|
60
|
+
=> "http://gateway.marvel.com/v1/public/characters/1009262?apikey=xxx&hash=xxx&ts=2014-02-08T18%3A52%3A25%2B01%3A00"
|
61
|
+
|
62
|
+
#For combined calls (like, comics in a character => GET /v1/public/characters/{characterId}/comics), you make them like this
|
63
|
+
asgardian_god_comics = watcher.character_comics(1009664)
|
64
|
+
asgardian_god_comics.first.title
|
65
|
+
"Thor: God of Thunder (2012) #2" # Which is, by the way, an amazing comic.
|
66
|
+
```
|
67
|
+
|
68
|
+
## Contributing
|
69
|
+
|
70
|
+
Please, be my guest!
|
71
|
+
|
72
|
+
1. Fork it ( http://github.com/eltercero/uatu/fork )
|
73
|
+
2. Create your feature branch (`git checkout -b nuff-said`)
|
74
|
+
3. Commit your changes (`git commit -am 'Excelsior!'`)
|
75
|
+
4. Push to the branch (`git push origin nuff-said`)
|
76
|
+
5. Create new Pull Request
|
77
|
+
|
78
|
+
## License
|
79
|
+
|
80
|
+
Released under the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/lib/uatu.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'digest/md5'
|
3
|
+
require 'json'
|
4
|
+
require 'hashie/mash'
|
5
|
+
require 'active_support/inflector'
|
6
|
+
|
7
|
+
require 'uatu/configuration'
|
8
|
+
require 'uatu/version'
|
9
|
+
|
10
|
+
require 'uatu/base'
|
11
|
+
|
12
|
+
module Uatu
|
13
|
+
extend Configuration
|
14
|
+
|
15
|
+
|
16
|
+
end
|
17
|
+
|
data/lib/uatu/base.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'uatu/connection'
|
2
|
+
require 'uatu/resource'
|
3
|
+
require 'pry'
|
4
|
+
|
5
|
+
module Uatu
|
6
|
+
class Base
|
7
|
+
include Uatu::Connection
|
8
|
+
|
9
|
+
attr_accessor *Configuration::VALID_CONFIG_KEYS
|
10
|
+
attr_accessor :last_request_url
|
11
|
+
RESOURCES = %w(comic serie character event story creator)
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
Configuration::VALID_CONFIG_KEYS.each do |key|
|
15
|
+
send("#{key}=", Uatu.options[key])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
RESOURCES.each do |method_name|
|
20
|
+
# Singular
|
21
|
+
# example: GET /v1/public/characters/{characterId} => Uatu::Base.new.character
|
22
|
+
define_method method_name do |id, options={}|
|
23
|
+
raise Uatu::Error::BadRequest.new('options must be in a Hash') unless options.is_a?(Hash)
|
24
|
+
options.merge!("#{method_name}_id".to_sym => id)
|
25
|
+
output = request_and_build(method_name, options)
|
26
|
+
output.first
|
27
|
+
end
|
28
|
+
|
29
|
+
# Plural
|
30
|
+
# example: GET /v1/public/characters => Uatu::Base.new.characters
|
31
|
+
define_method method_name.pluralize do |options={}|
|
32
|
+
raise Uatu::Error::BadRequest.new('options must be in a Hash') unless options.is_a?(Hash)
|
33
|
+
request_and_build(method_name, options)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Combined
|
37
|
+
# example: GET /v1/public/characters/{characterId}/comics => Uatu::Base.new.character_comics
|
38
|
+
RESOURCES.each do |combined|
|
39
|
+
unless combined == method_name
|
40
|
+
define_method "#{method_name}_#{combined.pluralize}" do |id, options={}|
|
41
|
+
raise Uatu::Error::BadRequest.new('options must be in a Hash') unless options.is_a?(Hash)
|
42
|
+
options.merge!("#{method_name}_id".to_sym => id)
|
43
|
+
request_and_build("#{method_name}_#{combined.pluralize}", options)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def request_and_build(method_name, options)
|
50
|
+
response = request(method_name, options, conn_options)
|
51
|
+
parsed_body = JSON.parse(response.body)
|
52
|
+
|
53
|
+
self.last_request_url = response.env.url.to_s
|
54
|
+
|
55
|
+
output = parsed_body['data']['results'].map do |resource_hash|
|
56
|
+
"Uatu::#{method_name.split('_').last.classify}".constantize.new(resource_hash)
|
57
|
+
end
|
58
|
+
|
59
|
+
output
|
60
|
+
end
|
61
|
+
|
62
|
+
def conn_options
|
63
|
+
_conn_options = Hashie::Mash.new
|
64
|
+
Configuration::VALID_CONFIG_KEYS.each{|key| _conn_options[key] = send(key)}
|
65
|
+
_conn_options
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Uatu
|
2
|
+
module Configuration
|
3
|
+
|
4
|
+
VALID_CONFIG_KEYS = [:base_url, :public_key, :private_key]
|
5
|
+
|
6
|
+
BASE_URL = "http://gateway.marvel.com"
|
7
|
+
PUBLIC_KEY = ENV["MARVEL_PUBLIC_KEY"]
|
8
|
+
PRIVATE_KEY = ENV["MARVEL_PRIVATE_KEY"]
|
9
|
+
|
10
|
+
attr_accessor *VALID_CONFIG_KEYS
|
11
|
+
|
12
|
+
def self.extended(base)
|
13
|
+
base.reset
|
14
|
+
end
|
15
|
+
|
16
|
+
def configure
|
17
|
+
yield self
|
18
|
+
end
|
19
|
+
|
20
|
+
def options
|
21
|
+
Hash[ * VALID_CONFIG_KEYS.map { |key| [key, send(key)] }.flatten ]
|
22
|
+
end
|
23
|
+
|
24
|
+
def reset
|
25
|
+
self.base_url = BASE_URL
|
26
|
+
self.public_key = PUBLIC_KEY
|
27
|
+
self.private_key = PRIVATE_KEY
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'uatu/response'
|
3
|
+
|
4
|
+
module Uatu
|
5
|
+
module Connection
|
6
|
+
|
7
|
+
def request(method, options, conn_options)
|
8
|
+
conn = build_connection(conn_options)
|
9
|
+
conn_params = prepare_options(options).merge(mandatory_params(conn_options))
|
10
|
+
conn_route = build_route(method, options)
|
11
|
+
|
12
|
+
conn.get conn_route, conn_params
|
13
|
+
end
|
14
|
+
|
15
|
+
def build_connection(conn_options)
|
16
|
+
Faraday.new(url: conn_options.base_url) do |faraday|
|
17
|
+
faraday.use Uatu::Response::RaiseMarvelError
|
18
|
+
|
19
|
+
faraday.request :url_encoded
|
20
|
+
faraday.adapter Faraday.default_adapter
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def build_route(method, options={})
|
25
|
+
route = "/v1/public/#{valid_method(method)}"
|
26
|
+
if resource_id = options["#{valid_method(method).singularize}_id".to_sym]
|
27
|
+
route += "/#{resource_id}"
|
28
|
+
end
|
29
|
+
|
30
|
+
# If it is combined, it comes afet the '_'
|
31
|
+
if method.split('_').count>1 && combined_path = method.split('_').last
|
32
|
+
route += "/#{combined_path}"
|
33
|
+
end
|
34
|
+
|
35
|
+
route
|
36
|
+
end
|
37
|
+
|
38
|
+
def prepare_options(options)
|
39
|
+
valid_opts = {}
|
40
|
+
|
41
|
+
# We remove innecessary keys that should go on the route
|
42
|
+
_options = options.reject{|key, value| key.to_s.match(/.*_id/)}
|
43
|
+
|
44
|
+
# We change the names, so 'format_type' becomes 'formatType'
|
45
|
+
_options.each{|key, value| valid_opts[unrubify(key)] = value }
|
46
|
+
|
47
|
+
# An array should become a string with comma separated values
|
48
|
+
valid_opts.each{|key, value| valid_opts[key] = value.join(',') if value.is_a?(Array) }
|
49
|
+
|
50
|
+
valid_opts
|
51
|
+
end
|
52
|
+
|
53
|
+
def unrubify(name)
|
54
|
+
key = name.to_s
|
55
|
+
unrubified_key_array = key.split('_')
|
56
|
+
unrubified_key_array[1..-1].each(&:capitalize!)
|
57
|
+
unrubified_key_array.join.to_sym
|
58
|
+
end
|
59
|
+
|
60
|
+
def valid_method(method)
|
61
|
+
_method = method.split('_').first.pluralize
|
62
|
+
raise 'InvalidMethod' unless %w(characters series creators comics events stories).include?(_method)
|
63
|
+
_method
|
64
|
+
end
|
65
|
+
|
66
|
+
def current_timestamp
|
67
|
+
DateTime.now.to_s
|
68
|
+
end
|
69
|
+
|
70
|
+
def hash(timestamp, conn_options)
|
71
|
+
Digest::MD5.hexdigest("#{timestamp}#{conn_options.private_key}#{conn_options.public_key}")
|
72
|
+
end
|
73
|
+
|
74
|
+
def mandatory_params(conn_options)
|
75
|
+
ts = current_timestamp
|
76
|
+
{apikey: conn_options.public_key, ts: ts, hash: hash(ts, conn_options)}
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
data/lib/uatu/error.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module Uatu
|
2
|
+
class Error < StandardError
|
3
|
+
attr_reader :http_headers
|
4
|
+
|
5
|
+
def initialize(message, http_headers={})
|
6
|
+
@http_headers = http_headers
|
7
|
+
super(message)
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
class Error::ClientError < Uatu::Error; end
|
13
|
+
class Error::BadRequest < Uatu::Error; end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Uatu
|
2
|
+
class Resource < OpenStruct
|
3
|
+
|
4
|
+
def initialize(resource_hash)
|
5
|
+
super(improve_hash(resource_hash))
|
6
|
+
end
|
7
|
+
|
8
|
+
def improve_hash(original_hash)
|
9
|
+
output_hash = underscore_keys(original_hash)
|
10
|
+
output_hash = add_shortcuts(output_hash)
|
11
|
+
output_hash = mashify(output_hash)
|
12
|
+
output_hash
|
13
|
+
end
|
14
|
+
|
15
|
+
# We change the hasehs to mashes (Hashie::Mash) so it's easier to manipulate
|
16
|
+
def mashify(hash)
|
17
|
+
_hash = {}
|
18
|
+
hash.each do |k,v|
|
19
|
+
_hash[k] = if v.is_a?(Hash)
|
20
|
+
Hashie::Mash.new(v)
|
21
|
+
else
|
22
|
+
v
|
23
|
+
end
|
24
|
+
end
|
25
|
+
_hash
|
26
|
+
end
|
27
|
+
|
28
|
+
# Underscore names of the Hash. I mean... this is Ruby, right?.
|
29
|
+
def underscore_keys(hash)
|
30
|
+
_hash = {}
|
31
|
+
hash.each do |k, v|
|
32
|
+
_hash[k.to_s.underscore] = if v.is_a?(Hash)
|
33
|
+
underscore_keys(v)
|
34
|
+
elsif v.is_a?(Array) and v.first.is_a?(Hash)
|
35
|
+
v.map{|h| underscore_keys(h)}
|
36
|
+
else
|
37
|
+
v
|
38
|
+
end
|
39
|
+
end
|
40
|
+
_hash
|
41
|
+
end
|
42
|
+
|
43
|
+
# That "thumbnail" hash in the original response drives me crazy
|
44
|
+
def add_shortcuts(args)
|
45
|
+
_args = {}
|
46
|
+
args.each do |k, v|
|
47
|
+
_args[k] = case k.to_s
|
48
|
+
when 'thumbnail' then [v['path'],v['extension']].join('.')
|
49
|
+
else v
|
50
|
+
end
|
51
|
+
end
|
52
|
+
_args
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
class Character < Resource ; end
|
58
|
+
class Event < Resource ; end
|
59
|
+
class Comic < Resource ; end
|
60
|
+
class Story < Resource ; end
|
61
|
+
class Serie < Resource ; end
|
62
|
+
class Creator < Resource ; end
|
63
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'uatu/error'
|
3
|
+
|
4
|
+
module Uatu
|
5
|
+
module Response
|
6
|
+
|
7
|
+
class RaiseMarvelError < Faraday::Response::Middleware
|
8
|
+
|
9
|
+
def on_complete(env)
|
10
|
+
status = env[:status]
|
11
|
+
body = env[:body]
|
12
|
+
headers = env[:response_headers]
|
13
|
+
|
14
|
+
parsed_body = JSON.parse(body)
|
15
|
+
code = parsed_body['code']
|
16
|
+
message = parsed_body['message'] || parsed_body['status']
|
17
|
+
|
18
|
+
unless code.to_i == 200
|
19
|
+
raise Uatu::Error::ClientError.new "#{code} - #{message}\n ", {body: body, headers: headers}
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
data/lib/uatu/version.rb
ADDED
data/test/helper.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe '.base' do
|
4
|
+
|
5
|
+
before do
|
6
|
+
keys?
|
7
|
+
@uatu = Uatu::Base.new
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should be able to connect to Marvel API and bring a character" do
|
11
|
+
hero = @uatu.character(1009262)
|
12
|
+
hero.name.must_equal 'Daredevil'
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should be able to connect to Marvel API and bring a character by name" do
|
16
|
+
hero = @uatu.characters(name: 'Daredevil').first
|
17
|
+
hero.name.must_equal 'Daredevil'
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should be able to connect to Marvel API and bring comics from a character " do
|
21
|
+
hero_comics = @uatu.character_comics(1009262)
|
22
|
+
hero_comics.first.class.must_equal Uatu::Comic
|
23
|
+
hero_comics.first.characters.items.any?{|item| item['name'].must_equal 'Daredevil' }
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should be able to connect to Marvel API and bring a creator" do
|
27
|
+
creator = @uatu.creator(2)
|
28
|
+
creator.first_name.must_equal 'Garth'
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should be able to connect to Marvel API and bring a creator by name" do
|
32
|
+
creator = @uatu.creators(first_name: 'Garth', last_name: 'Ennis').first
|
33
|
+
creator.first_name.must_equal 'Garth'
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should be able to connect to Marvel API and bring an event" do
|
37
|
+
event = @uatu.event(238)
|
38
|
+
event.title.must_equal 'Civil War'
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should be able to connect to Marvel API and bring an event by nae" do
|
42
|
+
event = @uatu.events(name: 'Civil War').first
|
43
|
+
event.id.must_equal 238
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should be able to connect to Marvel API and bring an comic" do
|
47
|
+
comic = @uatu.comic(41530)
|
48
|
+
comic.title.must_equal 'Ant-Man: So (Trade Paperback)'
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe '.configure' do
|
5
|
+
after do
|
6
|
+
Uatu.reset
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should set the public and private key" do
|
10
|
+
Uatu.configure do |config|
|
11
|
+
config.public_key = 'PUBLIC_KEY'
|
12
|
+
config.private_key = 'PRIVATE_KEY'
|
13
|
+
end
|
14
|
+
|
15
|
+
Uatu.public_key.must_equal 'PUBLIC_KEY'
|
16
|
+
Uatu.private_key.must_equal 'PRIVATE_KEY'
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe '.connect' do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@uatu = Uatu::Base.new
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should prepare options just fine" do
|
11
|
+
unrubified = @uatu.prepare_options(format_type: 'comic', date_descriptor: 'lastWeek', limit: 20, character_id: '1009262')
|
12
|
+
|
13
|
+
unrubified[:formatType].must_equal 'comic'
|
14
|
+
unrubified[:dateDescriptor].must_equal 'lastWeek'
|
15
|
+
unrubified[:limit].must_equal 20
|
16
|
+
unrubified[:characterId].must_equal nil
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should build normal routes just fine" do
|
20
|
+
route = @uatu.build_route('character', {})
|
21
|
+
route.must_equal "/v1/public/characters"
|
22
|
+
|
23
|
+
route = @uatu.build_route('characters', {})
|
24
|
+
route.must_equal "/v1/public/characters"
|
25
|
+
|
26
|
+
route = @uatu.build_route('character', {character_id: '1009262'})
|
27
|
+
route.must_equal "/v1/public/characters/1009262"
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe '.initialize' do
|
5
|
+
|
6
|
+
|
7
|
+
it "should underscore the response keys and add the shortcuts" do
|
8
|
+
original = {"id"=>1009521,
|
9
|
+
"name"=>" Hank Pym",
|
10
|
+
"resourceURI" => "http://gateway.marvel.com/v1/public/characters/1009521",
|
11
|
+
"thumbnail" =>
|
12
|
+
{ "path" => "http://i.annihil.us/u/prod/marvel/i/mg/8/c0/4ce5a0e31f109",
|
13
|
+
"extension" => "jpg"
|
14
|
+
},
|
15
|
+
"comics"=>
|
16
|
+
{ "available"=>44,
|
17
|
+
"items"=>
|
18
|
+
[{"resourceURI"=>"http://gateway.marvel.com/v1/public/comics/35533",
|
19
|
+
"name"=>"Amazing Spider-Man (1999) #661"}]
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
resource = Uatu::Resource.new(original)
|
24
|
+
resource.thumbnail.must_equal "http://i.annihil.us/u/prod/marvel/i/mg/8/c0/4ce5a0e31f109.jpg"
|
25
|
+
resource.resource_uri.must_equal "http://gateway.marvel.com/v1/public/characters/1009521"
|
26
|
+
resource.resourceURI.must_equal nil
|
27
|
+
resource.comics.items.first.resource_uri.must_equal "http://gateway.marvel.com/v1/public/comics/35533"
|
28
|
+
resource.comics.items.first.resourceURI.must_equal nil
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
end
|
data/uatu.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'uatu/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "uatu-marvel"
|
8
|
+
spec.version = Uatu::VERSION
|
9
|
+
spec.authors = ["Victor"]
|
10
|
+
spec.email = ["victor.martin84@gmail.com"]
|
11
|
+
spec.summary = %q{Marvel API Wrapper}
|
12
|
+
spec.description = %q{Marvel API Wrapper for Ruby.}
|
13
|
+
spec.homepage = "https://github.com/eltercero/uatu"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
24
|
+
spec.add_development_dependency "rake", '~> 10.1'
|
25
|
+
|
26
|
+
spec.add_development_dependency 'faraday', '~>0.9'
|
27
|
+
spec.add_development_dependency 'minitest', '~>5.2'
|
28
|
+
spec.add_development_dependency 'json', '~>1.8'
|
29
|
+
spec.add_development_dependency 'hashie', '~>2.0'
|
30
|
+
spec.add_development_dependency 'pry', '~>0.9'
|
31
|
+
spec.add_development_dependency 'activesupport', '~>3.2'
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,183 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: uatu-marvel
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Victor
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.1'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: faraday
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.9'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.9'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: json
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.8'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.8'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: hashie
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.9'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.9'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: activesupport
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3.2'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '3.2'
|
125
|
+
description: Marvel API Wrapper for Ruby.
|
126
|
+
email:
|
127
|
+
- victor.martin84@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".travis.yml"
|
134
|
+
- Gemfile
|
135
|
+
- LICENSE.txt
|
136
|
+
- README.md
|
137
|
+
- Rakefile
|
138
|
+
- lib/uatu.rb
|
139
|
+
- lib/uatu/base.rb
|
140
|
+
- lib/uatu/configuration.rb
|
141
|
+
- lib/uatu/connection.rb
|
142
|
+
- lib/uatu/error.rb
|
143
|
+
- lib/uatu/resource.rb
|
144
|
+
- lib/uatu/response.rb
|
145
|
+
- lib/uatu/version.rb
|
146
|
+
- test/helper.rb
|
147
|
+
- test/uatu/base_test.rb
|
148
|
+
- test/uatu/configuration_test.rb
|
149
|
+
- test/uatu/connection_test.rb
|
150
|
+
- test/uatu/resource_test.rb
|
151
|
+
- test/uatu/uatu_test.rb
|
152
|
+
- uatu.gemspec
|
153
|
+
homepage: https://github.com/eltercero/uatu
|
154
|
+
licenses:
|
155
|
+
- MIT
|
156
|
+
metadata: {}
|
157
|
+
post_install_message:
|
158
|
+
rdoc_options: []
|
159
|
+
require_paths:
|
160
|
+
- lib
|
161
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
|
+
requirements:
|
168
|
+
- - ">="
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
version: '0'
|
171
|
+
requirements: []
|
172
|
+
rubyforge_project:
|
173
|
+
rubygems_version: 2.2.0
|
174
|
+
signing_key:
|
175
|
+
specification_version: 4
|
176
|
+
summary: Marvel API Wrapper
|
177
|
+
test_files:
|
178
|
+
- test/helper.rb
|
179
|
+
- test/uatu/base_test.rb
|
180
|
+
- test/uatu/configuration_test.rb
|
181
|
+
- test/uatu/connection_test.rb
|
182
|
+
- test/uatu/resource_test.rb
|
183
|
+
- test/uatu/uatu_test.rb
|