lieu 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CONTRIBUTING.md +34 -0
- data/LICENSE +20 -0
- data/README.md +112 -0
- data/Rakefile +42 -0
- data/lib/lieu/client/actions.rb +105 -0
- data/lib/lieu/client/autocomplete.rb +21 -0
- data/lib/lieu/client/details.rb +21 -0
- data/lib/lieu/client/photos.rb +23 -0
- data/lib/lieu/client/query_autocomplete.rb +21 -0
- data/lib/lieu/client/search.rb +79 -0
- data/lib/lieu/client.rb +36 -0
- data/lib/lieu/configuration.rb +45 -0
- data/lib/lieu/connection.rb +28 -0
- data/lib/lieu/error.rb +58 -0
- data/lib/lieu/request.rb +53 -0
- data/lib/lieu/response/raise_error.rb +18 -0
- data/lib/lieu/version.rb +5 -0
- data/lib/lieu.rb +25 -0
- data/lieu.gemspec +26 -0
- data/spec/cassettes/Lieu_Client_Actions/_event_details/returns_an_event_details.yml +54 -0
- data/spec/cassettes/Lieu_Client_Autocomplete/_autocomplete/returns_an_array_of_places.yml +203 -0
- data/spec/cassettes/Lieu_Client_Details/_details/returns_a_place_details.yml +220 -0
- data/spec/cassettes/Lieu_Client_Photos/_photo/returns_a_photo_image.yml +111 -0
- data/spec/cassettes/Lieu_Client_QueryAutocomplete/_query_autocomplete/returns_an_array_of_places.yml +203 -0
- data/spec/cassettes/Lieu_Client_Search/_nearby_search/returns_an_array_of_places.yml +517 -0
- data/spec/cassettes/Lieu_Client_Search/_radarsearch/returns_an_array_of_places.yml +1683 -0
- data/spec/cassettes/Lieu_Client_Search/_textsearch/returns_an_array_of_places.yml +560 -0
- data/spec/cassettes/Lieu_Request/given_a_GET_request/with_options/sets_options_as_url_parameters.yml +63 -0
- data/spec/cassettes/Lieu_Request/given_a_POST_request/with_options/sets_options_as_body_parameters.yml +63 -0
- data/spec/lib/lieu/client/actions_spec.rb +178 -0
- data/spec/lib/lieu/client/autocomplete_spec.rb +11 -0
- data/spec/lib/lieu/client/details_spec.rb +11 -0
- data/spec/lib/lieu/client/photo_spec.rb +17 -0
- data/spec/lib/lieu/client/query_autocomplete_spec.rb +11 -0
- data/spec/lib/lieu/client/search_spec.rb +39 -0
- data/spec/lib/lieu/client_spec.rb +70 -0
- data/spec/lib/lieu/request_spec.rb +35 -0
- data/spec/lib/lieu_spec.rb +32 -0
- data/spec/spec_helper.rb +65 -0
- data/spec/support/shared_examples/error.rb +33 -0
- metadata +120 -0
@@ -0,0 +1,63 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://maps.googleapis.com/maps/api/place/fuubar/json?key=<API_KEY>&sensor=false
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: '{"test":"toto"}'
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.8.8
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
14
|
+
Accept:
|
15
|
+
- '*/*'
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 404
|
19
|
+
message: Not Found
|
20
|
+
headers:
|
21
|
+
Date:
|
22
|
+
- Thu, 26 Sep 2013 11:47:29 GMT
|
23
|
+
Content-Type:
|
24
|
+
- text/html; charset=UTF-8
|
25
|
+
Server:
|
26
|
+
- mafe
|
27
|
+
Content-Length:
|
28
|
+
- '1018'
|
29
|
+
X-Xss-Protection:
|
30
|
+
- 1; mode=block
|
31
|
+
X-Frame-Options:
|
32
|
+
- SAMEORIGIN
|
33
|
+
Alternate-Protocol:
|
34
|
+
- 443:quic
|
35
|
+
body:
|
36
|
+
encoding: ASCII-8BIT
|
37
|
+
string: !binary |-
|
38
|
+
PCFET0NUWVBFIGh0bWw+CjxodG1sIGxhbmc9ZW4+CiAgPG1ldGEgY2hhcnNl
|
39
|
+
dD11dGYtOD4KICA8bWV0YSBuYW1lPXZpZXdwb3J0IGNvbnRlbnQ9ImluaXRp
|
40
|
+
YWwtc2NhbGU9MSwgbWluaW11bS1zY2FsZT0xLCB3aWR0aD1kZXZpY2Utd2lk
|
41
|
+
dGgiPgogIDx0aXRsZT5FcnJvciA0MDQgKE5vdCBGb3VuZCkhITE8L3RpdGxl
|
42
|
+
PgogIDxzdHlsZT4KICAgICp7bWFyZ2luOjA7cGFkZGluZzowfWh0bWwsY29k
|
43
|
+
ZXtmb250OjE1cHgvMjJweCBhcmlhbCxzYW5zLXNlcmlmfWh0bWx7YmFja2dy
|
44
|
+
b3VuZDojZmZmO2NvbG9yOiMyMjI7cGFkZGluZzoxNXB4fWJvZHl7bWFyZ2lu
|
45
|
+
OjclIGF1dG8gMDttYXgtd2lkdGg6MzkwcHg7bWluLWhlaWdodDoxODBweDtw
|
46
|
+
YWRkaW5nOjMwcHggMCAxNXB4fSogPiBib2R5e2JhY2tncm91bmQ6dXJsKC8v
|
47
|
+
d3d3Lmdvb2dsZS5jb20vaW1hZ2VzL2Vycm9ycy9yb2JvdC5wbmcpIDEwMCUg
|
48
|
+
NXB4IG5vLXJlcGVhdDtwYWRkaW5nLXJpZ2h0OjIwNXB4fXB7bWFyZ2luOjEx
|
49
|
+
cHggMCAyMnB4O292ZXJmbG93OmhpZGRlbn1pbnN7Y29sb3I6Izc3Nzt0ZXh0
|
50
|
+
LWRlY29yYXRpb246bm9uZX1hIGltZ3tib3JkZXI6MH1AbWVkaWEgc2NyZWVu
|
51
|
+
IGFuZCAobWF4LXdpZHRoOjc3MnB4KXtib2R5e2JhY2tncm91bmQ6bm9uZTtt
|
52
|
+
YXJnaW4tdG9wOjA7bWF4LXdpZHRoOm5vbmU7cGFkZGluZy1yaWdodDowfX0K
|
53
|
+
ICA8L3N0eWxlPgogIDxhIGhyZWY9Ly93d3cuZ29vZ2xlLmNvbS8+PGltZyBz
|
54
|
+
cmM9Ly93d3cuZ29vZ2xlLmNvbS9pbWFnZXMvZXJyb3JzL2xvZ29fc20uZ2lm
|
55
|
+
IGFsdD1Hb29nbGU+PC9hPgogIDxwPjxiPjQwNC48L2I+IDxpbnM+VGhhdOKA
|
56
|
+
mXMgYW4gZXJyb3IuPC9pbnM+CiAgPHA+VGhlIHJlcXVlc3RlZCBVUkwgPGNv
|
57
|
+
ZGU+L21hcHMvYXBpL3BsYWNlL2Z1dWJhci9qc29uP2tleT1BSXphU3lBaXh4
|
58
|
+
UFUyczdmbVJNNFdfUHVzbWE1MzdWWHdrWVRaYnMmYW1wO3NlbnNvcj1mYWxz
|
59
|
+
ZTwvY29kZT4gd2FzIG5vdCBmb3VuZCBvbiB0aGlzIHNlcnZlci4gIDxpbnM+
|
60
|
+
VGhhdOKAmXMgYWxsIHdlIGtub3cuPC9pbnM+Cg==
|
61
|
+
http_version:
|
62
|
+
recorded_at: Thu, 26 Sep 2013 11:47:29 GMT
|
63
|
+
recorded_with: VCR 2.5.0
|
@@ -0,0 +1,178 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Lieu::Client::Actions do
|
4
|
+
describe '.add' do
|
5
|
+
let(:add_place_body) do
|
6
|
+
{
|
7
|
+
location: {
|
8
|
+
lat: '-33.8669710',
|
9
|
+
lng: '151.1958750'
|
10
|
+
},
|
11
|
+
accuracy: 50,
|
12
|
+
name: 'Google Shoes!',
|
13
|
+
types: [
|
14
|
+
'shoe_store'
|
15
|
+
],
|
16
|
+
language: 'en-AU'
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'adds a place' do
|
21
|
+
VCR.turn_off!
|
22
|
+
|
23
|
+
stub_post('add').with(add_place_body).to_return(
|
24
|
+
body: { reference: '123', id: '456', status: 'OK' }.to_json,
|
25
|
+
headers: json_content_type
|
26
|
+
)
|
27
|
+
|
28
|
+
new_place = client.add(add_place_body)
|
29
|
+
|
30
|
+
expect(new_place.reference).to eql('123')
|
31
|
+
expect(new_place.id).to eql('456')
|
32
|
+
|
33
|
+
VCR.turn_on!
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '.delete' do
|
38
|
+
let(:delete_place_body) do
|
39
|
+
{
|
40
|
+
reference: place_reference
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'deletes a place' do
|
45
|
+
VCR.turn_off!
|
46
|
+
|
47
|
+
stub_post('delete').with(delete_place_body).to_return(
|
48
|
+
body: { status: 'OK' }.to_json,
|
49
|
+
headers: json_content_type
|
50
|
+
)
|
51
|
+
|
52
|
+
delete_request = client.delete(reference: place_reference)
|
53
|
+
|
54
|
+
expect(delete_request).to eql(true)
|
55
|
+
|
56
|
+
VCR.turn_on!
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe '.bump' do
|
61
|
+
before { VCR.turn_off! }
|
62
|
+
|
63
|
+
after { VCR.turn_on! }
|
64
|
+
|
65
|
+
let(:bump_place_body) do
|
66
|
+
{
|
67
|
+
reference: place_reference
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'bumping a place' do
|
72
|
+
it 'bumps a place' do
|
73
|
+
stub_post('bump').with(bump_place_body).to_return(
|
74
|
+
body: { status: 'OK' }.to_json,
|
75
|
+
headers: json_content_type
|
76
|
+
)
|
77
|
+
|
78
|
+
bump_place_request = client.bump(reference: place_reference)
|
79
|
+
|
80
|
+
expect(bump_place_request).to eql(true)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'bumping an event' do
|
85
|
+
let(:bump_event_body) do
|
86
|
+
bump_place_body.merge({ event_id: '123' })
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'bumps an event' do
|
90
|
+
stub_post('bump').with(bump_event_body).to_return(
|
91
|
+
body: { status: 'OK' }.to_json,
|
92
|
+
headers: json_content_type
|
93
|
+
)
|
94
|
+
|
95
|
+
bump_event_request = client.bump(
|
96
|
+
reference: place_reference,
|
97
|
+
event_id: '123'
|
98
|
+
)
|
99
|
+
|
100
|
+
expect(bump_event_request).to eql(true)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe '.add_event' do
|
106
|
+
let(:add_event_body) do
|
107
|
+
{
|
108
|
+
duration: 172800,
|
109
|
+
language: 'EN-CA',
|
110
|
+
reference: 'CnRkAAAAGnBVNFDeQoOQHzgdOpOqJNV7K9-etc',
|
111
|
+
summary: 'Rock n Roll Dreams: The band fully electric in my kitchen '\
|
112
|
+
'and drinking all my beer.',
|
113
|
+
url: 'http://www.example.com/event_details/10476.html'
|
114
|
+
}
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'adds an event' do
|
118
|
+
VCR.turn_off!
|
119
|
+
|
120
|
+
stub_post('event/add').with(add_event_body).to_return(
|
121
|
+
body: { event_id: '123', status: 'OK' }.to_json,
|
122
|
+
headers: json_content_type
|
123
|
+
)
|
124
|
+
|
125
|
+
new_event = client.add_event(add_event_body)
|
126
|
+
|
127
|
+
expect(new_event.event_id).to eql('123')
|
128
|
+
|
129
|
+
VCR.turn_on!
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe '.delete_event' do
|
134
|
+
let(:delete_event_body) do
|
135
|
+
{
|
136
|
+
reference: place_reference,
|
137
|
+
event_id: '123'
|
138
|
+
}
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'deletes an event' do
|
142
|
+
VCR.turn_off!
|
143
|
+
|
144
|
+
stub_post('event/delete').with(delete_event_body).to_return(
|
145
|
+
body: { status: 'OK' }.to_json,
|
146
|
+
headers: json_content_type
|
147
|
+
)
|
148
|
+
|
149
|
+
delete_event_request = client.delete_event(
|
150
|
+
reference: place_reference,
|
151
|
+
event_id: '123'
|
152
|
+
)
|
153
|
+
|
154
|
+
expect(delete_event_request).to eql(true)
|
155
|
+
|
156
|
+
VCR.turn_on!
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
160
|
+
|
161
|
+
describe '.event_details', :vcr do
|
162
|
+
it 'returns an event details' do
|
163
|
+
place = nil
|
164
|
+
|
165
|
+
VCR.use_cassette('Lieu_Client_Details/'\
|
166
|
+
'_details/returns_a_place_details') do
|
167
|
+
place = client.details(place_reference)
|
168
|
+
end
|
169
|
+
|
170
|
+
event = client.event_details(
|
171
|
+
place.reference,
|
172
|
+
place.events.first.event_id
|
173
|
+
)
|
174
|
+
|
175
|
+
expect(event.event_id).not_to be_empty
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Lieu::Client::Photos do
|
4
|
+
let(:photo_reference) do
|
5
|
+
'CnRtAAAAqCdOEgCrPQY3kaulN3Ywx0CMfg_W97Vfyp5M2tr_qd9HRcodoKvZZhsT_glcV_xJ'\
|
6
|
+
'QDM7br-tI2eb9u1cqkyNYEiMvkVLbky4FvheFSvfoqHUDnnJhjzPMxQfFf3GDGnbBmh6aD'\
|
7
|
+
'lgSOdd2LNHCm5SNBIQBT5s3kRxjhR0oAnzhINbcxoUyvD_Ce1R79aAormNMM5LhcwFU5w'
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '.photo', :vcr do
|
11
|
+
it 'returns a photo image' do
|
12
|
+
image = client.photo(photo_reference, maxheight: 10)
|
13
|
+
|
14
|
+
expect(image).not_to be_empty
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Lieu::Client::Search do
|
4
|
+
let(:options) do
|
5
|
+
{
|
6
|
+
location: {
|
7
|
+
lat: '48.85341',
|
8
|
+
lng: '2.3488'
|
9
|
+
},
|
10
|
+
radius: '1500'
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '.nearby_search', :vcr do
|
15
|
+
it 'returns an array of places' do
|
16
|
+
places = client.nearby_search(options)
|
17
|
+
|
18
|
+
expect(places).to be_a Array
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '.textsearch', :vcr do
|
23
|
+
it 'returns an array of places' do
|
24
|
+
places = client.text_search('Google Sydney')
|
25
|
+
|
26
|
+
expect(places).to be_a Array
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '.radarsearch', :vcr do
|
31
|
+
before { options.merge!(types: ['bank', 'atm']) }
|
32
|
+
|
33
|
+
it 'returns an array of places' do
|
34
|
+
places = client.radar_search(options)
|
35
|
+
|
36
|
+
expect(places).to be_a Array
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Lieu::Client do
|
4
|
+
describe 'module configuration' do
|
5
|
+
before do
|
6
|
+
Lieu.reset!
|
7
|
+
|
8
|
+
Lieu.configure do |config|
|
9
|
+
Lieu::Configuration::VALID_OPTIONS.each do |key|
|
10
|
+
config.send("#{key}=", "Some #{key}")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
after { Lieu.reset! }
|
16
|
+
|
17
|
+
it "inherits the module configuration" do
|
18
|
+
client = Lieu::Client.new
|
19
|
+
|
20
|
+
Lieu::Configuration::VALID_OPTIONS.each do |key|
|
21
|
+
expect(client.instance_variable_get(:"@#{key}")).to eq "Some #{key}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'with class level configuration' do
|
27
|
+
describe 'api_endpoint' do
|
28
|
+
it 'sets api_endpoint' do
|
29
|
+
client = Lieu::Client.new
|
30
|
+
|
31
|
+
expect(client.api_endpoint).
|
32
|
+
to eql 'https://maps.googleapis.com/maps/api/place/'
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'overrides module configuration' do
|
36
|
+
client = Lieu::Client.new(api_endpoint: 'http://fuubar.com')
|
37
|
+
|
38
|
+
expect(client.api_endpoint).to eql 'http://fuubar.com'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe 'api_key' do
|
43
|
+
it 'sets api_key' do
|
44
|
+
client = Lieu::Client.new
|
45
|
+
|
46
|
+
expect(client.api_key).to be_nil
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'overrides module configuration' do
|
50
|
+
client = Lieu::Client.new(api_key: 'randomkey')
|
51
|
+
|
52
|
+
expect(client.api_key).to eql 'randomkey'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe 'sensor' do
|
57
|
+
it 'sets sensor' do
|
58
|
+
client = Lieu::Client.new
|
59
|
+
|
60
|
+
expect(client.sensor).to be_false
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'overrides module configuration' do
|
64
|
+
client = Lieu::Client.new(sensor: true)
|
65
|
+
|
66
|
+
expect(client.sensor).to be_true
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Lieu::Request do
|
4
|
+
it_behaves_like 'an error', 'INVALID_REQUEST'
|
5
|
+
it_behaves_like 'an error', 'REQUEST_DENIED'
|
6
|
+
it_behaves_like 'an error', 'NOT_FOUND'
|
7
|
+
it_behaves_like 'an error', 'UNKNOWN_ERROR'
|
8
|
+
it_behaves_like 'an error', 'ZERO_RESULTS'
|
9
|
+
it_behaves_like 'an error', 'OVER_QUERY_LIMIT'
|
10
|
+
|
11
|
+
it_behaves_like 'a http error', 400, Lieu::InvalidRequest
|
12
|
+
it_behaves_like 'a http error', 403, Lieu::OverQueryLimit
|
13
|
+
|
14
|
+
context 'given a GET request' do
|
15
|
+
context 'with options', :vcr do
|
16
|
+
before { client.get('fuubar', language: 'fr') }
|
17
|
+
|
18
|
+
it 'sets options as url parameters' do
|
19
|
+
a_request(:get, google_places_url('fuubar')).
|
20
|
+
with(query: { 'language' => 'fr' }).should have_been_made
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'given a POST request' do
|
26
|
+
context 'with options', :vcr do
|
27
|
+
before { client.post('fuubar', test: 'toto') }
|
28
|
+
|
29
|
+
it 'sets options as body parameters' do
|
30
|
+
a_request(:post, google_places_url('fuubar')).
|
31
|
+
with(body: { test: 'toto' }.to_json).should have_been_made
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Lieu do
|
4
|
+
describe '.respond_to?' do
|
5
|
+
context 'with an existing Lieu method' do
|
6
|
+
it 'responds to method' do
|
7
|
+
expect(Lieu.respond_to?(:new, true)).to be_true
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'with an existing Lieu::Client method' do
|
12
|
+
it 'responds to method' do
|
13
|
+
expect(Lieu.respond_to?(:get, true)).to be_true
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'delegates to Lieu::Client' do
|
17
|
+
Lieu::Client.stub_chain(:new, :get).and_return(true)
|
18
|
+
|
19
|
+
expect(Lieu::Client).to receive(:new).ordered
|
20
|
+
expect(Lieu::Client).to receive(:new).ordered
|
21
|
+
|
22
|
+
Lieu.get('fuubar')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '.new' do
|
28
|
+
it 'returns a Lieu::Client' do
|
29
|
+
expect(Lieu.new).to be_a Lieu::Client
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
require 'coveralls'
|
3
|
+
|
4
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
5
|
+
SimpleCov::Formatter::HTMLFormatter,
|
6
|
+
Coveralls::SimpleCov::Formatter
|
7
|
+
]
|
8
|
+
|
9
|
+
SimpleCov.start do
|
10
|
+
add_filter 'spec'
|
11
|
+
add_filter 'lib/lieu/response'
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'rspec'
|
15
|
+
require 'vcr'
|
16
|
+
require 'json'
|
17
|
+
require 'webmock/rspec'
|
18
|
+
require 'lieu'
|
19
|
+
|
20
|
+
Dir['./spec/support/**/*.rb'].each { |f| require f }
|
21
|
+
|
22
|
+
WebMock.disable_net_connect!(allow: 'coveralls.io')
|
23
|
+
|
24
|
+
VCR.configure do |c|
|
25
|
+
c.cassette_library_dir = 'spec/cassettes'
|
26
|
+
c.hook_into :webmock
|
27
|
+
c.filter_sensitive_data('<API_KEY>') do
|
28
|
+
test_api_key
|
29
|
+
end
|
30
|
+
c.configure_rspec_metadata!
|
31
|
+
end
|
32
|
+
|
33
|
+
RSpec.configure do |c|
|
34
|
+
c.treat_symbols_as_metadata_keys_with_true_values = true
|
35
|
+
end
|
36
|
+
|
37
|
+
def stub_get(url)
|
38
|
+
stub_request(:get, google_places_url(url))
|
39
|
+
end
|
40
|
+
|
41
|
+
def stub_post(url)
|
42
|
+
stub_request(:post, google_places_url(url))
|
43
|
+
end
|
44
|
+
|
45
|
+
def google_places_url(url)
|
46
|
+
"https://maps.googleapis.com/maps/api/place/#{url}/json?key=#{test_api_key}&sensor=false"
|
47
|
+
end
|
48
|
+
|
49
|
+
def place_reference
|
50
|
+
'CmRYAAAAciqGsTRX1mXRvuXSH2ErwW-jCINE1aLiwP64MCWDN5vkXvXoQGPKldMfmdGyqWS'\
|
51
|
+
'pm7BEYCgDm-iv7Kc2PF7QA7brMAwBbAcqMr5i1f4PwTpaovIZjysCEZTry8Ez30wpEhCN'\
|
52
|
+
'CXpynextCld2EBsDkRKsGhSLayuRyFsex6JA6NPh9dyupoTH3g'
|
53
|
+
end
|
54
|
+
|
55
|
+
def json_content_type
|
56
|
+
{ 'Content-type' => 'application/json' }
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_api_key
|
60
|
+
ENV.fetch('GOOGLE_PLACES_API_KEY', 'test_api_key')
|
61
|
+
end
|
62
|
+
|
63
|
+
def client
|
64
|
+
Lieu.new(api_key: test_api_key)
|
65
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
shared_examples 'an error' do |error|
|
2
|
+
error_class_name = error.split(/_/).map{ |word| word.capitalize }.join('')
|
3
|
+
exception = Lieu.const_get(error_class_name)
|
4
|
+
|
5
|
+
it "raising #{exception.name} when status is #{error}" do
|
6
|
+
VCR.turn_off!
|
7
|
+
|
8
|
+
endpoint = 'bigboombadaboum'
|
9
|
+
|
10
|
+
stub_get(endpoint).to_return(
|
11
|
+
body: { status: error }.to_json,
|
12
|
+
headers: json_content_type
|
13
|
+
)
|
14
|
+
|
15
|
+
expect { client.get(endpoint) }.to raise_error exception
|
16
|
+
|
17
|
+
VCR.turn_on!
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
shared_examples 'a http error' do |status_code, exception|
|
22
|
+
it "raising #{exception.name} when http status code is #{status_code}" do
|
23
|
+
VCR.turn_off!
|
24
|
+
|
25
|
+
endpoint = 'bigboombadaboum'
|
26
|
+
|
27
|
+
stub_get(endpoint).to_return(status: status_code)
|
28
|
+
|
29
|
+
expect { client.get(endpoint) }.to raise_error exception
|
30
|
+
|
31
|
+
VCR.turn_on!
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lieu
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aylic Petit
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
description: Simple Ruby wrapper for the Google places API.
|
28
|
+
email:
|
29
|
+
- sush@users.noreply.github.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- LICENSE
|
35
|
+
- README.md
|
36
|
+
- CONTRIBUTING.md
|
37
|
+
- Rakefile
|
38
|
+
- lieu.gemspec
|
39
|
+
- spec/lib/lieu/client/actions_spec.rb
|
40
|
+
- spec/lib/lieu/client/autocomplete_spec.rb
|
41
|
+
- spec/lib/lieu/client/details_spec.rb
|
42
|
+
- spec/lib/lieu/client/photo_spec.rb
|
43
|
+
- spec/lib/lieu/client/query_autocomplete_spec.rb
|
44
|
+
- spec/lib/lieu/client/search_spec.rb
|
45
|
+
- spec/lib/lieu/client_spec.rb
|
46
|
+
- spec/lib/lieu/request_spec.rb
|
47
|
+
- spec/lib/lieu_spec.rb
|
48
|
+
- spec/spec_helper.rb
|
49
|
+
- spec/support/shared_examples/error.rb
|
50
|
+
- lib/lieu/client/actions.rb
|
51
|
+
- lib/lieu/client/autocomplete.rb
|
52
|
+
- lib/lieu/client/details.rb
|
53
|
+
- lib/lieu/client/photos.rb
|
54
|
+
- lib/lieu/client/query_autocomplete.rb
|
55
|
+
- lib/lieu/client/search.rb
|
56
|
+
- lib/lieu/client.rb
|
57
|
+
- lib/lieu/configuration.rb
|
58
|
+
- lib/lieu/connection.rb
|
59
|
+
- lib/lieu/error.rb
|
60
|
+
- lib/lieu/request.rb
|
61
|
+
- lib/lieu/response/raise_error.rb
|
62
|
+
- lib/lieu/version.rb
|
63
|
+
- lib/lieu.rb
|
64
|
+
- spec/cassettes/Lieu_Client_Actions/_event_details/returns_an_event_details.yml
|
65
|
+
- spec/cassettes/Lieu_Client_Autocomplete/_autocomplete/returns_an_array_of_places.yml
|
66
|
+
- spec/cassettes/Lieu_Client_Details/_details/returns_a_place_details.yml
|
67
|
+
- spec/cassettes/Lieu_Client_Photos/_photo/returns_a_photo_image.yml
|
68
|
+
- spec/cassettes/Lieu_Client_QueryAutocomplete/_query_autocomplete/returns_an_array_of_places.yml
|
69
|
+
- spec/cassettes/Lieu_Client_Search/_nearby_search/returns_an_array_of_places.yml
|
70
|
+
- spec/cassettes/Lieu_Client_Search/_radarsearch/returns_an_array_of_places.yml
|
71
|
+
- spec/cassettes/Lieu_Client_Search/_textsearch/returns_an_array_of_places.yml
|
72
|
+
- spec/cassettes/Lieu_Request/given_a_GET_request/with_options/sets_options_as_url_parameters.yml
|
73
|
+
- spec/cassettes/Lieu_Request/given_a_POST_request/with_options/sets_options_as_body_parameters.yml
|
74
|
+
homepage: https://github.com/sush/lieu
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 1.9.2
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.1.0
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Google Places API Ruby wrapper
|
98
|
+
test_files:
|
99
|
+
- spec/cassettes/Lieu_Client_Actions/_event_details/returns_an_event_details.yml
|
100
|
+
- spec/cassettes/Lieu_Client_Autocomplete/_autocomplete/returns_an_array_of_places.yml
|
101
|
+
- spec/cassettes/Lieu_Client_Details/_details/returns_a_place_details.yml
|
102
|
+
- spec/cassettes/Lieu_Client_Photos/_photo/returns_a_photo_image.yml
|
103
|
+
- spec/cassettes/Lieu_Client_QueryAutocomplete/_query_autocomplete/returns_an_array_of_places.yml
|
104
|
+
- spec/cassettes/Lieu_Client_Search/_nearby_search/returns_an_array_of_places.yml
|
105
|
+
- spec/cassettes/Lieu_Client_Search/_radarsearch/returns_an_array_of_places.yml
|
106
|
+
- spec/cassettes/Lieu_Client_Search/_textsearch/returns_an_array_of_places.yml
|
107
|
+
- spec/cassettes/Lieu_Request/given_a_GET_request/with_options/sets_options_as_url_parameters.yml
|
108
|
+
- spec/cassettes/Lieu_Request/given_a_POST_request/with_options/sets_options_as_body_parameters.yml
|
109
|
+
- spec/lib/lieu/client/actions_spec.rb
|
110
|
+
- spec/lib/lieu/client/autocomplete_spec.rb
|
111
|
+
- spec/lib/lieu/client/details_spec.rb
|
112
|
+
- spec/lib/lieu/client/photo_spec.rb
|
113
|
+
- spec/lib/lieu/client/query_autocomplete_spec.rb
|
114
|
+
- spec/lib/lieu/client/search_spec.rb
|
115
|
+
- spec/lib/lieu/client_spec.rb
|
116
|
+
- spec/lib/lieu/request_spec.rb
|
117
|
+
- spec/lib/lieu_spec.rb
|
118
|
+
- spec/spec_helper.rb
|
119
|
+
- spec/support/shared_examples/error.rb
|
120
|
+
has_rdoc:
|