yelp2 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +2 -0
- data/lib/yelp2.rb +6 -0
- data/lib/yelp2/base.rb +61 -0
- data/lib/yelp2/business.rb +44 -0
- data/lib/yelp2/location.rb +47 -0
- data/lib/yelp2/version.rb +3 -0
- data/yelp2.gemspec +26 -0
- metadata +121 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
data/lib/yelp2.rb
ADDED
data/lib/yelp2/base.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'addressable/uri'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Yelp
|
5
|
+
|
6
|
+
class Base
|
7
|
+
API_HOST = "api.yelp.com"
|
8
|
+
API_PATH = "/v2"
|
9
|
+
|
10
|
+
SEARCH_PATH = "#{API_PATH}/search"
|
11
|
+
|
12
|
+
# Passing in the appropriate values, have access to the yelp api
|
13
|
+
#
|
14
|
+
# consumer_key - A value used by the Consumer to identify itself to the Service Provider.
|
15
|
+
# consumer_secret - A secret used by the Consumer to establish ownership of the Consumer Key.
|
16
|
+
# token - A value used by the Consumer to obtain authorization from the User, and exchanged for an Access Token.
|
17
|
+
# token_secret - A secret used by the Consumer to establish ownership of a given Token.
|
18
|
+
#
|
19
|
+
# Returns nothing.
|
20
|
+
def initialize(consumer_key, consumer_secret, token, token_secret)
|
21
|
+
@consumer = OAuth::Consumer.new(consumer_key, consumer_secret, {:site => API_HOST})
|
22
|
+
@access_token = OAuth::AccessToken.new(@consumer, token, token_secret)
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
# Search for a given optional term and locations
|
27
|
+
#
|
28
|
+
# term - (Optional) Search term.
|
29
|
+
# location - Location to search
|
30
|
+
# location_type - Location Hash continaing one of three search types.
|
31
|
+
#
|
32
|
+
# Example
|
33
|
+
# search("dinner", "san+francisco", :location)
|
34
|
+
# search("dinner", "34.720,-112.299", :ll)
|
35
|
+
#
|
36
|
+
# Returns hash of businesses found.
|
37
|
+
def search(term, location)
|
38
|
+
raise ArgumentError, "Location must be a hash and of size 1" unless location.is_a?(Hash) || location.size != 1
|
39
|
+
uri = Addressable::URI.new(
|
40
|
+
:scheme => "http",
|
41
|
+
:host => API_HOST,
|
42
|
+
:path => SEARCH_PATH
|
43
|
+
)
|
44
|
+
|
45
|
+
uri.query_values = {
|
46
|
+
:term => term
|
47
|
+
}.merge(location)
|
48
|
+
|
49
|
+
|
50
|
+
res = @access_token.get(uri.to_s)
|
51
|
+
hash = JSON.parse(res.body)
|
52
|
+
if hash["error"]
|
53
|
+
"Sorry, #{hash["error"]["text"]}"
|
54
|
+
else
|
55
|
+
hash["businesses"].collect {|b| Yelp::Business.new(b)}
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
|
2
|
+
module Yelp
|
3
|
+
|
4
|
+
class Business
|
5
|
+
|
6
|
+
def initialize(hash)
|
7
|
+
@hash = hash
|
8
|
+
end
|
9
|
+
|
10
|
+
def id
|
11
|
+
@hash["id"]
|
12
|
+
end
|
13
|
+
|
14
|
+
def name
|
15
|
+
@hash["name"]
|
16
|
+
end
|
17
|
+
|
18
|
+
def phone
|
19
|
+
@hash["phone"]
|
20
|
+
end
|
21
|
+
|
22
|
+
def url
|
23
|
+
@hash["url"]
|
24
|
+
end
|
25
|
+
|
26
|
+
def mobile_url
|
27
|
+
@hash["mobile_url"]
|
28
|
+
end
|
29
|
+
|
30
|
+
def image_url
|
31
|
+
@hash["image_url"]
|
32
|
+
end
|
33
|
+
|
34
|
+
def review_count
|
35
|
+
@hash["review_count"]
|
36
|
+
end
|
37
|
+
|
38
|
+
def location
|
39
|
+
Yelp::Location.new(@hash["location"])
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Yelp
|
2
|
+
|
3
|
+
class Location
|
4
|
+
|
5
|
+
def initialize(hash)
|
6
|
+
@hash = hash
|
7
|
+
end
|
8
|
+
|
9
|
+
def address
|
10
|
+
@hash["address"]
|
11
|
+
end
|
12
|
+
|
13
|
+
def display_address
|
14
|
+
@hash["display_address"]
|
15
|
+
end
|
16
|
+
|
17
|
+
def city
|
18
|
+
@hash["city"]
|
19
|
+
end
|
20
|
+
|
21
|
+
def state
|
22
|
+
@hash["state_code"]
|
23
|
+
end
|
24
|
+
|
25
|
+
def postal_code
|
26
|
+
@hash["postal_code"]
|
27
|
+
end
|
28
|
+
|
29
|
+
def country
|
30
|
+
@hash["country_code"]
|
31
|
+
end
|
32
|
+
|
33
|
+
def latitude
|
34
|
+
@hash["coordinate"]["latitude"]
|
35
|
+
end
|
36
|
+
|
37
|
+
def longitude
|
38
|
+
@hash["coordinate"]["longitude"]
|
39
|
+
end
|
40
|
+
|
41
|
+
def neighborhoods
|
42
|
+
@hash["neighborhoods"]
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
data/yelp2.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "yelp2/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "yelp2"
|
7
|
+
s.version = Yelp2::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Michael Pilat"]
|
10
|
+
s.email = ["mike@mikepilat.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{A simple wrapper around the Yelp v2 API}
|
13
|
+
s.description = %q{A simple wrapper around the Yelp v2 API}
|
14
|
+
|
15
|
+
s.rubyforge_project = "yelp2"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency('oauth', '>= 0.4.4')
|
23
|
+
s.add_dependency('addressable', '>= 2.2.6')
|
24
|
+
s.add_dependency('json', '>= 1.5.1')
|
25
|
+
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yelp2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Michael Pilat
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-09-13 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: oauth
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 7
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
- 4
|
32
|
+
- 4
|
33
|
+
version: 0.4.4
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: addressable
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 11
|
45
|
+
segments:
|
46
|
+
- 2
|
47
|
+
- 2
|
48
|
+
- 6
|
49
|
+
version: 2.2.6
|
50
|
+
type: :runtime
|
51
|
+
version_requirements: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
name: json
|
54
|
+
prerelease: false
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 1
|
61
|
+
segments:
|
62
|
+
- 1
|
63
|
+
- 5
|
64
|
+
- 1
|
65
|
+
version: 1.5.1
|
66
|
+
type: :runtime
|
67
|
+
version_requirements: *id003
|
68
|
+
description: A simple wrapper around the Yelp v2 API
|
69
|
+
email:
|
70
|
+
- mike@mikepilat.com
|
71
|
+
executables: []
|
72
|
+
|
73
|
+
extensions: []
|
74
|
+
|
75
|
+
extra_rdoc_files: []
|
76
|
+
|
77
|
+
files:
|
78
|
+
- .gitignore
|
79
|
+
- Gemfile
|
80
|
+
- Rakefile
|
81
|
+
- lib/yelp2.rb
|
82
|
+
- lib/yelp2/base.rb
|
83
|
+
- lib/yelp2/business.rb
|
84
|
+
- lib/yelp2/location.rb
|
85
|
+
- lib/yelp2/version.rb
|
86
|
+
- yelp2.gemspec
|
87
|
+
homepage: ""
|
88
|
+
licenses: []
|
89
|
+
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
hash: 3
|
101
|
+
segments:
|
102
|
+
- 0
|
103
|
+
version: "0"
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
hash: 3
|
110
|
+
segments:
|
111
|
+
- 0
|
112
|
+
version: "0"
|
113
|
+
requirements: []
|
114
|
+
|
115
|
+
rubyforge_project: yelp2
|
116
|
+
rubygems_version: 1.8.10
|
117
|
+
signing_key:
|
118
|
+
specification_version: 3
|
119
|
+
summary: A simple wrapper around the Yelp v2 API
|
120
|
+
test_files: []
|
121
|
+
|