lita-yelpme 0.0.3 → 0.1.0
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 +4 -4
- data/lib/lita/handlers/yelpme.rb +22 -4
- data/lita-yelpme.gemspec +1 -1
- data/spec/lita/handlers/yelpme_spec.rb +62 -22
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c14a1a9987d94ae1b311ec22452378998ce5564
|
4
|
+
data.tar.gz: 86aab3594dd42af3e7782e340200dbc44c3e18ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8a1fad4bf070abdf1715b70dc41ffdc2890eb75c25d5271da07f2f012676be9aad3ea247643e642928e45fb00c2ea70b110143312b3f77362d194793b0a9ff2
|
7
|
+
data.tar.gz: fd70ff35831442238371353f44d303fb76df04ea06caa11134e3d9d79a439bdc0c474dad1dce329a83329bf64f286d979014a7878fa9d8db7d50c250652ebcb1
|
data/lib/lita/handlers/yelpme.rb
CHANGED
@@ -3,10 +3,12 @@ require 'yelp'
|
|
3
3
|
module Lita
|
4
4
|
module Handlers
|
5
5
|
class Yelpme < Handler
|
6
|
-
route(/^(?:yelp|y)\s+(.+)
|
6
|
+
route(/^(?:yelp|y)\s+(.+)./u, :yelp, command: true, help: {
|
7
7
|
"yelp QUERY" => "Return the first Yelp result with information about the first business found"
|
8
8
|
})
|
9
|
-
|
9
|
+
route(/^(?:yelp|y)\s+(.+)@\s(.*)/u, :yelp_city, command: true, help: {
|
10
|
+
"yelp QUERY @ CITY" => "Return the first Yelp result with information about the first business found"
|
11
|
+
})
|
10
12
|
def self.default_config(handler_config)
|
11
13
|
handler_config.default_city = "San Francisco"
|
12
14
|
end
|
@@ -20,12 +22,28 @@ module Lita
|
|
20
22
|
response.reply('Sorry, could not fetch a response from Yelp')
|
21
23
|
return
|
22
24
|
end
|
25
|
+
response.reply create_reply(config.default_city, query, yelp_response)
|
26
|
+
end
|
27
|
+
def yelp_city(response)
|
28
|
+
query = response.matches[0][0]
|
29
|
+
city = response.matches[0][1]
|
30
|
+
begin
|
31
|
+
yelp_response = client.search(city, { term: query, limit: 1 })
|
32
|
+
rescue Yelp::Error::MissingAPIKeys
|
33
|
+
Lita.logger.error('Could not receive response from yelp, check your API keys')
|
34
|
+
response.reply('Sorry, could not fetch a response from Yelp')
|
35
|
+
return
|
36
|
+
end
|
37
|
+
response.reply create_reply(city, query, yelp_response)
|
38
|
+
end
|
39
|
+
|
40
|
+
def create_reply(city, query, yelp_response)
|
23
41
|
if yelp_response.businesses.length == 0
|
24
|
-
|
42
|
+
return "Cannot find any businesses in #{city} matching #{query}"
|
25
43
|
end
|
26
44
|
result = yelp_response.businesses[0]
|
27
45
|
address = "#{result.location.address.join(' ')}, #{result.location.city}, #{result.location.state_code} #{result.location.postal_code}"
|
28
|
-
|
46
|
+
"#{result.name} (#{result.rating} from #{result.review_count} reviews) @ #{address} - #{result.display_phone} #{result.url}"
|
29
47
|
end
|
30
48
|
|
31
49
|
def client
|
data/lita-yelpme.gemspec
CHANGED
@@ -2,6 +2,7 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Lita::Handlers::Yelpme, lita_handler: true do
|
4
4
|
it { routes_command('yelp state bird provisions').to(:yelp) }
|
5
|
+
it { routes_command('yelp original gravity @ san jose').to(:yelp_city) }
|
5
6
|
|
6
7
|
describe "without valid API keys" do
|
7
8
|
it "returns an error when no api keys are defined" do
|
@@ -11,32 +12,71 @@ describe Lita::Handlers::Yelpme, lita_handler: true do
|
|
11
12
|
end
|
12
13
|
|
13
14
|
describe "with valid API keys" do
|
14
|
-
|
15
|
-
BurstStruct::Burst.new({
|
16
|
-
businesses: [
|
17
|
-
{
|
18
|
-
location: {
|
19
|
-
city: "San Francisco",
|
20
|
-
address: ["1529", "Fillmore", "St"],
|
21
|
-
state_code: "CA",
|
22
|
-
postal_code: "94115"
|
23
|
-
},
|
24
|
-
name: "State Bird Provisions",
|
25
|
-
rating: "4.5",
|
26
|
-
review_count: 787,
|
27
|
-
display_phone: "+1-415-795-1272",
|
28
|
-
url: "http://www.yelp.com/biz/state-bird-provisions-san-francisco"
|
29
|
-
}
|
30
|
-
]
|
31
|
-
})
|
32
|
-
}
|
15
|
+
|
33
16
|
before do
|
34
17
|
allow(Yelp::Client).to receive(:new) { Yelp::Client }
|
35
18
|
allow(Yelp::Client).to receive(:search) { yelp_response }
|
36
19
|
end
|
37
|
-
|
38
|
-
|
39
|
-
|
20
|
+
describe "using the default city" do
|
21
|
+
let(:yelp_response) {
|
22
|
+
BurstStruct::Burst.new({
|
23
|
+
businesses: [
|
24
|
+
{
|
25
|
+
location: {
|
26
|
+
city: "San Francisco",
|
27
|
+
address: ["1529", "Fillmore", "St"],
|
28
|
+
state_code: "CA",
|
29
|
+
postal_code: "94115"
|
30
|
+
},
|
31
|
+
name: "State Bird Provisions",
|
32
|
+
rating: "4.5",
|
33
|
+
review_count: 787,
|
34
|
+
display_phone: "+1-415-795-1272",
|
35
|
+
url: "http://www.yelp.com/biz/state-bird-provisions-san-francisco"
|
36
|
+
}
|
37
|
+
]
|
38
|
+
})
|
39
|
+
}
|
40
|
+
it "fetches a result from yelp" do
|
41
|
+
send_command("yelp state bird provisions")
|
42
|
+
expect(replies.last).to eq ("State Bird Provisions (4.5 from 787 reviews) @ 1529 Fillmore St, San Francisco, CA 94115 - +1-415-795-1272 http://www.yelp.com/biz/state-bird-provisions-san-francisco")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
describe "using the specified city" do
|
46
|
+
let(:yelp_response) {
|
47
|
+
BurstStruct::Burst.new({
|
48
|
+
businesses: [
|
49
|
+
{
|
50
|
+
location: {
|
51
|
+
city: "San Jose",
|
52
|
+
address: ["66", "S", "1st", "St"],
|
53
|
+
state_code: "CA",
|
54
|
+
postal_code: "95113"
|
55
|
+
},
|
56
|
+
name: "Original Gravity Public House",
|
57
|
+
rating: "4.0",
|
58
|
+
review_count: 348,
|
59
|
+
display_phone: "+1-408-915-2337",
|
60
|
+
url: "http://www.yelp.com/biz/original-gravity-public-house-san-jose"
|
61
|
+
}
|
62
|
+
]
|
63
|
+
})
|
64
|
+
}
|
65
|
+
it "fetches a result from the specified city" do
|
66
|
+
send_command('yelp original gravity @ san jose')
|
67
|
+
expect(replies.last).to eq ("Original Gravity Public House (4.0 from 348 reviews) @ 66 S 1st St, San Jose, CA 95113 - +1-408-915-2337 http://www.yelp.com/biz/original-gravity-public-house-san-jose")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
describe "if there are no results" do
|
71
|
+
let(:yelp_response) {
|
72
|
+
BurstStruct::Burst.new({
|
73
|
+
businesses: []
|
74
|
+
})
|
75
|
+
}
|
76
|
+
it "returns an error" do
|
77
|
+
send_command("yelp fhaskjlfhaskfhdaskjlgflaskjhdalkhflaksjhfsa")
|
78
|
+
expect(replies.last).to eq("Cannot find any businesses in San Francisco matching fhaskjlfhaskfhdaskjlgflaskjhdalkhflaksjhfs")
|
79
|
+
end
|
40
80
|
end
|
41
81
|
end
|
42
82
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-yelpme
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ted
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|