comic_vine 0.0.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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in comic_vine.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 TODO: Write your name
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,97 @@
1
+ # ComicVine
2
+
3
+ VERY simple first cut at a gem to interface with the ComicVine api. http://api.comicvine.com/
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'comic_vine'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install comic_vine
18
+
19
+ You will also need to have a ComicVine API key.
20
+
21
+ After installing gem run the generator
22
+
23
+ rails g comic_vine:install
24
+
25
+ This will install a keyfile at config/cv_key.yml. Update this file with your own API key.
26
+
27
+ The generator also installs an initializer to capture the api key in a class variable for ComicVine::API
28
+
29
+ ## Usage
30
+
31
+ works on a subset of the api actions
32
+
33
+ characters
34
+
35
+ chats
36
+
37
+ concepts
38
+
39
+ issues
40
+
41
+ locations
42
+
43
+ movies
44
+
45
+ objects
46
+
47
+ origins
48
+
49
+ persons
50
+
51
+ powers
52
+
53
+ promos
54
+
55
+ publishers
56
+
57
+ story_arcs
58
+
59
+ teams
60
+
61
+ videos
62
+
63
+ video_types
64
+
65
+ volumes
66
+
67
+
68
+ Calls to plurals return arrays of CVObjects:
69
+
70
+ ComicVine::API.characters
71
+
72
+ Calls to singulars require an id and return a CVObject:
73
+
74
+ ComicVine::API.volume 766
75
+
76
+ Search takes a resource type and a query string and returns an array of CVObjects
77
+
78
+ ComicVine::API.search 'volume', 'batman'
79
+
80
+ ## ToDos
81
+ Limits and Offsets
82
+
83
+ Filtering
84
+
85
+ Error checking
86
+
87
+ Documentation
88
+
89
+ Tests
90
+
91
+ ## Contributing
92
+
93
+ 1. Fork it
94
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
95
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
96
+ 4. Push to the branch (`git push origin my-new-feature`)
97
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/comic_vine/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = "Patrick Sharp"
6
+ gem.email = "jakanapes@gmail.com"
7
+ gem.description = %q{Simple api interface to Comic Vine. Allows for searches and returning specific information on resources.}
8
+ gem.summary = %q{Interface to ComicVine API}
9
+ gem.homepage = ""
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "comic_vine"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = ComicVine::VERSION
17
+
18
+ gem.add_dependency 'json'
19
+ end
@@ -0,0 +1,3 @@
1
+ module ComicVine
2
+ VERSION = "0.0.1"
3
+ end
data/lib/comic_vine.rb ADDED
@@ -0,0 +1,75 @@
1
+ require "comic_vine/version"
2
+ require "net/http"
3
+
4
+ module ComicVine
5
+ class CVObject
6
+ def initialize(args)
7
+ args.each do |k,v|
8
+ class_eval { attr_accessor k }
9
+ instance_variable_set "@#{k}", v
10
+ end
11
+ end
12
+ end
13
+
14
+ class API
15
+ cattr_accessor :key
16
+
17
+ API_BASE_URL = "http://api.comicvine.com/"
18
+
19
+ LIST_ACTIONS = [ :characters,
20
+ :chats,
21
+ :concepts,
22
+ :issues,
23
+ :locations,
24
+ :movies,
25
+ :objects,
26
+ :origins,
27
+ :persons,
28
+ :powers,
29
+ :promos,
30
+ :publishers,
31
+ :story_arcs,
32
+ :teams,
33
+ :videos,
34
+ :video_types,
35
+ :volumes ].freeze
36
+
37
+ def self.search res, query
38
+ hit_api(build_url("search")+"&resources=#{res}&query=#{query}")
39
+ end
40
+
41
+ def self.method_missing(method_sym, *arguments, &block)
42
+ if LIST_ACTIONS.include?(method_sym)
43
+ self.get_list method_sym.to_s
44
+ elsif LIST_ACTIONS.include?(method_sym.to_s.pluralize.to_sym)
45
+ self.get_item method_sym, arguments.first
46
+ elsif
47
+ super
48
+ end
49
+ end
50
+
51
+ private
52
+ def self.get_list list_type
53
+ hit_api(build_url(list_type))
54
+ end
55
+
56
+ def self.get_item item_type, id
57
+ hit_api(build_url("#{item_type}/#{id}"))
58
+ end
59
+
60
+ def self.hit_api url
61
+ url = URI.parse(url)
62
+ resp = Net::HTTP.get(url)
63
+ presp = JSON.parse(resp)
64
+ if presp['results'].kind_of?(Array)
65
+ presp['results'].map{ |r| ComicVine::CVObject.new(r)}
66
+ else
67
+ ComicVine::CVObject.new(presp['results'])
68
+ end
69
+ end
70
+
71
+ def self.build_url action
72
+ API_BASE_URL+action+"/?api_key=#{@@key}&format=json"
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,17 @@
1
+ module ComicVine
2
+ module Generators
3
+ class InstallGenerator < ::Rails::Generators::Base
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ desc "This generator installs the blank keyfile for ComicVine and copies the initializer"
7
+ def copy_the_keyfile
8
+ copy_file "cv_key.yml", "config/cv_key.yml"
9
+ end
10
+
11
+ def copy_the_init
12
+ copy_file "initializer.rb", "config/initializers/comic_vine.rb"
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,2 @@
1
+ # Add your ComicVine API key here
2
+ cvkey: XXXXXX
@@ -0,0 +1,5 @@
1
+
2
+
3
+ keyfile = YAML::load(File.open(Rails.root.join('config', 'cv_key.yml')))
4
+
5
+ ComicVine::API.key = keyfile['cvkey']
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: comic_vine
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Patrick Sharp
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-09 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: &70163194218340 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70163194218340
25
+ description: Simple api interface to Comic Vine. Allows for searches and returning
26
+ specific information on resources.
27
+ email: jakanapes@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - comic_vine.gemspec
38
+ - lib/comic_vine.rb
39
+ - lib/comic_vine/version.rb
40
+ - lib/generators/comic_vine/install/install_generator.rb
41
+ - lib/generators/comic_vine/install/templates/cv_key.yml
42
+ - lib/generators/comic_vine/install/templates/initializer.rb
43
+ homepage: ''
44
+ licenses: []
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 1.8.10
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: Interface to ComicVine API
67
+ test_files: []