comic_vine-api 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/.rspec +2 -0
- data/.rubocop.yml +6 -0
- data/.travis.yml +36 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +123 -0
- data/Rakefile +1 -0
- data/comic_vine-api.gemspec +32 -0
- data/config/types.json +102 -0
- data/lib/comic_vine/api/api_methods.rb +63 -0
- data/lib/comic_vine/api/http_service.rb +39 -0
- data/lib/comic_vine/api/request.rb +37 -0
- data/lib/comic_vine/api/response.rb +31 -0
- data/lib/comic_vine/api/version.rb +5 -0
- data/lib/comic_vine/api.rb +37 -0
- metadata +158 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: facbc48e025db55e56100c30fee204969f94018c
|
|
4
|
+
data.tar.gz: 9e0c886440158d99d5cb03cb0d401c701caae08b
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 96c184849dbf461edd709e98ad1c21e035298bd4080c133ed00bd63910868e9c03120af840fafd80f916a293ef54022ac559e646f3e8c994b89ef3b15dbf314d
|
|
7
|
+
data.tar.gz: 1ef088063d1c51d1fbf42b738893ddbea62d9b8c2408a40ab3157adb0ab47447377b8bfbb8c037c831200c8c97e667b721f30b3f862389eb50b15c91b03fffdd
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Available ruby versions: http://rubies.travis-ci.org/
|
|
2
|
+
|
|
3
|
+
language: ruby
|
|
4
|
+
|
|
5
|
+
os:
|
|
6
|
+
- linux
|
|
7
|
+
|
|
8
|
+
rvm:
|
|
9
|
+
- '2.1' # latest 2.1.x
|
|
10
|
+
- '2.2.6'
|
|
11
|
+
- '2.3.3'
|
|
12
|
+
- '2.4.0'
|
|
13
|
+
- 'ruby-head'
|
|
14
|
+
|
|
15
|
+
script:
|
|
16
|
+
bundle exec rspec
|
|
17
|
+
|
|
18
|
+
before_install:
|
|
19
|
+
# bundler installation needed for jruby-head
|
|
20
|
+
# https://github.com/travis-ci/travis-ci/issues/5861
|
|
21
|
+
- gem install bundler
|
|
22
|
+
|
|
23
|
+
# Travis OS X support is pretty janky. These are some hacks to include tests
|
|
24
|
+
# only on versions that actually work.
|
|
25
|
+
# (last tested: 2016-11)
|
|
26
|
+
matrix:
|
|
27
|
+
# exclude: {}
|
|
28
|
+
# include: {}
|
|
29
|
+
|
|
30
|
+
allow_failures:
|
|
31
|
+
- rvm: 'ruby-head'
|
|
32
|
+
|
|
33
|
+
# return results as soon as mandatory versions are done
|
|
34
|
+
fast_finish: true
|
|
35
|
+
|
|
36
|
+
sudo: false
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Krzysztof Wawer
|
|
4
|
+
|
|
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:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
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
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# ComicVine::Api
|
|
2
|
+
|
|
3
|
+
[](https://rubygems.org/gems/comic_vine-api)
|
|
4
|
+
[](https://travis-ci.org/comics-apps/comic_vine-api)
|
|
5
|
+
[](https://codeclimate.com/github/comics-apps/comic_vine-api)
|
|
6
|
+
|
|
7
|
+
A simple ComicVine API client for Ruby, inspired by the koala's gem style.
|
|
8
|
+
|
|
9
|
+
This gem contains several advantages over other API clients:
|
|
10
|
+
* unlike with `comic_vine` gem, you can fetch series list
|
|
11
|
+
* you can write own http service class which can use different gem than `faraday`
|
|
12
|
+
* response is returned as pure Hash instead of mapping to different object
|
|
13
|
+
* default http service class allows you to override http options like proxy settings.
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
Add this line to your application's Gemfile:
|
|
18
|
+
|
|
19
|
+
```ruby
|
|
20
|
+
gem 'comic_vine-api'
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
And then execute:
|
|
24
|
+
|
|
25
|
+
$ bundle
|
|
26
|
+
|
|
27
|
+
Or install it yourself as:
|
|
28
|
+
|
|
29
|
+
$ gem install comic_vine-api
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
33
|
+
```ruby
|
|
34
|
+
api_key = 'foo'
|
|
35
|
+
options = {}
|
|
36
|
+
service = ComicVine::Api.new(api_key, **options)
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
There are two static methods:
|
|
40
|
+
|
|
41
|
+
* search
|
|
42
|
+
|
|
43
|
+
```ruby
|
|
44
|
+
service.search(...)
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
* types
|
|
48
|
+
|
|
49
|
+
```ruby
|
|
50
|
+
service.types
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Rest of methods, for resources are creating dynamically. If API some method will change you can call `#redefine_api_methods` which recreate method from `types` API endpoint.
|
|
54
|
+
|
|
55
|
+
Gem provide also universal method which allows you to create custome call to API:
|
|
56
|
+
|
|
57
|
+
```ruby
|
|
58
|
+
service.api_call(path, args, options)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
* path - append to `http://comicvine.gamespot.com/api/`
|
|
62
|
+
* args - query params
|
|
63
|
+
* options - options for http service class
|
|
64
|
+
|
|
65
|
+
Dynamic methods:
|
|
66
|
+
|
|
67
|
+
* `character(id, args)`
|
|
68
|
+
* `characters(args)`
|
|
69
|
+
* `chat(id, args)`
|
|
70
|
+
* `chats(args)`
|
|
71
|
+
* `concept(id, args)`
|
|
72
|
+
* `concepts(args)`
|
|
73
|
+
* `episode(id, args)`
|
|
74
|
+
* `episodes(args)`
|
|
75
|
+
* `issue(id, args)`
|
|
76
|
+
* `issues(args)`
|
|
77
|
+
* `location(id, args)`
|
|
78
|
+
* `locations(args)`
|
|
79
|
+
* `movie(id, args)`
|
|
80
|
+
* `movies(args)`
|
|
81
|
+
* `object(id, args)`
|
|
82
|
+
* `objects(args)`
|
|
83
|
+
* `origin(id, args)`
|
|
84
|
+
* `origins(args)`
|
|
85
|
+
* `person(id, args)`
|
|
86
|
+
* `people(args)`
|
|
87
|
+
* `power(id, args)`
|
|
88
|
+
* `powers(args)`
|
|
89
|
+
* `promo(id, args)`
|
|
90
|
+
* `promos(args)`
|
|
91
|
+
* `publisher(id, args)`
|
|
92
|
+
* `publishers(args)`
|
|
93
|
+
* `series(id, args)`
|
|
94
|
+
* `series_list(args)`
|
|
95
|
+
* `story_arc(id, args)`
|
|
96
|
+
* `story_arcs(args)`
|
|
97
|
+
* `team(id, args)`
|
|
98
|
+
* `teams(args)`
|
|
99
|
+
* `video(id, args)`
|
|
100
|
+
* `videos(args)`
|
|
101
|
+
* `video_type(id, args)`
|
|
102
|
+
* `video_types(args)`
|
|
103
|
+
* `video_category(id, args)`
|
|
104
|
+
* `video_categories(args)`
|
|
105
|
+
* `volume(id, args)`
|
|
106
|
+
* `volumes(args)`
|
|
107
|
+
|
|
108
|
+
Check official API docs what arguments you can use: http://comicvine.gamespot.com/api/documentation
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
## Development
|
|
112
|
+
|
|
113
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
114
|
+
|
|
115
|
+
## Contributing
|
|
116
|
+
|
|
117
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Krzysztof Wawer/comic_vine-api.
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
## License
|
|
121
|
+
|
|
122
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
|
123
|
+
|
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'bundler/gem_tasks'
|
|
@@ -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 'comic_vine/api/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = 'comic_vine-api'
|
|
8
|
+
spec.version = ComicVine::Api::VERSION
|
|
9
|
+
spec.authors = ['Krzysztof Wawer']
|
|
10
|
+
spec.email = ['krzysztof.wawer@gmail.com']
|
|
11
|
+
|
|
12
|
+
spec.summary = 'Interface to ComicVine API'
|
|
13
|
+
spec.description = 'Interface to ComicVine API'
|
|
14
|
+
spec.homepage = ''
|
|
15
|
+
spec.license = 'MIT'
|
|
16
|
+
|
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
|
19
|
+
end
|
|
20
|
+
spec.bindir = 'exe'
|
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
22
|
+
spec.require_paths = ['lib']
|
|
23
|
+
|
|
24
|
+
spec.add_runtime_dependency 'faraday'
|
|
25
|
+
|
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.14'
|
|
27
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.5'
|
|
29
|
+
spec.add_development_dependency 'rubocop'
|
|
30
|
+
spec.add_development_dependency 'vcr', '~> 3.0'
|
|
31
|
+
spec.add_development_dependency 'webmock', '~> 2.3'
|
|
32
|
+
end
|
data/config/types.json
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"detail_resource_name": "character",
|
|
4
|
+
"list_resource_name": "characters",
|
|
5
|
+
"id": 4005
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
"detail_resource_name": "chat",
|
|
9
|
+
"list_resource_name": "chats",
|
|
10
|
+
"id": 2450
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"detail_resource_name": "concept",
|
|
14
|
+
"list_resource_name": "concepts",
|
|
15
|
+
"id": 4015
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"detail_resource_name": "episode",
|
|
19
|
+
"list_resource_name": "episodes",
|
|
20
|
+
"id": 4070
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"detail_resource_name": "issue",
|
|
24
|
+
"list_resource_name": "issues",
|
|
25
|
+
"id": 4000
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"detail_resource_name": "location",
|
|
29
|
+
"list_resource_name": "locations",
|
|
30
|
+
"id": 4020
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"detail_resource_name": "movie",
|
|
34
|
+
"list_resource_name": "movies",
|
|
35
|
+
"id": 4025
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"detail_resource_name": "object",
|
|
39
|
+
"list_resource_name": "objects",
|
|
40
|
+
"id": 4055
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"detail_resource_name": "origin",
|
|
44
|
+
"list_resource_name": "origins",
|
|
45
|
+
"id": 4030
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"detail_resource_name": "person",
|
|
49
|
+
"list_resource_name": "people",
|
|
50
|
+
"id": 4040
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"detail_resource_name": "power",
|
|
54
|
+
"list_resource_name": "powers",
|
|
55
|
+
"id": 4035
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"detail_resource_name": "promo",
|
|
59
|
+
"list_resource_name": "promos",
|
|
60
|
+
"id": 1700
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"detail_resource_name": "publisher",
|
|
64
|
+
"list_resource_name": "publishers",
|
|
65
|
+
"id": 4010
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"detail_resource_name": "series",
|
|
69
|
+
"list_resource_name": "series_list",
|
|
70
|
+
"id": 4075
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"detail_resource_name": "story_arc",
|
|
74
|
+
"list_resource_name": "story_arcs",
|
|
75
|
+
"id": 4045
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"detail_resource_name": "team",
|
|
79
|
+
"list_resource_name": "teams",
|
|
80
|
+
"id": 4060
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"detail_resource_name": "video",
|
|
84
|
+
"list_resource_name": "videos",
|
|
85
|
+
"id": 2300
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
"detail_resource_name": "video_type",
|
|
89
|
+
"list_resource_name": "video_types",
|
|
90
|
+
"id": 2320
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"detail_resource_name": "video_category",
|
|
94
|
+
"list_resource_name": "video_categories",
|
|
95
|
+
"id": 2320
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"detail_resource_name": "volume",
|
|
99
|
+
"list_resource_name": "volumes",
|
|
100
|
+
"id": 4050
|
|
101
|
+
}
|
|
102
|
+
]
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
module ComicVine
|
|
2
|
+
class Api
|
|
3
|
+
module ApiMethods
|
|
4
|
+
def types
|
|
5
|
+
api_call('types', {})
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def search(args = {})
|
|
9
|
+
api_call('search', args)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def initial_define_api_methods
|
|
13
|
+
# types data from API has bug(s), in json file data are fixed
|
|
14
|
+
path = File.join(File.dirname(__FILE__), '../../../config/types.json')
|
|
15
|
+
stored_types = JSON.parse(File.read(path))
|
|
16
|
+
define_api_methods(stored_types)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Maybe in future ComicVine devs will fix bug in types,
|
|
20
|
+
# when it happened then you can still work with new endpoints,
|
|
21
|
+
# just run #redefine_api_methods method,
|
|
22
|
+
def redefine_api_methods
|
|
23
|
+
define_api_methods(types.results, true)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
def define_api_methods(stored_types, redefine = false)
|
|
29
|
+
stored_types.each do |type|
|
|
30
|
+
define_collection_method(type, redefine)
|
|
31
|
+
define_entity_method(type, redefine)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def define_collection_method(type, redefine)
|
|
36
|
+
resource_name = type['list_resource_name']
|
|
37
|
+
optional_define_api_method(resource_name, redefine) do |method_name|
|
|
38
|
+
self.class.send(:define_method, method_name) do |args = {}|
|
|
39
|
+
api_call(resource_name, args)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def define_entity_method(type, redefine)
|
|
45
|
+
resource_name = type['detail_resource_name']
|
|
46
|
+
optional_define_api_method(resource_name, redefine) do |method_name|
|
|
47
|
+
self.class.send(:define_method, method_name) do |id, args = {}|
|
|
48
|
+
path = "#{resource_name}/#{type['id']}-#{id}"
|
|
49
|
+
api_call(path, args)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def optional_define_api_method(type, redefine)
|
|
55
|
+
return if redefine || (!redefine && self.class.method_defined?(type))
|
|
56
|
+
|
|
57
|
+
method_name = :"#{type}_#{Time.now.to_f.to_s.tr('.', '_')}"
|
|
58
|
+
yield(method_name)
|
|
59
|
+
self.class.send(:alias_method, type.to_sym, method_name)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require 'faraday'
|
|
2
|
+
|
|
3
|
+
module ComicVine
|
|
4
|
+
class Api
|
|
5
|
+
module HTTPService
|
|
6
|
+
class << self
|
|
7
|
+
attr_accessor :faraday_middleware, :http_options
|
|
8
|
+
|
|
9
|
+
private
|
|
10
|
+
|
|
11
|
+
def faraday_options(options)
|
|
12
|
+
valid_options = [
|
|
13
|
+
:request, :proxy, :ssl, :builder, :url, :parallel_manager, :params,
|
|
14
|
+
:headers, :builder_class
|
|
15
|
+
]
|
|
16
|
+
Hash[options.select { |key, _| valid_options.include?(key) }]
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
self.http_options ||= {}
|
|
21
|
+
|
|
22
|
+
DEFAULT_MIDDLEWARE = proc do |builder|
|
|
23
|
+
builder.adapter Faraday.default_adapter
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.make_request(request)
|
|
27
|
+
connection = Faraday.new(
|
|
28
|
+
request.server, faraday_options(request.options),
|
|
29
|
+
&(faraday_middleware || DEFAULT_MIDDLEWARE)
|
|
30
|
+
)
|
|
31
|
+
response = connection.send(request.verb, request.path, request.args)
|
|
32
|
+
ComicVine::Api::Response.new(
|
|
33
|
+
status: response.status.to_i, headers: response.headers,
|
|
34
|
+
body: response.body
|
|
35
|
+
)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module ComicVine
|
|
2
|
+
class Api
|
|
3
|
+
class Request
|
|
4
|
+
attr_reader :raw_path, :raw_args, :raw_options
|
|
5
|
+
|
|
6
|
+
GET = 'get'.freeze
|
|
7
|
+
|
|
8
|
+
def initialize(path:, args: {}, options: {})
|
|
9
|
+
@raw_path = path
|
|
10
|
+
@raw_args = args
|
|
11
|
+
@raw_options = options
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def verb
|
|
15
|
+
GET
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def path
|
|
19
|
+
"/api/#{raw_path}/"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def args
|
|
23
|
+
{
|
|
24
|
+
format: :json
|
|
25
|
+
}.merge(raw_args)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def options
|
|
29
|
+
raw_options
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def server
|
|
33
|
+
"http://#{ComicVine::Api::DEFAULT_SERVER}"
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module ComicVine
|
|
2
|
+
class Api
|
|
3
|
+
class Response
|
|
4
|
+
attr_reader :raw_response, :status, :headers, :body, :error, :limit,
|
|
5
|
+
:offset, :number_of_page_results, :number_of_total_results,
|
|
6
|
+
:status_code, :results, :version
|
|
7
|
+
|
|
8
|
+
def initialize(status:, headers:, body:)
|
|
9
|
+
@status = status
|
|
10
|
+
@headers = headers
|
|
11
|
+
@body = body
|
|
12
|
+
|
|
13
|
+
parse_body
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def parse_body
|
|
19
|
+
data = JSON.parse(body)
|
|
20
|
+
methods = %w(error limit offset number_of_page_results
|
|
21
|
+
number_of_total_results status_code results version)
|
|
22
|
+
|
|
23
|
+
methods.each do |method_name|
|
|
24
|
+
instance_variable_set(:"@#{method_name}", data[method_name])
|
|
25
|
+
end
|
|
26
|
+
rescue
|
|
27
|
+
nil
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
require 'comic_vine/api/api_methods'
|
|
4
|
+
require 'comic_vine/api/http_service'
|
|
5
|
+
require 'comic_vine/api/request'
|
|
6
|
+
require 'comic_vine/api/response'
|
|
7
|
+
require 'comic_vine/api/version'
|
|
8
|
+
|
|
9
|
+
module ComicVine
|
|
10
|
+
class Api
|
|
11
|
+
include ApiMethods
|
|
12
|
+
|
|
13
|
+
class << self
|
|
14
|
+
attr_accessor :http_service
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
self.http_service = HTTPService
|
|
18
|
+
|
|
19
|
+
DEFAULT_SERVER = 'comicvine.gamespot.com'.freeze
|
|
20
|
+
|
|
21
|
+
attr_reader :api_key, :options
|
|
22
|
+
|
|
23
|
+
def initialize(api_key, options = {})
|
|
24
|
+
@api_key = api_key
|
|
25
|
+
@options = options
|
|
26
|
+
|
|
27
|
+
initial_define_api_methods
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def api_call(path, args, options = {})
|
|
31
|
+
request = Request.new(
|
|
32
|
+
path: path, args: args.merge(api_key: api_key), options: options
|
|
33
|
+
)
|
|
34
|
+
self.class.http_service.make_request(request)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: comic_vine-api
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Krzysztof Wawer
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-03-05 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: faraday
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: bundler
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '1.14'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '1.14'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rake
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '10.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '10.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rspec
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '3.5'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '3.5'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rubocop
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: vcr
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '3.0'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '3.0'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: webmock
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - "~>"
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '2.3'
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - "~>"
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '2.3'
|
|
111
|
+
description: Interface to ComicVine API
|
|
112
|
+
email:
|
|
113
|
+
- krzysztof.wawer@gmail.com
|
|
114
|
+
executables: []
|
|
115
|
+
extensions: []
|
|
116
|
+
extra_rdoc_files: []
|
|
117
|
+
files:
|
|
118
|
+
- ".gitignore"
|
|
119
|
+
- ".rspec"
|
|
120
|
+
- ".rubocop.yml"
|
|
121
|
+
- ".travis.yml"
|
|
122
|
+
- Gemfile
|
|
123
|
+
- LICENSE.txt
|
|
124
|
+
- README.md
|
|
125
|
+
- Rakefile
|
|
126
|
+
- comic_vine-api.gemspec
|
|
127
|
+
- config/types.json
|
|
128
|
+
- lib/comic_vine/api.rb
|
|
129
|
+
- lib/comic_vine/api/api_methods.rb
|
|
130
|
+
- lib/comic_vine/api/http_service.rb
|
|
131
|
+
- lib/comic_vine/api/request.rb
|
|
132
|
+
- lib/comic_vine/api/response.rb
|
|
133
|
+
- lib/comic_vine/api/version.rb
|
|
134
|
+
homepage: ''
|
|
135
|
+
licenses:
|
|
136
|
+
- MIT
|
|
137
|
+
metadata: {}
|
|
138
|
+
post_install_message:
|
|
139
|
+
rdoc_options: []
|
|
140
|
+
require_paths:
|
|
141
|
+
- lib
|
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
143
|
+
requirements:
|
|
144
|
+
- - ">="
|
|
145
|
+
- !ruby/object:Gem::Version
|
|
146
|
+
version: '0'
|
|
147
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
|
+
requirements:
|
|
149
|
+
- - ">="
|
|
150
|
+
- !ruby/object:Gem::Version
|
|
151
|
+
version: '0'
|
|
152
|
+
requirements: []
|
|
153
|
+
rubyforge_project:
|
|
154
|
+
rubygems_version: 2.5.1
|
|
155
|
+
signing_key:
|
|
156
|
+
specification_version: 4
|
|
157
|
+
summary: Interface to ComicVine API
|
|
158
|
+
test_files: []
|