yelp 2.0.0 → 2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 084eed60efb387e4e9ff29a1efaa55b9a956ac6d
4
- data.tar.gz: cd0c27b10455857f1ec7a8eb252a3f2bea5c7a99
3
+ metadata.gz: 710d6c122e7ae066c91a091792306a3750d7b2ac
4
+ data.tar.gz: 2d11f7b9635da6bc2bff6225f15f53e3f9104fbe
5
5
  SHA512:
6
- metadata.gz: 37dd0feece6d826fb97373c91f6765a019dab1724a4ba8df88856a0d0d1a405e8a4e793280dfa68f07edf3df2ea418c679fc5cff1f5ab6a950643c73e8528bd4
7
- data.tar.gz: 8a5895e8cc5c19e248b4e286490e3c6a6aac080c73e155d7806199cab48d7b05f50a6504635db0be8acbbb68e0500a46b316bc41a2dbd0cc062de774ade296dd
6
+ metadata.gz: 34b6db5b4727c5352c0a94d24b190463b05e810c364863144955b6de97a8405fa4cf2c1021d0bb2f481112accb5302bc9a25a7f39250cd2aa5d97676bce8f9a8
7
+ data.tar.gz: 3ca2121ebc48b5c19352654828e39ee66c032e4a9bc5d931147aeb722a163bafe6ca6780162a858d5573c32044f8ab6d642003f414ea1ec4ca858e2c8be585a3
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - 1.9.2
6
+ env:
7
+ - YELP_CONSUMER_KEY='abcdefg' YELP_CONSUMER_SECRET='hijklmn' YELP_TOKEN='12345' YELP_TOKEN_SECRET='67890'
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # yelp-ruby
2
2
 
3
- This is a Ruby Gem for the Yelp API. It'll simplifies the process of consuming data from the Yelp API for developers using Ruby. The library encompasses both Search and Business API functions.
3
+ [![Gem Version](https://badge.fury.io/rb/yelp.svg)](http://badge.fury.io/rb/yelp) [![Build Status](https://travis-ci.org/Yelp/yelp-ruby.svg)](https://travis-ci.org/Yelp/yelp-ruby) [![Code Climate](https://codeclimate.com/github/Yelp/yelp-ruby.png)](https://codeclimate.com/github/Yelp/yelp-ruby)
4
+
5
+ This is a Ruby Gem for the Yelp API. It'll simplify the process of consuming data from the Yelp API for developers using Ruby. The library encompasses both Search and Business API functions.
4
6
 
5
7
  Please remember to read and follow the [Terms of Use](http://www.yelp.com/developers/getting_started/api_terms) and [display requirements](http://www.yelp.com/developers/getting_started/display_requirements) before creating your applications.
6
8
 
data/Rakefile CHANGED
@@ -1,5 +1,12 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
2
3
 
3
4
  Dir["tasks/**/*.rake"].each do |file|
4
5
  load(file)
5
- end
6
+ end
7
+
8
+ # Setup new RSpec for rake task
9
+ RSpec::Core::RakeTask.new(:spec)
10
+
11
+ # make default task to run specs
12
+ task :default => :spec
data/lib/yelp/client.rb CHANGED
@@ -40,7 +40,7 @@ module Yelp
40
40
  # config.token_secret = 'jkl'
41
41
  # end
42
42
  def configure
43
- raise AlreadyConfigured unless @configuration.nil?
43
+ raise Error::AlreadyConfigured unless @configuration.nil?
44
44
 
45
45
  @configuration = Configuration.new
46
46
  yield(@configuration)
@@ -51,7 +51,7 @@ module Yelp
51
51
  def check_api_keys
52
52
  if configuration.nil? || !configuration.valid?
53
53
  @configuration = nil
54
- raise MissingAPIKeys
54
+ raise Error::MissingAPIKeys
55
55
  else
56
56
  # Freeze the configuration so it cannot be modified once the gem is
57
57
  # configured. This prevents the configuration changing while the gem
@@ -83,7 +83,8 @@ module Yelp
83
83
  #
84
84
  # response = client.search(bounding_box, params)
85
85
  def search_by_bounding_box(bounding_box, params = {}, locale = {})
86
- raise BoundingBoxNotComplete if BOUNDING_BOX.any? { |corner| bounding_box[corner].nil? }
86
+ raise Error::BoundingBoxNotComplete if BOUNDING_BOX.any? { |corner|
87
+ bounding_box[corner].nil? }
87
88
 
88
89
  options = { bounds: build_bounding_box(bounding_box) }
89
90
  options.merge!(params)
@@ -128,7 +129,8 @@ module Yelp
128
129
  #
129
130
  # response = client.search(coordinates, params)
130
131
  def search_by_coordinates(coordinates, params = {}, locale = {})
131
- raise MissingLatLng if coordinates[:latitude].nil? || coordinates[:longitude].nil?
132
+ raise Error::MissingLatLng if coordinates[:latitude].nil? ||
133
+ coordinates[:longitude].nil?
132
134
 
133
135
  options = { ll: build_coordinates_string(coordinates) }
134
136
  options.merge!(params)
data/lib/yelp/error.rb CHANGED
@@ -1,55 +1,88 @@
1
1
  module Yelp
2
- class Error < StandardError
3
- def self.check_for_error(data)
4
- # Check if the status is in the range of non-error status codes
5
- return if (200..399).include?(data.status)
2
+ module Error
3
+ # Validates Yelp API responses. This class shouldn't be used directly, but
4
+ # should be accessed through the Yelp::Error.check_for_error interface.
5
+ # @see check_for_error
6
+ class ResponseValidator
6
7
 
7
- body = JSON.parse(data.body)
8
- @error_classes ||= Hash.new do |hash, key|
9
- class_name = key.split('_').map(&:capitalize).join('').gsub('Oauth', 'OAuth')
10
- hash[key] = Yelp.const_get(class_name)
8
+ # If the request is not successful, raise an appropriate Yelp::Error
9
+ # exception with the error text from the request response.
10
+ # @param response from the Yelp API
11
+ def validate(response)
12
+ return if successful_response?(response)
13
+ raise error_from_response(response)
11
14
  end
12
15
 
13
- klass = @error_classes[body['error']['id']]
14
- raise klass.new(body['error']['text'])
16
+ private
17
+
18
+ def successful_response?(response)
19
+ # Check if the status is in the range of non-error status codes
20
+ (200..399).include?(response.status)
21
+ end
22
+
23
+ # Create an initialized exception from the response
24
+ # @return [Yelp::Error::Base] exception corresponding to API error
25
+ def error_from_response(response)
26
+ body = JSON.parse(response.body)
27
+ klass = error_classes[body['error']['id']]
28
+ klass.new(body['error']['text'])
29
+ end
30
+
31
+ # Maps from API Error id's to Yelp::Error exception classes.
32
+ def error_classes
33
+ @@error_classes ||= Hash.new do |hash, key|
34
+ class_name = key.split('_').map(&:capitalize).join('').gsub('Oauth', 'OAuth')
35
+ hash[key] = Yelp::Error.const_get(class_name)
36
+ end
37
+ end
15
38
  end
16
- end
17
39
 
18
- class AlreadyConfigured < Error
19
- def initialize(msg = 'Gem cannot be reconfigured. Initialize a new ' +
20
- 'instance of Yelp::Client.')
21
- super
40
+ # Check the response for errors, raising an appropriate exception if
41
+ # necessary
42
+ # @param (see ResponseValidator#validate)
43
+ def self.check_for_error(response)
44
+ @response_validator ||= ResponseValidator.new
45
+ @response_validator.validate(response)
22
46
  end
23
- end
24
47
 
25
- class MissingAPIKeys < Error
26
- def initialize(msg = "You're missing an API key")
27
- super
48
+ class Base < StandardError; end
49
+
50
+ class AlreadyConfigured < Base
51
+ def initialize(msg = 'Gem cannot be reconfigured. Initialize a new ' +
52
+ 'instance of Yelp::Client.')
53
+ super
54
+ end
28
55
  end
29
- end
30
56
 
31
- class MissingLatLng < Error
32
- def initialize(msg = 'Missing required latitude or longitude parameters')
33
- super
57
+ class MissingAPIKeys < Base
58
+ def initialize(msg = "You're missing an API key")
59
+ super
60
+ end
34
61
  end
35
- end
36
62
 
37
- class BoundingBoxNotComplete < Error
38
- def initialize(msg = 'Missing required values for bounding box')
39
- super
63
+ class MissingLatLng < Base
64
+ def initialize(msg = 'Missing required latitude or longitude parameters')
65
+ super
66
+ end
40
67
  end
41
- end
42
68
 
43
- class InternalError < Error; end
44
- class ExceededRequests < Error; end
45
- class MissingParameter < Error; end
46
- class InvalidParameter < Error; end
47
- class InvalidSignature < Error; end
48
- class InvalidOAuthCredentials < Error; end
49
- class InvalidOAuthUser < Error; end
50
- class AccountUnconfirmed < Error; end
51
- class UnavailableForLocation < Error; end
52
- class AreaTooLarge < Error; end
53
- class MultipleLocations < Error; end
54
- class BusinessUnavailable < Error; end
69
+ class BoundingBoxNotComplete < Base
70
+ def initialize(msg = 'Missing required values for bounding box')
71
+ super
72
+ end
73
+ end
74
+
75
+ class InternalError < Base; end
76
+ class ExceededRequests < Base; end
77
+ class MissingParameter < Base; end
78
+ class InvalidParameter < Base; end
79
+ class InvalidSignature < Base; end
80
+ class InvalidOAuthCredentials < Base; end
81
+ class InvalidOAuthUser < Base; end
82
+ class AccountUnconfirmed < Base; end
83
+ class UnavailableForLocation < Base; end
84
+ class AreaTooLarge < Base; end
85
+ class MultipleLocations < Base; end
86
+ class BusinessUnavailable < Base; end
87
+ end
55
88
  end
data/lib/yelp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Yelp
2
- VERSION = "2.0.0"
2
+ VERSION = "2.0.1"
3
3
  end
@@ -5,7 +5,7 @@ shared_examples 'a request error' do
5
5
 
6
6
  it 'should raise an error' do
7
7
  client.stub_chain(:connection, :get).and_return(bad_response)
8
- expect { request }.to raise_error(Yelp::InternalError)
8
+ expect { request }.to raise_error(Yelp::Error::InternalError)
9
9
  end
10
10
  end
11
11
  end
@@ -57,11 +57,11 @@ describe Yelp::Endpoint::Search do
57
57
  describe 'errors' do
58
58
  context 'search' do
59
59
  it 'raises when #search_by_coordinates params are empty' do
60
- expect { client.search_by_coordinates({}, params) }.to raise_error(Yelp::MissingLatLng)
60
+ expect { client.search_by_coordinates({}, params) }.to raise_error(Yelp::Error::MissingLatLng)
61
61
  end
62
62
 
63
63
  it 'raises when #search_by_bounding_box params are empty' do
64
- expect { client.search_by_bounding_box({}, params) }.to raise_error(Yelp::BoundingBoxNotComplete)
64
+ expect { client.search_by_bounding_box({}, params) }.to raise_error(Yelp::Error::BoundingBoxNotComplete)
65
65
  end
66
66
  end
67
67
 
@@ -1,5 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'yelp'
3
2
 
4
3
  describe Yelp::Error do
5
4
  context '#from_request' do
@@ -16,7 +15,7 @@ describe Yelp::Error do
16
15
  it 'should raise an internal error' do
17
16
  expect {
18
17
  Yelp::Error.check_for_error(bad_response)
19
- }.to raise_error(Yelp::InternalError, 'error message')
18
+ }.to raise_error(Yelp::Error::InternalError, 'error message')
20
19
  end
21
20
  end
22
21
  end
data/yelp.gemspec CHANGED
@@ -6,11 +6,11 @@ require 'yelp/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'yelp'
8
8
  spec.version = Yelp::VERSION
9
- spec.authors = ['Tomer Elmalem', 'Yelp']
9
+ spec.authors = ['Tomer Elmalem', 'Justin Cunningham', 'Yelp']
10
10
  spec.email = ['telmalem@gmail.com', 'partnerships@yelp.com']
11
11
  spec.summary = %q{Ruby client library for the Yelp API}
12
12
  spec.description = 'Provides easy way to interact with the Yelp API in any kind of application'
13
- spec.homepage = 'https://github.com/yelp/yelp.rb'
13
+ spec.homepage = 'https://github.com/Yelp/yelp-ruby'
14
14
  spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
+ spec.required_ruby_version = '>= 1.9.2'
22
+
21
23
  spec.add_development_dependency 'bundler', '~> 1.5'
22
24
  spec.add_development_dependency 'rake', '~> 10.0', '>= 10.0.0'
23
25
  spec.add_development_dependency 'rspec', '~> 2.6'
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yelp
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomer Elmalem
8
+ - Justin Cunningham
8
9
  - Yelp
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2014-04-29 00:00:00.000000000 Z
13
+ date: 2014-05-02 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: bundler
@@ -202,6 +203,7 @@ extensions: []
202
203
  extra_rdoc_files: []
203
204
  files:
204
205
  - ".gitignore"
206
+ - ".travis.yml"
205
207
  - Gemfile
206
208
  - LICENSE.txt
207
209
  - README.md
@@ -230,7 +232,7 @@ files:
230
232
  - spec/yelp/yelp_spec.rb
231
233
  - tasks/console.rake
232
234
  - yelp.gemspec
233
- homepage: https://github.com/yelp/yelp.rb
235
+ homepage: https://github.com/Yelp/yelp-ruby
234
236
  licenses:
235
237
  - MIT
236
238
  metadata: {}
@@ -242,7 +244,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
242
244
  requirements:
243
245
  - - ">="
244
246
  - !ruby/object:Gem::Version
245
- version: '0'
247
+ version: 1.9.2
246
248
  required_rubygems_version: !ruby/object:Gem::Requirement
247
249
  requirements:
248
250
  - - ">="