comicvine 0.1.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e57f06754f14d9c6e34e4c7bb96c9dfd7f3b5a05
4
+ data.tar.gz: 3b7e8ee97f5e4201482545f1e55746376a24c3c0
5
+ SHA512:
6
+ metadata.gz: 7ae0274f1a68527ba65c43344de16bb918d392041ea19ef79f678bd24251d9445cddf6408b974959a148fa80bfdc29607ed48738285ea6fde82261c2b178abd8
7
+ data.tar.gz: 28ba70a48ca692f6d17ad15aeade62684a98f3f713bc1dcf40fc0416d5f8e24e81c5417b59edb6bb19a8e34075e20839e9958e5a3e88a6ec63921909d5269d4a
Binary file
Binary file
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in comicvine.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Holden Omans
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.
@@ -0,0 +1,86 @@
1
+ # Comicvine
2
+
3
+ A ruby gem to interface with the [ComicVine API](http://comicvine.gamespot.com/api/).
4
+
5
+ Some code was built off of work by [Patrick Sharp](https://github.com/Jakanapes), you can find it [here](https://github.com/Jakanapes/ComicVine)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'comicvine'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install comicvine
22
+
23
+ Then set a environmental variable named `CV_API_KEY` to your ComicVine API key **(optional)**
24
+
25
+ $ export CV_API_KEY=18357f40df87fb4a4aa6bbbb27cd8ad1deb08d3e
26
+
27
+ ## Usage
28
+
29
+ If you did not set the env variable `CV_API_KEY` then you need to set the class `api_key` before using. If you did set the env variable you do not need to set this.
30
+
31
+ ```ruby
32
+ resp = ComicVine::API.api_key = '18357f40df87fb4a4aa6bbbb27cd8ad1deb08d3e'
33
+ ```
34
+
35
+ Gather response from a url:
36
+
37
+ ```ruby
38
+ resp = ComicVine::API.get_details_by_url('http://comicvine.gamespot.com/api/issue/4000-371103')
39
+ ```
40
+
41
+ You can also fetch lists of resources while passing API options: (see [ComicVine API Docs](http://comicvine.gamespot.com/api/documentation) for optional values)
42
+
43
+ ```ruby
44
+ vol_list = ComicVine::API.get_list(:volumes, limit: 50)
45
+ ```
46
+
47
+ You can fetch a more specific result by id:
48
+
49
+ ```ruby
50
+ issue = ComicVine::API.get_details(:issue, '371103')
51
+ ```
52
+
53
+ Performing a search:
54
+
55
+ ```ruby
56
+ results = ComicVine::API.search(:volume, 'Avengers ', limit: 5)
57
+
58
+ # Go to next 5 results
59
+ results.next_page
60
+
61
+ # Go to last 5 results
62
+ results.prev_page
63
+ ```
64
+
65
+ Create also create an `ComicVine::API` instance using your API key:
66
+
67
+ ```ruby
68
+ api = ComicVine::API.new('18357f40df87fb4a4aa6bbbb27cd8ad1deb08d3e')
69
+ ```
70
+
71
+ You can gather more detailed API information at http://rubydoc.info/gems/comicvine
72
+
73
+ ## Development
74
+
75
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
76
+
77
+ To install this gem onto your local machine, run `gem install comicvine`. Or you can download it from https://rubygems.org/gems/comicvine
78
+
79
+ ## Contributing
80
+
81
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kalinon/ruby-comicvine-api.
82
+
83
+ ## License
84
+
85
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
86
+
@@ -0,0 +1,27 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+ require 'yard'
4
+
5
+ # Test tasks
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/*_test.rb']
10
+ end
11
+
12
+ YARD::Rake::YardocTask.new do |t|
13
+ t.files = ['lib/**/*.rb'] # optional
14
+ t.options = %w{--private} # optional
15
+ t.stats_options = ['--list-undoc'] # optional
16
+ end
17
+
18
+ # Default task
19
+ task :default => :test
20
+
21
+ task :gen_checksum do
22
+ require 'digest/sha2'
23
+ built_gem_path = 'pkg/comicvine-'+ComicVine::VERSION+'.gem'
24
+ checksum = Digest::SHA512.new.hexdigest(File.read(built_gem_path))
25
+ checksum_path = 'checksum/comicvine-'+ComicVine::VERSION+'.gem.sha512'
26
+ File.open(checksum_path, 'w' ) {|f| f.write(checksum) }
27
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'comicvine'
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
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,21 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDgDCCAmigAwIBAgIBATANBgkqhkiG9w0BAQUFADBDMRUwEwYDVQQDDAxob2xk
3
+ ZW4ub21hbnMxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkW
4
+ A2NvbTAeFw0xNjExMDkxNTU5MTdaFw0xNzExMDkxNTU5MTdaMEMxFTATBgNVBAMM
5
+ DGhvbGRlbi5vbWFuczEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPy
6
+ LGQBGRYDY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2V7yrTuO
7
+ 4FNzWlhQL2R8Vdx5LKX/oewZ7bKh/2GJcR5R7mowdqejlfzJb7abtmYsQfyvwNfy
8
+ NrKneghJ/rLflQ1NrlehYSYLlBFTVuymPvejG+EH5C2/RJqhm2zyfjkisasqhWk8
9
+ Bq6IUPX1l8C78Kkd6t3QR/n3zr1Ip25NicpJ2flBMHPg3IV9qaNXywkCzutkEMoW
10
+ FuHdHMN2cDMUnhM9qGOK7nvRk7rkP/yJAp+sf2nv+C99s5CMNuvnGeSgnX7IMcRV
11
+ Ks2FrSvqKDj24Xf5kHdlcpDrS1VcFsAkIT6bVBm19KO8pFvZkDJE76Yshy80FRpQ
12
+ bijjrYQhYXiM4QIDAQABo38wfTAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNV
13
+ HQ4EFgQUbbbHhJ0Z4S/c5FcDSqEVx7Yk1agwIQYDVR0RBBowGIEWaG9sZGVuLm9t
14
+ YW5zQGdtYWlsLmNvbTAhBgNVHRIEGjAYgRZob2xkZW4ub21hbnNAZ21haWwuY29t
15
+ MA0GCSqGSIb3DQEBBQUAA4IBAQCoC/7FnCsRFIV/rwAJRXY3Ao0qdbnksPrqUhP0
16
+ 7A8m8PccIDuUspq/WtkhzSMLZvzurlXEw1qdLtRLS2LnftQQuo5YPz6PQj4XAx8w
17
+ yF48j5e3XvUZJiMQ+cIsXPnjes13JgnP/KOfILgfIz9ad0pGMMUCTLYahu+fXqxE
18
+ if+otWjB2is7MBxd+krcr8vCJ4E46a8H3zyBN/tSgGw4RwkxHnXekTJvMy4skcSB
19
+ VpDNqh/BlGMQ0mqAEuBFZFSNaroph6JLUz1ykVvQENOQLThxAjolK7SAUrdoBDOc
20
+ fXEVP1s+hpJB6IEU8/LW016TU8WpnA+MHGfJRtkrUm/cEsWU
21
+ -----END CERTIFICATE-----
@@ -0,0 +1 @@
1
+ 98a260c7e46e2166f400b41fc88d9da43d2f75c42712fd1f137734d20f8cebdeb101b735edb005f94cf67878d7f44c7da686775229edbc2751d0468581feed7c
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'comicvine/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'comicvine'
8
+ spec.version = ComicVine::VERSION
9
+ spec.authors = ['Holden Omans']
10
+ spec.email = ['holden.omans@gmail.com']
11
+
12
+ spec.summary = %q{Api interface to ComicVine. Allows for searches and returning specific information on resources.}
13
+ spec.description = %q{Interface to ComicVine API}
14
+ spec.homepage = 'https://github.com/kalinon/ruby-comicvine-api'
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.cert_chain = ['certs/homans.pem']
25
+ spec.signing_key = File.expand_path('~/.ssh/gem-private_key.pem') if $0 =~ /gem\z/
26
+
27
+ spec.add_development_dependency 'bundler', '~> 1.13'
28
+ spec.add_development_dependency 'rake', '~> 10.0'
29
+ spec.add_development_dependency 'minitest', '~> 5.9', '>= 5.9.1'
30
+ spec.add_development_dependency 'minitest-reporters', '~> 1.1', '>= 1.1.12'
31
+ spec.add_development_dependency 'rdoc', '~> 4.2', '>= 4.2.1'
32
+ spec.add_development_dependency 'yard', '~> 0.9', '>= 0.9.5'
33
+
34
+ # Dependencies
35
+ spec.add_dependency 'rest-client', '~> 2.0'
36
+ end
@@ -0,0 +1,301 @@
1
+ require 'comicvine/version'
2
+ require 'comicvine/list'
3
+ require 'comicvine/resource'
4
+ require 'rest-client'
5
+ require 'cgi'
6
+ require 'json'
7
+
8
+ ## Yard Doc generation stuff
9
+ # @!macro [new] raise.ResourceNotSupportedError
10
+ # @raise [ResourceNotSupportedError] indicating the resource requested is not supported
11
+ # @!macro [new] raise.ComicVineAPIError
12
+ # @raise [ComicVineAPIError] indicating the api request code recived
13
+
14
+ ##
15
+ # Base ComicVine module, holds default api variables
16
+ #
17
+ module ComicVine
18
+ # ComicVine api version (1.0)
19
+ API_VERSION = '1.0'
20
+
21
+ # Base ComicVine url
22
+ API_URL = 'http://comicvine.gamespot.com/api'
23
+
24
+ # ComicVine format (json)
25
+ API_FORMAT = 'json'
26
+
27
+ # Array of available resources
28
+ API_RESOURCES = [:character, :characters, :chat, :chats, :concept, :concepts, :episode, :episodes, :issue, :issues,
29
+ :location, :locations, :movie, :movies, :object, :objects, :origin, :origins, :person, :people,
30
+ :power, :powers, :promo, :promos, :publisher, :publishers, :series, :series_list, :search, :story_arc,
31
+ :story_arcs, :team, :teams, :types, :video, :videos, :video_type, :video_types, :video_category,
32
+ :video_categories, :volume, :volumes]
33
+ ##
34
+ # Class to interact and query the ComicVine API
35
+ # @since 0.1.0
36
+ class API
37
+
38
+ ##
39
+ # Raised when a resource is not implemented on the current API
40
+ #
41
+ # Must be included in {ComicVine::API_RESOURCES}
42
+ #
43
+ # @since 0.1.0
44
+ class ResourceNotSupportedError < ScriptError
45
+ end
46
+
47
+ ##
48
+ # Raised when a ComicVine API error is encountered
49
+ #
50
+ # @since 0.1.0
51
+ class ComicVineAPIError < ScriptError
52
+ end
53
+
54
+ # Hash containing ComicVine resource types and corresponding id values
55
+ @@types = nil
56
+ # Last time we pulled types from the API
57
+ @@last_type_check = nil
58
+
59
+ # ComicVine API Key. Set to the environmental variable CV_API_KEY by default if present
60
+ @@api_key = ENV['CV_API_KEY'] || nil
61
+
62
+ class << self
63
+
64
+ ##
65
+ # @return [ComicVine::API]
66
+ # @since 0.1.0
67
+ def new(key)
68
+ @@api_key=key
69
+ self
70
+ end
71
+
72
+ ##
73
+ # Returns ComicVine API Key. Set to the environmental variable CV_API_KEY by default if present
74
+ # @return [String]
75
+ # @since 0.1.0
76
+ def api_key
77
+ @@api_key || ENV['CV_API_KEY']
78
+ end
79
+
80
+ ##
81
+ # Sets the ComicVine API Key. Overrides the environmental variable CV_API_KEY
82
+ # @param key [String]
83
+ # @since 0.1.0
84
+ def api_key=(key)
85
+ @@api_key = key
86
+ end
87
+
88
+ ##
89
+ # Makes request for the current api version
90
+ #
91
+ # @return [String]
92
+ # @since 0.1.0
93
+ def get_api_version
94
+ _make_request(:types)['version'].to_s
95
+ end
96
+
97
+ ##
98
+ # Search ComicVine with the provided information
99
+ # @example
100
+ # ComicVine::API.search(:volume, 'Avengers ', limit: 5)
101
+ #
102
+ # @param resource [Symbol] The symbol of the resource to query
103
+ # @param query [String] The string to query
104
+ # @param params [Hash] optional parameters to pass to CV API
105
+ # @return [ComicVine::SearchResults]
106
+ # @since 0.1.0
107
+ def search(resource, query, **params)
108
+ options = {
109
+ resources: resource.to_s,
110
+ query: CGI::escape(query)
111
+ }
112
+
113
+ options.merge! params
114
+
115
+ ComicVine::SearchResults.new(_make_request(:search, options), resource, query)
116
+ end
117
+
118
+ ##
119
+ # Returns comicvine type information
120
+ #
121
+ # @return [Hash]
122
+ # @since 0.1.0
123
+ def types
124
+ if @@types.nil? || (@@last_type_check + (4 * 60 * 60)) < Time.now
125
+ @@last_type_check = Time.now
126
+ @@types = _make_request(:types)['results']
127
+ end
128
+ @@types
129
+ end
130
+
131
+ ##
132
+ # Cycles through type hash to return the +resource+ hash of the matching the detail_resource_name
133
+ # @example
134
+ # ComicVine::API.find_detail(:issue) #=> { "detail_resource_name": "issue", "list_resource_name": "issues", "id": 4000 }
135
+ # @param resource [Symbol] The symbol of the resource to return
136
+ # @return [Hash]
137
+ # @since 0.1.0
138
+ def find_detail(resource)
139
+ types.find { |t| t['detail_resource_name'] == resource.to_s }
140
+ end
141
+
142
+ ##
143
+ # Cycles through type hash to return the +resource+ hash of the matching the list_resource_name
144
+ # @example
145
+ # ComicVine::API.find_list(:issues) #=> { "detail_resource_name": "issue", "list_resource_name": "issues", "id": 4000 }
146
+ # @param resource [Symbol] The symbol of the resource to return
147
+ # @return [Hash]
148
+ # @since 0.1.0
149
+ def find_list(resource)
150
+ types.find { |t| t['list_resource_name'] == resource.to_s }
151
+ end
152
+
153
+ ##
154
+ # Fetches provided
155
+ # @example
156
+ # ComicVine::API.get_list(:volumes, limit: 50)
157
+ # @param resource [Symbol] The symbol of the resource to fetch (plural)
158
+ # @param params [Hash] optional parameters to pass to CV API
159
+ # @return [ComicVine::ResourceList]
160
+ # @since 0.1.0
161
+ def get_list(resource, **params)
162
+ resp = _make_request(resource, params)
163
+ ComicVine::ResourceList.new(resp, resource)
164
+ end
165
+
166
+ ##
167
+ # Fetches provided +resource+ with associated +id+
168
+ # @example
169
+ # ComicVine::API.get_details(:issue, '371103')
170
+ # @param resource [Symbol] The symbol of the resource to fetch
171
+ # @param id [String] The id of the resource you would like to fetch
172
+ # @param params [Hash] optional parameters to pass to CV API
173
+ # @return [ComicVine::Resource]
174
+ # @since 0.1.0
175
+ def get_details(resource, id, **params)
176
+ ops_hash = {
177
+ id: id
178
+ }
179
+ ops_hash.merge! params
180
+ resp = _make_request(resource, ops_hash)
181
+ ComicVine::Resource.new(resp['results'])
182
+ end
183
+
184
+ ##
185
+ # Will fetch the provided +url+ as a {ComicVine::Resource}
186
+ # @example
187
+ # ComicVine::API.get_details_by_url('http://comicvine.gamespot.com/api/issue/4000-371103')
188
+ # @param url [String]
189
+ # @return [ComicVine::Resource]
190
+ def get_details_by_url(url)
191
+ resp = _make_url_request(url)
192
+ ComicVine::Resource.new(resp['results'])
193
+ end
194
+
195
+ ##
196
+ # Checks missing method against the resource {@@types types} and passes it to {find_list} or {get_details}
197
+ def method_missing(method_sym, *arguments, &block)
198
+ if find_list(method_sym)
199
+ get_list method_sym, arguments.first
200
+ elsif find_detail(method_sym)
201
+ get_details method_sym, *arguments
202
+ elsif
203
+ super
204
+ end
205
+ end
206
+
207
+ private
208
+
209
+ ##
210
+ # Builds api url string based on provided +resource+ and optional +id+
211
+ #
212
+ # @example Build a url for resource +:issue+ with an id of +371103+
213
+ # _build_base_url(:issue, '371103') #=> "http://comicvine.gamespot.com/api/issue/4000-371103"
214
+ # @example Build a url for resource +:issues+
215
+ # _build_base_url(:issues) #=> "http://comicvine.gamespot.com/api/issues"
216
+ #
217
+ # @param resource [Symbol] The symbol of the resource to build the url for
218
+ # @param id [String] optional id for specific resource requests
219
+ # @return [String] Full url of the requested resource
220
+ # @macro raise.ResourceNotSupportedError
221
+ def _build_base_url(resource, id = nil)
222
+ if ComicVine::API_RESOURCES.include? resource
223
+ if !id.nil?
224
+ API_URL + '/' + resource.to_s + '/' + "#{self.find_detail(resource)['id']}-#{id.to_s}"
225
+ else
226
+ API_URL + '/' + resource.to_s
227
+ end
228
+ else
229
+ raise ResourceNotSupportedError, resource.to_s + ' is not a supported resource'
230
+ end
231
+ end
232
+
233
+ ##
234
+ # Executes api request based on provided +resource+ and +params+
235
+ #
236
+ # @example Return 5 results from the +:characters+ resource
237
+ # _make_request(:characters, limit: 5)
238
+ #
239
+ # @param resource [Symbol] The symbol of the resource to fetch
240
+ # @param params [Hash] The named key value pairs of query parameters
241
+ # @return [Hash]
242
+ # @since 0.1.0
243
+ # @macro raise.ComicVineAPIError
244
+ # @macro raise.ResourceNotSupportedError
245
+ def _make_request(resource, **params)
246
+ _make_url_request(_build_base_url(resource, params[:id] || nil), params)
247
+ end
248
+
249
+ ##
250
+ # Executes api request based on provided +resource+ and +params+
251
+ #
252
+ # @example Make a simple request with +limit: 1+
253
+ # _make_url_request('http://comicvine.gamespot.com/api/issues', limit: 1)
254
+ #
255
+ # @param url [String] Request url
256
+ # @param params [Hash] optional request parameters
257
+ # @return [Hash]
258
+ # @since 0.1.0
259
+ # @macro raise.ComicVineAPIError
260
+ def _make_url_request(url, **params)
261
+ # Default options hash
262
+ options = {
263
+ params: {
264
+ api_key: self.api_key,
265
+ format: ComicVine::API_FORMAT
266
+ }
267
+ }
268
+
269
+ options[:params].merge! params
270
+
271
+ begin
272
+ # Perform request
273
+ request = RestClient::Request.execute(
274
+ method: :get,
275
+ url: url,
276
+ timeout: 10,
277
+ headers: options
278
+ )
279
+ #request = RestClient.get(url, options)
280
+ rescue RestClient::NotFound, RestClient::Exceptions::ReadTimeout => e
281
+ raise ComicVineAPIError, e.message
282
+ end
283
+
284
+ case request.code
285
+ when 200
286
+ req = JSON.parse(request.body)
287
+ if req['error'].eql?('OK')
288
+ req
289
+ else
290
+ raise ComicVineAPIError, req['error']
291
+ end
292
+ when 420
293
+ raise ComicVineAPIError, 'Recived a '+request.code+' http response: You\'ve been rate limited'
294
+ else
295
+ raise ComicVineAPIError, 'Recived a '+request.code+' http response'
296
+ end
297
+ end
298
+
299
+ end
300
+ end
301
+ end
@@ -0,0 +1,99 @@
1
+ module ComicVine
2
+
3
+ ##
4
+ # Enumerable list for multiple ComicVine results
5
+ # @since 0.1.0
6
+ class List
7
+ include Enumerable
8
+
9
+ attr_reader :total_count
10
+ attr_reader :page_count
11
+ attr_reader :offset
12
+ attr_reader :limit
13
+ attr_reader :cvos
14
+
15
+ def initialize(resp)
16
+ @total_count = resp['number_of_total_results']
17
+ @page_count = resp['number_of_page_results']
18
+ @offset = resp['offset']
19
+ @limit = resp['limit']
20
+ end
21
+
22
+ def each
23
+ @cvos.each { |c| yield c }
24
+ end
25
+
26
+ def last
27
+ @cvos.last
28
+ end
29
+
30
+ def page
31
+ (@offset / @limit) + 1
32
+ end
33
+
34
+ protected
35
+
36
+ def update_ivals(new_cvol)
37
+ @total_count = new_cvol.total_count
38
+ @offset = new_cvol.offset
39
+ @limit = new_cvol.limit
40
+
41
+ @cvos = new_cvol.cvos
42
+ end
43
+
44
+ end
45
+
46
+ ##
47
+ # Class container for multiple ComicVine resources
48
+ # @since 0.1.0
49
+ class ResourceList < List
50
+ attr_reader :resource
51
+
52
+ def initialize(resp, resc)
53
+ super(resp)
54
+
55
+ @resource = resc
56
+ @cvos = resp['results'].map { |r| ComicVine::Resource.new(r) }
57
+ end
58
+
59
+ def next_page
60
+ return nil if (@offset + @page_count) >= @total_count
61
+ update_ivals(ComicVine::API.send(@resource, {:limit => @limit, :offset => (@offset + @page_count)}))
62
+ end
63
+
64
+ def prev_page
65
+ return nil if @offset == 0
66
+ update_ivals(ComicVine::API.send(@resource, {:limit => @limit, :offset => (@offset - @page_count)}))
67
+ end
68
+ end
69
+
70
+ ##
71
+ # Class container for ComicVine search results
72
+ # @since 0.1.0
73
+ class SearchResults < List
74
+ attr_reader :resource
75
+ attr_reader :query
76
+
77
+ def initialize(resp, resc, query)
78
+ super(resp)
79
+
80
+ @resource = resc
81
+ @query = query
82
+ @cvos = resp['results'].map { |r| ComicVine::Resource.new(r) }
83
+ end
84
+
85
+ ##
86
+ # Moves search to the next offset results
87
+ def next_page
88
+ return nil if (@offset + @page_count) >= @total_count
89
+ update_ivals(ComicVine::API.search(@resource, @query, {:limit => @limit, :page => (((@offset + @page_count) / @limit) + 1)}))
90
+ end
91
+
92
+ ##
93
+ # Moves search to the previous offset results
94
+ def prev_page
95
+ return nil if @offset == 0
96
+ update_ivals(ComicVine::API.search(@resource, @query, {:limit => @limit, :page => (@offset / @limit)}))
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,194 @@
1
+ module ComicVine
2
+ ##
3
+ # Holds the various modules for ComicVine resource attributes
4
+ # @since 0.1.0
5
+ module ResourceAttributes
6
+
7
+ ##
8
+ # Module to hold character resource attributes
9
+ # @since 0.1.0
10
+ module Character
11
+ attr_accessor :aliases, :api_detail_url, :birth, :character_enemies, :character_friends,
12
+ :count_of_issue_appearances, :creators, :date_added, :date_last_updated, :deck, :description,
13
+ :first_appeared_in_issue, :gender, :id, :image, :issue_credits, :issues_died_in, :movies, :name,
14
+ :origin, :powers, :publisher, :real_name, :site_detail_url, :story_arc_credits, :team_enemies,
15
+ :team_friends, :teams, :volume_credits
16
+ end
17
+
18
+ ##
19
+ # Module to hold chat resource attributes
20
+ # @since 0.1.0
21
+ module Chat
22
+ attr_accessor :api_detail_url, :channel_name, :deck, :image, :password, :site_detail_url, :title
23
+ end
24
+
25
+ ##
26
+ # Module to hold concept resource attributes
27
+ # @since 0.1.0
28
+ module Concept
29
+ attr_accessor :aliases, :api_detail_url, :count_of_issue_appearances, :date_added, :date_last_updated, :deck,
30
+ :description, :first_appeared_in_issue, :id, :image, :issue_credits, :movies, :name,
31
+ :site_detail_url, :start_year, :volume_credits
32
+ end
33
+
34
+ ##
35
+ # Module to hold episode resource attributes
36
+ # @since 0.1.0
37
+ module Episode
38
+ attr_accessor :aliases, :api_detail_url, :character_credits, :characters_died_in, :concept_credits, :air_date,
39
+ :date_added, :date_last_updated, :deck, :description, :first_appearance_characters,
40
+ :first_appearance_concepts, :first_appearance_locations, :first_appearance_objects,
41
+ :first_appearance_storyarcs, :first_appearance_teams, :has_staff_review, :id, :image,
42
+ :episode_number, :location_credits, :name, :object_credits, :person_credits, :site_detail_url,
43
+ :story_arc_credits, :team_credits, :series
44
+ end
45
+
46
+ ##
47
+ # Module to hold issue resource attributes
48
+ # @since 0.1.0
49
+ module Issue
50
+ attr_accessor :aliases, :api_detail_url, :character_credits, :characters_died_in, :concept_credits, :cover_date,
51
+ :date_added, :date_last_updated, :deck, :description, :disbanded_teams,
52
+ :first_appearance_characters, :first_appearance_concepts, :first_appearance_locations,
53
+ :first_appearance_objects, :first_appearance_storyarcs, :first_appearance_teams, :has_staff_review,
54
+ :id, :image, :issue_number, :location_credits, :name, :object_credits, :person_credits,
55
+ :site_detail_url, :store_date, :story_arc_credits, :team_credits, :teams_disbanded_in, :volume
56
+ end
57
+
58
+ ##
59
+ # Module to hold location resource attributes
60
+ # @since 0.1.0
61
+ module Location
62
+ attr_accessor :aliases, :api_detail_url, :count_of_issue_appearances, :date_added, :date_last_updated, :deck,
63
+ :description, :first_appeared_in_issue, :id, :image, :issue_credits, :movies, :name,
64
+ :site_detail_url, :start_year, :story_arc_credits, :volume_credits
65
+ end
66
+
67
+ ##
68
+ # Module to hold movie resource attributes
69
+ # @since 0.1.0
70
+ module Movie
71
+ attr_accessor :api_detail_url, :box_office_revenue, :budget, :characters, :concepts, :date_added,
72
+ :date_last_updated, :deck, :description, :distributor, :has_staff_review, :id, :image, :locations,
73
+ :name, :producers, :rating, :release_date, :runtime, :site_detail_url, :studios, :teams, :things,
74
+ :total_revenue, :writers
75
+ end
76
+
77
+ ##
78
+ # Module to hold object resource attributes
79
+ # @since 0.1.0
80
+ module Object
81
+ attr_accessor :aliases, :api_detail_url, :count_of_issue_appearances, :date_added, :date_last_updated, :deck,
82
+ :description, :first_appeared_in_issue, :id, :image, :issue_credits, :movies, :name,
83
+ :site_detail_url, :start_year, :story_arc_credits, :volume_credits
84
+ end
85
+
86
+ ##
87
+ # Module to hold origin resource attributes
88
+ # @since 0.1.0
89
+ module Origin
90
+ attr_accessor :api_detail_url, :character_set, :id, :name, :profiles, :site_detail_url
91
+ end
92
+
93
+ ##
94
+ # Module to hold person resource attributes
95
+ # @since 0.1.0
96
+ module Person
97
+ attr_accessor :aliases, :api_detail_url, :birth, :count_of_issue_appearances, :country, :created_characters,
98
+ :date_added, :date_last_updated, :death, :deck, :description, :email, :gender, :hometown, :id,
99
+ :image, :issue_credits, :name, :site_detail_url, :story_arc_credits, :volume_credits, :website
100
+ end
101
+
102
+ ##
103
+ # Module to hold power resource attributes
104
+ # @since 0.1.0
105
+ module Power
106
+ attr_accessor :attr_accessor, :aliases, :api_detail_url, :characters, :date_added, :date_last_updated,
107
+ :description, :id, :name, :site_detail_url
108
+ end
109
+
110
+ ##
111
+ # Module to hold promo resource attributes
112
+ # @since 0.1.0
113
+ module Promo
114
+ attr_accessor :api_detail_url, :date_added, :deck, :id, :image, :link, :name, :resource_type, :user
115
+ end
116
+
117
+ ##
118
+ # Module to hold publisher resource attributes
119
+ # @since 0.1.0
120
+ module Publisher
121
+ attr_accessor :aliases, :api_detail_url, :characters, :date_added, :date_last_updated, :deck, :description, :id,
122
+ :image, :location_address, :location_city, :location_state, :name, :site_detail_url, :story_arcs,
123
+ :teams, :volumes
124
+ end
125
+ ##
126
+ # Module to hold series resource attributes
127
+ # @since 0.1.0
128
+ module Series
129
+ attr_accessor :aliases, :api_detail_url, :character_credits, :count_of_episodes, :date_added, :date_last_updated,
130
+ :deck, :description, :first_episode, :id, :image, :last_episode, :location_credits, :name,
131
+ :publisher, :site_detail_url, :start_year
132
+ end
133
+
134
+ ##
135
+ # Module to hold story_arc resource attributes
136
+ # @since 0.1.0
137
+ module StoryArc
138
+ attr_accessor :aliases, :api_detail_url, :count_of_issue_appearances, :date_added, :date_last_updated, :deck,
139
+ :description, :first_appeared_in_issue, :id, :image, :issues, :movies, :name, :publisher,
140
+ :site_detail_url
141
+ end
142
+
143
+ ##
144
+ # Module to hold team resource attributes
145
+ # @since 0.1.0
146
+ module Team
147
+ attr_accessor :aliases, :api_detail_url, :character_enemies, :character_friends, :characters,
148
+ :count_of_issue_appearances, :count_of_team_members, :date_added, :date_last_updated, :deck,
149
+ :description, :disbanded_in_issues, :first_appeared_in_issue, :id, :image, :issue_credits,
150
+ :issues_disbanded_in, :movies, :name, :publisher, :site_detail_url, :story_arc_credits,
151
+ :volume_credits
152
+ end
153
+
154
+ ##
155
+ # Module to hold type resource attributes
156
+ # @since 0.1.0
157
+ module Type
158
+ attr_accessor :detail_resource_name, :list_resource_name, :id
159
+ end
160
+
161
+ ##
162
+ # Module to hold video resource attributes
163
+ # @since 0.1.0
164
+ module Video
165
+ attr_accessor :api_detail_url, :deck, :hd_url, :high_url, :id, :image, :length_seconds, :low_url, :name,
166
+ :publish_date, :site_detail_url, :url, :user
167
+ end
168
+
169
+ ##
170
+ # Module to hold video_category resource attributes
171
+ # @since 0.1.0
172
+ module VideoCategory
173
+ attr_accessor :api_detail_url, :deck, :id, :name, :site_detail_url
174
+ end
175
+
176
+ ##
177
+ # Module to hold video_type resource attributes
178
+ # @since 0.1.0
179
+ module VideoType
180
+ attr_accessor :api_detail_url, :deck, :id, :name, :site_detail_url
181
+ end
182
+
183
+ ##
184
+ # Module to hold volume resource attributes
185
+ # @since 0.1.0
186
+ module Volume
187
+ attr_accessor :aliases, :api_detail_url, :character_credits, :concept_credits, :count_of_issues, :date_added,
188
+ :date_last_updated, :deck, :description, :first_issue, :id, :image, :last_issue, :location_credits,
189
+ :name, :object_credits, :person_credits, :publisher, :site_detail_url, :start_year, :team_credits
190
+ end
191
+
192
+ end
193
+ end
194
+
@@ -0,0 +1,53 @@
1
+ module ComicVine
2
+
3
+ ##
4
+ # Class container for a singular ComicVine resource
5
+ # @since 0.1.0
6
+ class Resource
7
+
8
+ def initialize(args)
9
+ args.each do |k, v|
10
+ # Add an attribute reader for each key
11
+ # noinspection RubyResolve
12
+ self.class.class_eval { attr_reader k } unless self.respond_to? k
13
+
14
+ # Convert sub arrays to objects
15
+ v.collect! { |i| Resource.new i } if v.kind_of?(Array) && !v.empty? && v.first.key?('api_detail_url')
16
+
17
+ # Convert sub hashes to objects
18
+ v = Resource.new v if v.kind_of?(Hash) && v.key?('api_detail_url')
19
+
20
+ # Set the instance variable to value
21
+ instance_variable_set "@#{k}", v
22
+ end
23
+ end
24
+
25
+ # @return [ComicVine::Resource]
26
+ def fetch
27
+ ComicVine::API.get_details_by_url(self.api_detail_url)
28
+ end
29
+
30
+ # @private
31
+ def method_missing(method_sym, *arguments, &block)
32
+ if method_sym.to_s =~ /^get_(.*)$/
33
+ key = method_sym.to_s.sub 'get_', ''
34
+ if instance_variable_defined?("@#{key}")
35
+ item = instance_variable_get("@#{key}")
36
+ if item.kind_of?(Array) && item.first.kind_of?(Resource)
37
+ res = []
38
+ item.each do |i|
39
+ res << i.fetch
40
+ end
41
+ return res
42
+ end
43
+ if item.kind_of?(Resource)
44
+ return item.fetch
45
+ end
46
+ else
47
+ super
48
+ end
49
+ elsif super
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,4 @@
1
+ module ComicVine
2
+ # Current gem version number
3
+ VERSION = '0.1.1'
4
+ end
metadata ADDED
@@ -0,0 +1,206 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: comicvine
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Holden Omans
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDgDCCAmigAwIBAgIBATANBgkqhkiG9w0BAQUFADBDMRUwEwYDVQQDDAxob2xk
14
+ ZW4ub21hbnMxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkW
15
+ A2NvbTAeFw0xNjExMDkxNTU5MTdaFw0xNzExMDkxNTU5MTdaMEMxFTATBgNVBAMM
16
+ DGhvbGRlbi5vbWFuczEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPy
17
+ LGQBGRYDY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2V7yrTuO
18
+ 4FNzWlhQL2R8Vdx5LKX/oewZ7bKh/2GJcR5R7mowdqejlfzJb7abtmYsQfyvwNfy
19
+ NrKneghJ/rLflQ1NrlehYSYLlBFTVuymPvejG+EH5C2/RJqhm2zyfjkisasqhWk8
20
+ Bq6IUPX1l8C78Kkd6t3QR/n3zr1Ip25NicpJ2flBMHPg3IV9qaNXywkCzutkEMoW
21
+ FuHdHMN2cDMUnhM9qGOK7nvRk7rkP/yJAp+sf2nv+C99s5CMNuvnGeSgnX7IMcRV
22
+ Ks2FrSvqKDj24Xf5kHdlcpDrS1VcFsAkIT6bVBm19KO8pFvZkDJE76Yshy80FRpQ
23
+ bijjrYQhYXiM4QIDAQABo38wfTAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNV
24
+ HQ4EFgQUbbbHhJ0Z4S/c5FcDSqEVx7Yk1agwIQYDVR0RBBowGIEWaG9sZGVuLm9t
25
+ YW5zQGdtYWlsLmNvbTAhBgNVHRIEGjAYgRZob2xkZW4ub21hbnNAZ21haWwuY29t
26
+ MA0GCSqGSIb3DQEBBQUAA4IBAQCoC/7FnCsRFIV/rwAJRXY3Ao0qdbnksPrqUhP0
27
+ 7A8m8PccIDuUspq/WtkhzSMLZvzurlXEw1qdLtRLS2LnftQQuo5YPz6PQj4XAx8w
28
+ yF48j5e3XvUZJiMQ+cIsXPnjes13JgnP/KOfILgfIz9ad0pGMMUCTLYahu+fXqxE
29
+ if+otWjB2is7MBxd+krcr8vCJ4E46a8H3zyBN/tSgGw4RwkxHnXekTJvMy4skcSB
30
+ VpDNqh/BlGMQ0mqAEuBFZFSNaroph6JLUz1ykVvQENOQLThxAjolK7SAUrdoBDOc
31
+ fXEVP1s+hpJB6IEU8/LW016TU8WpnA+MHGfJRtkrUm/cEsWU
32
+ -----END CERTIFICATE-----
33
+ date: 2016-11-09 00:00:00.000000000 Z
34
+ dependencies:
35
+ - !ruby/object:Gem::Dependency
36
+ name: bundler
37
+ requirement: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.13'
42
+ type: :development
43
+ prerelease: false
44
+ version_requirements: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '1.13'
49
+ - !ruby/object:Gem::Dependency
50
+ name: rake
51
+ requirement: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '10.0'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '10.0'
63
+ - !ruby/object:Gem::Dependency
64
+ name: minitest
65
+ requirement: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '5.9'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 5.9.1
73
+ type: :development
74
+ prerelease: false
75
+ version_requirements: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '5.9'
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 5.9.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest-reporters
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.1'
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 1.1.12
93
+ type: :development
94
+ prerelease: false
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '1.1'
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 1.1.12
103
+ - !ruby/object:Gem::Dependency
104
+ name: rdoc
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '4.2'
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: 4.2.1
113
+ type: :development
114
+ prerelease: false
115
+ version_requirements: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: '4.2'
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: 4.2.1
123
+ - !ruby/object:Gem::Dependency
124
+ name: yard
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: '0.9'
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: 0.9.5
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: '0.9'
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: 0.9.5
143
+ - !ruby/object:Gem::Dependency
144
+ name: rest-client
145
+ requirement: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - "~>"
148
+ - !ruby/object:Gem::Version
149
+ version: '2.0'
150
+ type: :runtime
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - "~>"
155
+ - !ruby/object:Gem::Version
156
+ version: '2.0'
157
+ description: Interface to ComicVine API
158
+ email:
159
+ - holden.omans@gmail.com
160
+ executables: []
161
+ extensions: []
162
+ extra_rdoc_files: []
163
+ files:
164
+ - ".gitignore"
165
+ - ".rspec"
166
+ - ".travis.yml"
167
+ - Gemfile
168
+ - LICENSE.txt
169
+ - README.md
170
+ - Rakefile
171
+ - bin/console
172
+ - bin/setup
173
+ - certs/homans.pem
174
+ - checksum/comicvine-0.1.0.gem.sha512
175
+ - comicvine.gemspec
176
+ - lib/comicvine.rb
177
+ - lib/comicvine/list.rb
178
+ - lib/comicvine/modules.rb
179
+ - lib/comicvine/resource.rb
180
+ - lib/comicvine/version.rb
181
+ homepage: https://github.com/kalinon/ruby-comicvine-api
182
+ licenses:
183
+ - MIT
184
+ metadata: {}
185
+ post_install_message:
186
+ rdoc_options: []
187
+ require_paths:
188
+ - lib
189
+ required_ruby_version: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ required_rubygems_version: !ruby/object:Gem::Requirement
195
+ requirements:
196
+ - - ">="
197
+ - !ruby/object:Gem::Version
198
+ version: '0'
199
+ requirements: []
200
+ rubyforge_project:
201
+ rubygems_version: 2.5.1
202
+ signing_key:
203
+ specification_version: 4
204
+ summary: Api interface to ComicVine. Allows for searches and returning specific information
205
+ on resources.
206
+ test_files: []
Binary file