yellow_api 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,14 +1,39 @@
1
1
  # Yellow API
2
2
 
3
- Ruby wrapper for the YellowPages' Yellow API
3
+ Ruby wrapper for the YellowPages' [YellowAPI](http://www.yellowapi.com).
4
4
 
5
5
  ## Installation
6
- gem install yellow-api
6
+ gem install yellow_api
7
+
8
+ ## Examples
9
+
10
+ require 'yellow_api'
11
+
12
+ # Creating a client
13
+ @client = YellowApi.new(:apikey => "yourapikeygoeshere")
14
+
15
+ @client = YellowApi.new(:apikey => "sandboxapikey", :sandbox_enabled => true)
16
+
17
+ # Find businesses by listing
18
+ @client.find_business("barber", "Ottawa")
19
+
20
+ @client.find_business("barber", "Ottawa", { :pgLen => 10 }) # Limit to 10
21
+
22
+ # Get business details
23
+ my_barber = @client.find_business("barber", "Ottawa").listings.first
24
+ @client.get_business_details("Ontario", my_barber.name, my_barber.listingId)
25
+
26
+ # Find dealers
27
+ @client.find_dealer(6418182, { :pgLen => 10 })
28
+
29
+ # Get type ahead
30
+ @client.get_type_ahead("auto", :what)
31
+ @client.get_type_ahead("monct", :where)
7
32
 
8
33
  ## Documentation
9
- [See here](http://rdoc.info/gems/yellow-api)
34
+ [See here](http://rdoc.info/github/ianbishop/yellow_api/master/YellowApi)
10
35
 
11
- ## Examples
36
+ [Official API docs](http://www.yellowapi.com/docs/places)
12
37
 
13
38
  ## Inspiration
14
39
  API style was largely stolen/inspired by [hacker_news_search](https://github.com/ryanatwork/hacker_news_search) and [twitter](https://github.com/jnunemaker/twitter).
@@ -1,7 +1,25 @@
1
+ require 'active_support/all'
2
+
1
3
  module YellowApi
2
4
  class Client
3
5
  module GetBusinessDetails
4
6
 
7
+ PROVINCE_ABBREVIATION_MAP = {
8
+ :ab => "Alberta",
9
+ :bc => "British-Columbia",
10
+ :mb => "Manitoba",
11
+ :nb => "New-Brunswick",
12
+ :nl => "Newfoundland-and-Labrador",
13
+ :nt => "Northwest-Territories",
14
+ :ns => "Nova-Scotia",
15
+ :nu => "Nunavut",
16
+ :on => "Ontario",
17
+ :pe => "Prince-Edward-Island",
18
+ :qc => "Quebec",
19
+ :sk => "Saskatchewan",
20
+ :yt => "Yukon"
21
+ }
22
+
5
23
  # Gets business details.
6
24
  #
7
25
  # @see http://www.yellowapi.com/docs/places/#getbusinessdetails
@@ -20,13 +38,34 @@ module YellowApi
20
38
  # @example
21
39
  # YellowApi.get_business_details("Ile-du-Prince-Edouard", "Co-operators-The", 6418182)
22
40
  def get_business_details(province, business_name, listing_id, options={})
23
- options[:prov] = province
24
- options["bus-name"] = business_name
41
+ options[:prov] = normalize(expand_province(province))
42
+ options["bus-name"] = normalize(business_name)
25
43
  options[:listingId] = listing_id
44
+ options[:city] = normalize(options[:city]) if options.has_key? :city
26
45
 
27
46
  get('/GetBusinessDetails/', options)
28
47
  end
29
48
 
49
+ # Normalizes a given string
50
+ #
51
+ # All accents are removed (i.e. ‘à’ becomes ‘a’),
52
+ # and All non-alphanumeric characters are replaced by dash “-”, and
53
+ # Multiple dashes are replaced by a single dash.
54
+ #
55
+ # @see http://www.yellowapi.com/docs/places/#getbusinessdetails
56
+ # @see http://stackoverflow.com/questions/225471/how-do-i-replace-accented-latin-characters-in-ruby
57
+ def normalize(s)
58
+ s.mb_chars.normalize(:kd).gsub(/[^\x00-\x7F]/n, '').to_s
59
+ .gsub(/[\W]/, '-').gsub(/-+/, '-')
60
+ end
61
+
62
+ # Expands an abbreviated province
63
+ #
64
+ # This handles the fact that FindBusiness returns abbreviated provinces codes
65
+ # yet expects full province names for GetBusinessDetails
66
+ def expand_province(prov)
67
+ PROVINCE_ABBREVIATION_MAP.fetch(prov.downcase.to_sym, prov)
68
+ end
30
69
  end
31
70
  end
32
71
  end
@@ -1,3 +1,3 @@
1
1
  module YellowApi
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1 @@
1
+ [{"value":"auto body shop"},{"value":"automobile wrecking & recycling"},{"value":"automobile repair"},{"value":"automobile dealers"},{"value":"automobile dealers-new cars"},{"value":"automobile dealers-used cars"},{"value":"automobile parts"},{"value":"automobile detailing"},{"value":"automobiles"},{"value":"automobile insurance"}]
@@ -0,0 +1,28 @@
1
+ require 'helper'
2
+
3
+ describe YellowApi::Client::GetTypeAhead do
4
+
5
+ before do
6
+ @client = YellowApi::Client.new(:apikey => "a1s2d3f4g5h6j7k8l9k6j5j4")
7
+ end
8
+
9
+ describe ".get_type_ahead" do
10
+ before do
11
+ WebMock.allow_net_connect!
12
+
13
+ stub_get("GetTypeAhead/?apikey=a1s2d3f4g5h6j7k8l9k6j5j4&text=au&field=WHAT&UID=1").
14
+ to_return(:status => 200, :body => fixture("get_type_ahead.json"))
15
+ end
16
+
17
+ it "should return suggestions" do
18
+ wait 2 do
19
+ suggestions = @client.get_type_ahead("au", :what)
20
+
21
+ a_get("GetTypeAhead/?apikey=a1s2d3f4g5h6j7k8l9k6j5j4&text=au&field=WHAT&lang=en&fmt=JSON&UID=#{@client.uid}").
22
+ should have_been_made
23
+
24
+ suggestions.length.should > 0
25
+ end
26
+ end
27
+ end
28
+ end
@@ -26,4 +26,5 @@ Gem::Specification.new do |gem|
26
26
  gem.add_runtime_dependency 'multi_json', '~> 1.0.2'
27
27
  gem.add_runtime_dependency 'rash', '~> 0.3.0'
28
28
  gem.add_runtime_dependency 'uuid', '~> 2.3.5'
29
+ gem.add_runtime_dependency 'activesupport', '~> 3.2.3'
29
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yellow_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-04-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: maruku
16
- requirement: &77299160 !ruby/object:Gem::Requirement
16
+ requirement: &72188980 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0.6'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *77299160
24
+ version_requirements: *72188980
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &77297970 !ruby/object:Gem::Requirement
27
+ requirement: &72188360 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0.9'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *77297970
35
+ version_requirements: *72188360
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &77296910 !ruby/object:Gem::Requirement
38
+ requirement: &72187120 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '2.6'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *77296910
46
+ version_requirements: *72187120
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: simplecov
49
- requirement: &77296180 !ruby/object:Gem::Requirement
49
+ requirement: &72186590 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 0.5.3
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *77296180
57
+ version_requirements: *72186590
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: webmock
60
- requirement: &77295100 !ruby/object:Gem::Requirement
60
+ requirement: &72185860 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.7.6
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *77295100
68
+ version_requirements: *72185860
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: yard
71
- requirement: &77294490 !ruby/object:Gem::Requirement
71
+ requirement: &72185320 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0.7'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *77294490
79
+ version_requirements: *72185320
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: faraday
82
- requirement: &77328080 !ruby/object:Gem::Requirement
82
+ requirement: &72184950 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: 0.7.4
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *77328080
90
+ version_requirements: *72184950
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: faraday_middleware
93
- requirement: &77327400 !ruby/object:Gem::Requirement
93
+ requirement: &72184420 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ~>
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: 0.7.0
99
99
  type: :runtime
100
100
  prerelease: false
101
- version_requirements: *77327400
101
+ version_requirements: *72184420
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: hashie
104
- requirement: &77326570 !ruby/object:Gem::Requirement
104
+ requirement: &72252170 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ~>
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: 1.2.0
110
110
  type: :runtime
111
111
  prerelease: false
112
- version_requirements: *77326570
112
+ version_requirements: *72252170
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: multi_json
115
- requirement: &77326220 !ruby/object:Gem::Requirement
115
+ requirement: &72251260 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ~>
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: 1.0.2
121
121
  type: :runtime
122
122
  prerelease: false
123
- version_requirements: *77326220
123
+ version_requirements: *72251260
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: rash
126
- requirement: &77325580 !ruby/object:Gem::Requirement
126
+ requirement: &72250510 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ~>
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: 0.3.0
132
132
  type: :runtime
133
133
  prerelease: false
134
- version_requirements: *77325580
134
+ version_requirements: *72250510
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: uuid
137
- requirement: &77324320 !ruby/object:Gem::Requirement
137
+ requirement: &72249390 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ~>
@@ -142,7 +142,18 @@ dependencies:
142
142
  version: 2.3.5
143
143
  type: :runtime
144
144
  prerelease: false
145
- version_requirements: *77324320
145
+ version_requirements: *72249390
146
+ - !ruby/object:Gem::Dependency
147
+ name: activesupport
148
+ requirement: &72248400 !ruby/object:Gem::Requirement
149
+ none: false
150
+ requirements:
151
+ - - ~>
152
+ - !ruby/object:Gem::Version
153
+ version: 3.2.3
154
+ type: :runtime
155
+ prerelease: false
156
+ version_requirements: *72248400
146
157
  description: Simple ruby wrapper for the YellowPages' Yellow API
147
158
  email: ian.bishop@unb.ca
148
159
  executables: []
@@ -168,11 +179,13 @@ files:
168
179
  - spec/fixtures/find_business.json
169
180
  - spec/fixtures/find_dealer.json
170
181
  - spec/fixtures/get_business_details.json
182
+ - spec/fixtures/get_type_ahead.json
171
183
  - spec/helper.rb
172
184
  - spec/yellow_api/client_spec.rb
173
185
  - spec/yellow_api/find_business_spec.rb
174
186
  - spec/yellow_api/find_dealer_spec.rb
175
187
  - spec/yellow_api/get_business_details_spec.rb
188
+ - spec/yellow_api/get_type_ahead_spec.rb
176
189
  - spec/yellow_api_spec.rb
177
190
  - yellow_api.gemspec
178
191
  homepage: https://github.com/ianbishop/yellow_api
@@ -203,10 +216,12 @@ test_files:
203
216
  - spec/fixtures/find_business.json
204
217
  - spec/fixtures/find_dealer.json
205
218
  - spec/fixtures/get_business_details.json
219
+ - spec/fixtures/get_type_ahead.json
206
220
  - spec/helper.rb
207
221
  - spec/yellow_api/client_spec.rb
208
222
  - spec/yellow_api/find_business_spec.rb
209
223
  - spec/yellow_api/find_dealer_spec.rb
210
224
  - spec/yellow_api/get_business_details_spec.rb
225
+ - spec/yellow_api/get_type_ahead_spec.rb
211
226
  - spec/yellow_api_spec.rb
212
227
  has_rdoc: