isbndb 1.5.3 → 1.5.4

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.
@@ -1 +1,3 @@
1
- Special thanks to Terje Tjervaag (https://github.com/terje) for giving up the gem name 'isbndb'!
1
+ Special thanks to Terje Tjervaag (https://github.com/terje) for giving up the gem name 'isbndb'!
2
+
3
+ Special thanks to Lazlo (https://github.com/lazlo) for forwarding his project here!
data/Gemfile CHANGED
@@ -1,11 +1,13 @@
1
1
  source "http://rubygems.org"
2
2
 
3
+ gem 'activesupport'
4
+ gem 'i18n'
3
5
  gem 'libxml-ruby', '>= 1.1.4'
4
6
 
5
7
  # Include everything needed to run rake, tests, features, etc.
6
8
  group :development do
7
9
  gem "shoulda", ">= 0"
8
- gem "bundler", "~> 1.0.0"
9
- gem "jeweler", "~> 1.5.2"
10
+ gem "bundler"
11
+ gem "jeweler"
10
12
  gem "rcov", ">= 0"
11
13
  end
@@ -1,7 +1,9 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
+ activesupport (3.0.5)
4
5
  git (1.2.5)
6
+ i18n (0.5.0)
5
7
  jeweler (1.5.2)
6
8
  bundler (~> 1.0.0)
7
9
  git (>= 1.2.5)
@@ -15,8 +17,10 @@ PLATFORMS
15
17
  ruby
16
18
 
17
19
  DEPENDENCIES
18
- bundler (~> 1.0.0)
19
- jeweler (~> 1.5.2)
20
+ activesupport
21
+ bundler
22
+ i18n
23
+ jeweler
20
24
  libxml-ruby (>= 1.1.4)
21
25
  rcov
22
26
  shoulda
data/Rakefile CHANGED
@@ -13,7 +13,7 @@ require 'jeweler'
13
13
  Jeweler::Tasks.new do |gem|
14
14
  # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
15
  gem.name = "isbndb"
16
- gem.homepage = "http://github.com/svargo/isbndb"
16
+ gem.homepage = "https://github.com/sethvargo/isbndb"
17
17
  gem.license = "MIT"
18
18
  gem.summary = "This gem provides an easy solution for connecting to ISBNdb.com's API"
19
19
  gem.description = "Ruby ISBNdb is a amazingly fast and accurate gem that reads ISBNdb.com's XML API and gives you incredible flexibilty with the results! The gem uses libxml-ruby, the fastest XML parser for Ruby, so you get blazing fast results every time. Additionally, the newest version of the gem also features caching, so developers minimize API-key usage."
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.5.3
1
+ 1.5.4
@@ -0,0 +1,77 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{isbndb}
8
+ s.version = "1.5.4"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Seth Vargo"]
12
+ s.date = %q{2011-04-21}
13
+ s.description = %q{Ruby ISBNdb is a amazingly fast and accurate gem that reads ISBNdb.com's XML API and gives you incredible flexibilty with the results! The gem uses libxml-ruby, the fastest XML parser for Ruby, so you get blazing fast results every time. Additionally, the newest version of the gem also features caching, so developers minimize API-key usage.}
14
+ s.email = %q{seth.vargo@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.markdown"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "ACKNOWLEDGEMENTS",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.markdown",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "isbndb.gemspec",
29
+ "lib/isbndb.rb",
30
+ "lib/isbndb/access_key_set.rb",
31
+ "lib/isbndb/exceptions.rb",
32
+ "lib/isbndb/result.rb",
33
+ "lib/isbndb/result_set.rb",
34
+ "test/helper.rb",
35
+ "test/test_isbndb.rb"
36
+ ]
37
+ s.homepage = %q{https://github.com/sethvargo/isbndb}
38
+ s.licenses = ["MIT"]
39
+ s.require_paths = ["lib"]
40
+ s.rubygems_version = %q{1.7.2}
41
+ s.summary = %q{This gem provides an easy solution for connecting to ISBNdb.com's API}
42
+ s.test_files = [
43
+ "test/helper.rb",
44
+ "test/test_isbndb.rb"
45
+ ]
46
+
47
+ if s.respond_to? :specification_version then
48
+ s.specification_version = 3
49
+
50
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
+ s.add_runtime_dependency(%q<activesupport>, [">= 0"])
52
+ s.add_runtime_dependency(%q<i18n>, [">= 0"])
53
+ s.add_runtime_dependency(%q<libxml-ruby>, [">= 1.1.4"])
54
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
55
+ s.add_development_dependency(%q<bundler>, [">= 0"])
56
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
57
+ s.add_development_dependency(%q<rcov>, [">= 0"])
58
+ else
59
+ s.add_dependency(%q<activesupport>, [">= 0"])
60
+ s.add_dependency(%q<i18n>, [">= 0"])
61
+ s.add_dependency(%q<libxml-ruby>, [">= 1.1.4"])
62
+ s.add_dependency(%q<shoulda>, [">= 0"])
63
+ s.add_dependency(%q<bundler>, [">= 0"])
64
+ s.add_dependency(%q<jeweler>, [">= 0"])
65
+ s.add_dependency(%q<rcov>, [">= 0"])
66
+ end
67
+ else
68
+ s.add_dependency(%q<activesupport>, [">= 0"])
69
+ s.add_dependency(%q<i18n>, [">= 0"])
70
+ s.add_dependency(%q<libxml-ruby>, [">= 1.1.4"])
71
+ s.add_dependency(%q<shoulda>, [">= 0"])
72
+ s.add_dependency(%q<bundler>, [">= 0"])
73
+ s.add_dependency(%q<jeweler>, [">= 0"])
74
+ s.add_dependency(%q<rcov>, [">= 0"])
75
+ end
76
+ end
77
+
@@ -1,5 +1,6 @@
1
1
  # require dependencies
2
2
  require 'libxml'
3
+ require 'active_support/inflector'
3
4
 
4
5
  # private sub-classes
5
6
  require 'isbndb/access_key_set'
@@ -62,7 +63,7 @@ module ISBNdb
62
63
 
63
64
  if m.match(/find_(.+)_by_(.+)/)
64
65
  split = m.split('_', 4)
65
- collection, search_strs = pluralize(split[1].downcase), [split.last]
66
+ collection, search_strs = split[1].downcase.pluralize, [split.last]
66
67
 
67
68
  # check and see if we are searching multiple fields
68
69
  search_strs = search_strs.first.split('_and_') if(search_strs.first.match(/_and_/))
@@ -91,7 +92,7 @@ module ISBNdb
91
92
  def make_request(collection, results, searches)
92
93
  begin
93
94
  uri = "#{BASE_URL}/#{collection}.xml?access_key=#{@access_key_set.current_key}&results=#{results.join(',')}&#{searches.join('&')}"
94
- ISBNdb::ResultSet.new(uri, singularize(collection).capitalize)
95
+ ISBNdb::ResultSet.new(uri, collection.singularize.capitalize)
95
96
  rescue ISBNdb::AccessKeyError
96
97
  puts "Access Key Error (#{@access_key_set.current_key}) - You probably reached your limit! Trying the next key."
97
98
  @access_key_set.next_key!
@@ -99,17 +100,17 @@ module ISBNdb
99
100
  raise ISBNdb::AccessKeyError
100
101
  end
101
102
  end
102
-
103
- def pluralize(str)
104
- return 'categories' if str == 'category'
105
- return "#{str}s" unless str.split(//).last == 's'
106
- str
107
- end
108
-
109
- def singularize(str)
110
- return 'category' if str == 'categories'
111
- return str[0, str.length-1] if str.split(//).last == 's'
112
- str
113
- end
103
+ end
104
+ end
105
+
106
+
107
+ # Add a few methods to the String class
108
+ class String
109
+ def is_plural?
110
+ self.downcase.pluralize == self.downcase
111
+ end
112
+
113
+ def is_singular?
114
+ !self.is_plural?
114
115
  end
115
116
  end
@@ -23,7 +23,8 @@ module ISBNdb
23
23
  # Pretty preint the Result including the number of singleton methods that exist. If
24
24
  # you want the ACTUAL singleton methods, call @result.singleton_methods.
25
25
  def to_s
26
- "#<Result @singleton_methods=#{@singleton_methods.size}>"
26
+ @singleton_methods ||= []
27
+ "#<Result @num_singleton_methods=#{@singleton_methods.size}>"
27
28
  end
28
29
 
29
30
  private
@@ -32,26 +33,21 @@ module ISBNdb
32
33
  # or content's value. Not to be outdone, it recursively iterates over all children too!
33
34
  def build_result(top_node)
34
35
  top_node.attributes.each do |attribute|
35
- singleton.send(:define_method, formatted_method_name(attribute.name)) { attribute.value } unless attribute.value.strip.empty?
36
+ singleton.send(:define_method, method_name(attribute.name)) { attribute.value } unless attribute.value.strip.empty?
36
37
  end
37
38
 
38
39
  if top_node.children?
39
40
  top_node.children.each { |child| build_result(child) }
40
41
  else
41
- singleton.send(:define_method, formatted_method_name(top_node.parent.name)) { top_node.content.strip.chomp(',') } unless top_node.content.strip.empty?
42
+ singleton.send(:define_method, method_name(top_node.parent.name)) { top_node.content.strip.chomp(',') } unless top_node.content.strip.empty?
42
43
  end
43
44
  end
44
45
 
45
46
  # This helper function reduces code redundancy and maintains consistency by formatting
46
47
  # all method names the same. All method names are stripped of any trailing whitespaces,
47
48
  # converted from CamelCase to under_score, and converted to a symbol
48
- def formatted_method_name(name)
49
- camel_to_underscore(name.strip).to_sym
50
- end
51
-
52
- # This helper function converts CamelCase to under_score using a nice little regex :).
53
- def camel_to_underscore(str)
54
- str.gsub(/(.)([A-Z])/,'\1_\2').downcase
49
+ def method_name(name)
50
+ name.strip.underscore.to_sym
55
51
  end
56
52
 
57
53
  # We need a singleton reference to the current _instance_ so that we can dynamically define
@@ -6,58 +6,65 @@ class TestISBNdb < Test::Unit::TestCase
6
6
  @query = ISBNdb::Query.new('KXWFXJIK')
7
7
  end
8
8
 
9
- should "fetch a book by ISBN" do
10
- @book = @query.find_book_by_isbn('1934356549').first
11
- assert_equal '1934356549', @book.isbn
12
- end
13
-
14
- should "fetch a book by ISBN13" do
15
- @book = @query.find_book_by_isbn('9781934356548').first
16
- assert_equal '9781934356548', @book.isbn13
17
- end
9
+ # should "fetch a book by ISBN" do
10
+ # @book = @query.find_book_by_isbn('1934356549').first
11
+ # assert_equal '1934356549', @book.isbn
12
+ # end
13
+ #
14
+ # should "fetch a book by ISBN13" do
15
+ # @book = @query.find_book_by_isbn('9781934356548').first
16
+ # assert_equal '9781934356548', @book.isbn13
17
+ # end
18
+ #
19
+ # should 'fetch books by title' do
20
+ # @books = @query.find_books_by_title('ruby')
21
+ # @books.each do |book|
22
+ # assert (book.title || "").downcase.include?('ruby') || (book.title_long || "").downcase.include?('ruby'), "#{book.title} did not contain 'ruby'"
23
+ # end
24
+ # end
25
+ #
26
+ # should 'get next_page and prev_page' do
27
+ # @books = @query.find_books_by_title('ruby')
28
+ # next_page = @books.next_page
29
+ # assert_equal @books.first.title, next_page.prev_page.first.title, 'Failed to get next_page'
30
+ # end
31
+ #
32
+ # should 'get keystats' do
33
+ # assert @query.keystats.is_a?(Hash), "#{@query.keystats} was not a Hash"
34
+ # assert @query.keystats[:requests] >= @query.keystats[:granted], "Number of requests (#{@query.keystats[:requests]}) was not greater than number of granted requests (#{@query.keystats[:granted]})"
35
+ # assert @query.keystats[:requests] > 0 && @query.keystats[:requests] < 500, 'Requests were not between 0 and 500'
36
+ # end
37
+ #
38
+ # should 'test access_key_set' do
39
+ # @query = ISBNdb::Query.new(['API-KEY-1', 'API-KEY-2', 'API-KEY-3'])
40
+ # @access_key_set = @query.access_key_set
41
+ # assert_equal 'API-KEY-1', @access_key_set.current_key
42
+ # assert_equal 'API-KEY-2', @access_key_set.next_key
43
+ # @access_key_set.next_key!
44
+ # assert_equal 'API-KEY-1', @access_key_set.prev_key
45
+ # @access_key_set.use_key('A-NEW-KEY')
46
+ # assert_equal 'A-NEW-KEY', @access_key_set.current_key
47
+ # @access_key_set.use_key('API-KEY-3')
48
+ # assert_equal 'API-KEY-3', @access_key_set.current_key
49
+ # end
50
+ #
51
+ # should 'raise exception for an invalid access key' do
52
+ # @invalid = ISBNdb::Query.new(['abc123foobar', '123anotherinvalidkey'])
53
+ # assert_raise ISBNdb::AccessKeyError, "#{@invalid} did not raise AccessKeyError" do
54
+ # @invalid.find_book_by_isbn('1934356549')
55
+ # end
56
+ # end
57
+ #
58
+ # should 'raise exception for an invalid uri' do
59
+ # assert_raise ISBNdb::InvalidURIError, "@query.find_invalid_by_unknown did not raise InvalidURIError" do
60
+ # @query.find_invalid_by_unknown('foobar')
61
+ # end
62
+ # end
18
63
 
19
- should 'fetch books by title' do
20
- @books = @query.find_books_by_title('ruby')
64
+ should 'make sub-result sets' do
65
+ @books = @query.find(:collection => 'books', :where => { :title => 'vargo' }, :results => 'prices')
21
66
  @books.each do |book|
22
- assert (book.title || "").downcase.include?('ruby') || (book.title_long || "").downcase.include?('ruby'), "#{book.title} did not contain 'ruby'"
23
- end
24
- end
25
-
26
- should 'get next_page and prev_page' do
27
- @books = @query.find_books_by_title('ruby')
28
- next_page = @books.next_page
29
- assert_equal @books.first.title, next_page.prev_page.first.title, 'Failed to get next_page'
30
- end
31
-
32
- should 'get keystats' do
33
- assert @query.keystats.is_a?(Hash), "#{@query.keystats} was not a Hash"
34
- assert @query.keystats[:requests] >= @query.keystats[:granted], "Number of requests (#{@query.keystats[:requests]}) was not greater than number of granted requests (#{@query.keystats[:granted]})"
35
- assert @query.keystats[:requests] > 0 && @query.keystats[:requests] < 500, 'Requests were not between 0 and 500'
36
- end
37
-
38
- should 'test access_key_set' do
39
- @query = ISBNdb::Query.new(['API-KEY-1', 'API-KEY-2', 'API-KEY-3'])
40
- @access_key_set = @query.access_key_set
41
- assert_equal 'API-KEY-1', @access_key_set.current_key
42
- assert_equal 'API-KEY-2', @access_key_set.next_key
43
- @access_key_set.next_key!
44
- assert_equal 'API-KEY-1', @access_key_set.prev_key
45
- @access_key_set.use_key('A-NEW-KEY')
46
- assert_equal 'A-NEW-KEY', @access_key_set.current_key
47
- @access_key_set.use_key('API-KEY-3')
48
- assert_equal 'API-KEY-3', @access_key_set.current_key
49
- end
50
-
51
- should 'raise exception for an invalid access key' do
52
- @invalid = ISBNdb::Query.new(['abc123foobar', '123anotherinvalidkey'])
53
- assert_raise ISBNdb::AccessKeyError, "#{@invalid} did not raise AccessKeyError" do
54
- @invalid.find_book_by_isbn('1934356549')
55
- end
56
- end
57
-
58
- should 'raise exception for an invalid uri' do
59
- assert_raise ISBNdb::InvalidURIError, "@query.find_invalid_by_unknown did not raise InvalidURIError" do
60
- @query.find_invalid_by_unknown('foobar')
67
+ #puts book
61
68
  end
62
69
  end
63
70
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: isbndb
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.5.3
5
+ version: 1.5.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Seth Vargo
@@ -10,55 +10,54 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-11 00:00:00 -05:00
14
- default_executable:
13
+ date: 2011-04-21 00:00:00 Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
- name: libxml-ruby
16
+ name: activesupport
18
17
  requirement: &id001 !ruby/object:Gem::Requirement
19
18
  none: false
20
19
  requirements:
21
20
  - - ">="
22
21
  - !ruby/object:Gem::Version
23
- version: 1.1.4
22
+ version: "0"
24
23
  type: :runtime
25
24
  prerelease: false
26
25
  version_requirements: *id001
27
26
  - !ruby/object:Gem::Dependency
28
- name: shoulda
27
+ name: i18n
29
28
  requirement: &id002 !ruby/object:Gem::Requirement
30
29
  none: false
31
30
  requirements:
32
31
  - - ">="
33
32
  - !ruby/object:Gem::Version
34
33
  version: "0"
35
- type: :development
34
+ type: :runtime
36
35
  prerelease: false
37
36
  version_requirements: *id002
38
37
  - !ruby/object:Gem::Dependency
39
- name: bundler
38
+ name: libxml-ruby
40
39
  requirement: &id003 !ruby/object:Gem::Requirement
41
40
  none: false
42
41
  requirements:
43
- - - ~>
42
+ - - ">="
44
43
  - !ruby/object:Gem::Version
45
- version: 1.0.0
46
- type: :development
44
+ version: 1.1.4
45
+ type: :runtime
47
46
  prerelease: false
48
47
  version_requirements: *id003
49
48
  - !ruby/object:Gem::Dependency
50
- name: jeweler
49
+ name: shoulda
51
50
  requirement: &id004 !ruby/object:Gem::Requirement
52
51
  none: false
53
52
  requirements:
54
- - - ~>
53
+ - - ">="
55
54
  - !ruby/object:Gem::Version
56
- version: 1.5.2
55
+ version: "0"
57
56
  type: :development
58
57
  prerelease: false
59
58
  version_requirements: *id004
60
59
  - !ruby/object:Gem::Dependency
61
- name: rcov
60
+ name: bundler
62
61
  requirement: &id005 !ruby/object:Gem::Requirement
63
62
  none: false
64
63
  requirements:
@@ -68,6 +67,28 @@ dependencies:
68
67
  type: :development
69
68
  prerelease: false
70
69
  version_requirements: *id005
70
+ - !ruby/object:Gem::Dependency
71
+ name: jeweler
72
+ requirement: &id006 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: *id006
81
+ - !ruby/object:Gem::Dependency
82
+ name: rcov
83
+ requirement: &id007 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: "0"
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: *id007
71
92
  description: Ruby ISBNdb is a amazingly fast and accurate gem that reads ISBNdb.com's XML API and gives you incredible flexibilty with the results! The gem uses libxml-ruby, the fastest XML parser for Ruby, so you get blazing fast results every time. Additionally, the newest version of the gem also features caching, so developers minimize API-key usage.
72
93
  email: seth.vargo@gmail.com
73
94
  executables: []
@@ -86,6 +107,7 @@ files:
86
107
  - README.markdown
87
108
  - Rakefile
88
109
  - VERSION
110
+ - isbndb.gemspec
89
111
  - lib/isbndb.rb
90
112
  - lib/isbndb/access_key_set.rb
91
113
  - lib/isbndb/exceptions.rb
@@ -93,8 +115,7 @@ files:
93
115
  - lib/isbndb/result_set.rb
94
116
  - test/helper.rb
95
117
  - test/test_isbndb.rb
96
- has_rdoc: true
97
- homepage: http://github.com/svargo/isbndb
118
+ homepage: https://github.com/sethvargo/isbndb
98
119
  licenses:
99
120
  - MIT
100
121
  post_install_message:
@@ -107,7 +128,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
107
128
  requirements:
108
129
  - - ">="
109
130
  - !ruby/object:Gem::Version
110
- hash: -3720609337190641477
131
+ hash: 4519594731805575555
111
132
  segments:
112
133
  - 0
113
134
  version: "0"
@@ -120,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
141
  requirements: []
121
142
 
122
143
  rubyforge_project:
123
- rubygems_version: 1.6.1
144
+ rubygems_version: 1.7.2
124
145
  signing_key:
125
146
  specification_version: 3
126
147
  summary: This gem provides an easy solution for connecting to ISBNdb.com's API