comic_vine 0.0.5 → 0.0.6

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/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/README.md CHANGED
@@ -61,9 +61,13 @@ video_types
61
61
  volumes
62
62
 
63
63
 
64
- Calls to plurals return a CVObjectList:
64
+ Calls to plurals return a CVObjectList, which contains the result array as well as the values from the return (total_count, offset, limit, resource).
65
65
 
66
66
  chars = ComicVine::API.characters
67
+
68
+ CVObjectLists include enumerable, so they can be looped.
69
+
70
+ chars.each do |c|
67
71
 
68
72
  Pagination will return nil if you are at either end of the list, otherwise it will update the object allowing for looping
69
73
 
@@ -86,10 +90,11 @@ Pass in options as a hash
86
90
 
87
91
  ComicVine::API.characters {:limit=>5, :offset=>10}
88
92
 
89
- There are limited associations. If the name of the association matches the resource name, then you can get the array of CVObjects by calling get_[resource]
93
+ There are associations. Call the association by the key name, prefaced by get_ and the gem will return either a CVList or a CVObject from the API.
90
94
 
91
95
  volume = ComicVine::API.volume 766
92
96
  issues = volume.get_issues
97
+ chars = volume.get_character_credits
93
98
 
94
99
  Error responses from the API will raise a CVError with the error message
95
100
 
data/Rakefile CHANGED
@@ -1,2 +1,8 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new('spec')
7
+
8
+ task :default => :spec
data/changelog CHANGED
@@ -1,3 +1,5 @@
1
+ 0.0.6 - Expose the helper methods, add get_details_by_url, allow get_* for ANY of the resource items returned in the body
2
+
1
3
  0.0.5 - Behind the scenes cleanup. Change gem to work as a pure ruby implementation. API.key is now manually set as opposed to reading from a config file. Removed generator and railties.
2
4
 
3
5
  0.0.4 - Add CVObjectList to carry count vars from result. Add simple pagination. Include enumerable in the list classes
data/comic_vine.gemspec CHANGED
@@ -16,4 +16,5 @@ Gem::Specification.new do |gem|
16
16
  gem.version = ComicVine::VERSION
17
17
 
18
18
  gem.add_dependency 'json'
19
+ gem.add_development_dependency "rspec", ">= 2.0.0"
19
20
  end
@@ -11,15 +11,16 @@ module ComicVine
11
11
  if method_sym.to_s =~ /^get_(.*)$/
12
12
  key = method_sym.to_s.sub "get_", ""
13
13
  if instance_variable_defined?("@#{key}")
14
- if type = ComicVine::API.find_list(key)
14
+ item = instance_variable_get("@#{key}")
15
+ if item.kind_of?(Array) && item.first.key?("api_detail_url")
15
16
  res = []
16
- send(key).each do |i|
17
- res << ComicVine::API.send(type['detail_resource_name'], i['id'])
17
+ item.each do |i|
18
+ res << ComicVine::API.get_details_by_url(i["api_detail_url"])
18
19
  end
19
20
  return res
20
21
  end
21
- if ComicVine::API.find_detail(key)
22
- return ComicVine::API.send(key, send(key)['id'])
22
+ if item.kind_of?(Hash) && item.key?("api_detail_url")
23
+ return ComicVine::API.get_details_by_url(item["api_detail_url"])
23
24
  end
24
25
  else
25
26
  super
@@ -1,3 +1,3 @@
1
1
  module ComicVine
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
data/lib/comic_vine.rb CHANGED
@@ -15,78 +15,86 @@ module ComicVine
15
15
 
16
16
  @@API_BASE_URL = "http://api.comicvine.com/"
17
17
 
18
- def self.search res, query, opts={}
19
- resp = hit_api(build_url("search", opts)+"&resources=#{res}&query=#{query}")
20
- ComicVine::CVSearchList.new(resp, res, query)
21
- end
18
+ class << self
19
+ def search res, query, opts={}
20
+ resp = hit_api(build_url("search", opts)+"&resources=#{res}&query=#{query}")
21
+ ComicVine::CVSearchList.new(resp, res, query)
22
+ end
22
23
 
23
- def self.find_list type
24
- types.find { |t| t['list_resource_name'] == type }
25
- end
24
+ def find_list type
25
+ types.find { |t| t['list_resource_name'] == type }
26
+ end
26
27
 
27
- def self.find_detail type
28
- types.find { |t| t['detail_resource_name'] == type }
29
- end
28
+ def find_detail type
29
+ types.find { |t| t['detail_resource_name'] == type }
30
+ end
30
31
 
31
- def self.method_missing(method_sym, *arguments, &block)
32
- if find_list(method_sym.to_s)
33
- get_list method_sym.to_s, arguments.first
34
- elsif find_detail(method_sym.to_s)
35
- get_details method_sym.to_s, *arguments
36
- elsif
37
- super
32
+ def method_missing(method_sym, *arguments, &block)
33
+ if find_list(method_sym.to_s)
34
+ get_list method_sym.to_s, arguments.first
35
+ elsif find_detail(method_sym.to_s)
36
+ get_details method_sym.to_s, *arguments
37
+ elsif
38
+ super
39
+ end
38
40
  end
39
- end
40
41
 
41
- def self.key
42
- @@key
43
- end
42
+ def key
43
+ @@key
44
+ end
44
45
 
45
- def self.key= key
46
- @@key = key
47
- end
46
+ def key= key
47
+ @@key = key
48
+ end
48
49
 
49
- def self.types
50
- if @@types.nil? || (@@last_type_check + (4 *60 *60)) > Time.now
51
- @@last_type_check = Time.now
52
- @@types = hit_api(build_url('types'))['results']
50
+ def types
51
+ if @@types.nil? || (@@last_type_check + (4 *60 *60)) > Time.now
52
+ @@last_type_check = Time.now
53
+ @@types = hit_api(build_base_url('types'))['results']
54
+ end
55
+ @@types
56
+ end
57
+
58
+ def get_list list_type, opts=nil
59
+ resp = hit_api(build_base_url(list_type), build_query(opts))
60
+ ComicVine::CVObjectList.new(resp, list_type)
53
61
  end
54
- @@types
55
- end
56
62
 
57
- def self.get_list list_type, opts=nil
58
- resp = hit_api(build_url(list_type, opts))
59
- ComicVine::CVObjectList.new(resp, list_type)
60
- end
61
-
62
- def self.get_details item_type, id, opts=nil
63
- resp = hit_api(build_url("#{item_type}/#{id}", opts))
64
- ComicVine::CVObject.new(resp['results'])
65
- end
66
-
67
- def self.hit_api url
68
- uri = URI.parse(url)
69
- resp = Net::HTTP.get(uri)
70
- presp = JSON.parse(resp)
71
- raise CVError, presp['error'] unless presp['status_code'] == 1
72
- presp
73
- end
63
+ def get_details item_type, id, opts=nil
64
+ resp = hit_api(build_base_url("#{item_type}/#{id}"), build_query(opts))
65
+ ComicVine::CVObject.new(resp['results'])
66
+ end
67
+
68
+ def get_details_by_url url
69
+ resp = hit_api(url)
70
+ ComicVine::CVObject.new(resp['results'])
71
+ end
74
72
 
75
- def self.build_url action, opts=nil
76
- query = ''
77
- if !opts.nil? && !opts.empty?
78
- opts.each do |k,v|
79
- query << "&#{k.to_s}=#{v}"
73
+ private
74
+ def hit_api base_url, query=""
75
+ url = base_url<<"?format=json&api_key=#{@@key}"<<query
76
+ uri = URI.parse(url)
77
+ resp = Net::HTTP.get(uri)
78
+ presp = JSON.parse(resp)
79
+ raise CVError, presp['error'] unless presp['status_code'] == 1
80
+ presp
81
+ end
82
+
83
+ def build_base_url action
84
+ @@API_BASE_URL+action+"/"
85
+ end
86
+
87
+ def build_query opts=nil
88
+ query = ''
89
+ if !opts.nil? && !opts.empty?
90
+ opts.each do |k,v|
91
+ query << "&#{k.to_s}=#{v}"
92
+ end
93
+ end
94
+ query
80
95
  end
81
- end
82
- @@API_BASE_URL+action+"/?format=json&api_key=#{@@key}#{query}"
83
- end
84
96
 
85
- private_class_method :types
86
- private_class_method :get_list
87
- private_class_method :get_details
88
- private_class_method :hit_api
89
- private_class_method :build_url
97
+ end
90
98
  end
91
99
  end
92
100
 
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+ describe ComicVine do
3
+ it "should allow the user to set the API key" do
4
+ ComicVine::API.key = "some_api_key"
5
+ ComicVine::API.key.should == "some_api_key"
6
+ end
7
+
8
+ it "should raise a ComicVine::CVError on an API call without the key set" do
9
+ expect{ ComicVine::API.issues }.to raise_error(ComicVine::CVError)
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+ describe ComicVine::CVObject do
3
+ it "should inialize instance variables from a hash" do
4
+ h = {'something' => 'something', 'blah' => 'blah', 'number' => 100}
5
+ cvo = ComicVine::CVObject.new h
6
+ cvo.something.should == 'something'
7
+ cvo.blah.should == 'blah'
8
+ cvo.number.should == 100
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper.rb"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+
8
+ require 'comic_vine'
9
+
10
+ RSpec.configure do |config|
11
+ config.treat_symbols_as_metadata_keys_with_true_values = true
12
+ config.run_all_when_everything_filtered = true
13
+ config.filter_run :focus
14
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comic_vine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-12 00:00:00.000000000Z
12
+ date: 2012-04-18 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &70119669944600 !ruby/object:Gem::Requirement
16
+ requirement: &70331646007340 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,18 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70119669944600
24
+ version_requirements: *70331646007340
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70331646006800 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 2.0.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70331646006800
25
36
  description: Simple api interface to Comic Vine. Allows for searches and returning
26
37
  specific information on resources.
27
38
  email: jakanapes@gmail.com
@@ -30,6 +41,7 @@ extensions: []
30
41
  extra_rdoc_files: []
31
42
  files:
32
43
  - .gitignore
44
+ - .rspec
33
45
  - Gemfile
34
46
  - LICENSE
35
47
  - README.md
@@ -40,6 +52,9 @@ files:
40
52
  - lib/comic_vine/cv_list.rb
41
53
  - lib/comic_vine/cv_object.rb
42
54
  - lib/comic_vine/version.rb
55
+ - spec/comic_vine_spec.rb
56
+ - spec/cv_object_spec.rb
57
+ - spec/spec_helper.rb
43
58
  homepage: https://github.com/Jakanapes/ComicVine
44
59
  licenses: []
45
60
  post_install_message:
@@ -64,4 +79,7 @@ rubygems_version: 1.8.10
64
79
  signing_key:
65
80
  specification_version: 3
66
81
  summary: Interface to ComicVine API
67
- test_files: []
82
+ test_files:
83
+ - spec/comic_vine_spec.rb
84
+ - spec/cv_object_spec.rb
85
+ - spec/spec_helper.rb