locateStore 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/locateStore.rb +102 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0f917ba032e0ec5bd6da2a5c19be0adfd4f3a19d50cd27e9549cc025529644c8
|
4
|
+
data.tar.gz: 928ace557a87f324deea47ac16584cbdcfc4ccd149ec44d481e3cd62d7c58278
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8d190b545bbdb4d2b240aae576c44333cccd65c4622eb89a528058badbdf1fed8ac993b9872dc4813d1be364f57cb131c491dc42a5352f1cb6c9db8290c8226a
|
7
|
+
data.tar.gz: cc992141c54df39715c3bd7a7ddbf90653d98d89a66505b1c82c0039b617a61647ad90dad74b11c096572fd0f5d58ba201082046315bfe32d955c8b14c5ff535
|
data/lib/locateStore.rb
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
#perfectly working fine with test method at the end, includes address, includes distance
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
uri = URI('https://dev.tescolabs.com/locations/search')
|
7
|
+
|
8
|
+
class LocateStore
|
9
|
+
def self.find(string, number)
|
10
|
+
|
11
|
+
uri = URI('https://dev.tescolabs.com/locations/search')
|
12
|
+
query = URI.encode_www_form({
|
13
|
+
# Request parameters
|
14
|
+
'offset' => '0',
|
15
|
+
'limit' => '10',
|
16
|
+
'sort' => "near:#{string}",
|
17
|
+
})
|
18
|
+
|
19
|
+
|
20
|
+
array = Array.new
|
21
|
+
|
22
|
+
|
23
|
+
if uri.query && uri.query.length > 0
|
24
|
+
uri.query += '&' + query
|
25
|
+
else
|
26
|
+
uri.query = query
|
27
|
+
end
|
28
|
+
|
29
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
30
|
+
# Request headers
|
31
|
+
request['Ocp-Apim-Subscription-Key'] = '6e75f710286740aa8fbdb7bebef04143'
|
32
|
+
# Request body
|
33
|
+
request.body = "{body}"
|
34
|
+
|
35
|
+
#puts uri
|
36
|
+
|
37
|
+
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
|
38
|
+
http.request(request)
|
39
|
+
end
|
40
|
+
|
41
|
+
tesco_branches = JSON.parse(response.body);
|
42
|
+
|
43
|
+
i = 0
|
44
|
+
loop do
|
45
|
+
|
46
|
+
output = Hash.new
|
47
|
+
#branch = Array.new(i){Array.new(j)}
|
48
|
+
|
49
|
+
#puts branch_name = (tesco_branches['results'][i]['location']['name'])
|
50
|
+
|
51
|
+
output["name"] =(tesco_branches['results'][i]['location']['name'])
|
52
|
+
output["phone"] = (tesco_branches['results'][i]['location']['contact']['phoneNumbers'][0]['number'])
|
53
|
+
output["latitude"] = (tesco_branches['results'][i]['location']['geo']['coordinates']['latitude'])
|
54
|
+
output["longitude"] = (tesco_branches['results'][i]['location']['geo']['coordinates']['longitude'])
|
55
|
+
output["mon_open"] =(tesco_branches['results'][i]['location']['openingHours'][0]['standardOpeningHours']['mo']['open'])
|
56
|
+
output["mon_close"] =(tesco_branches['results'][i]['location']['openingHours'][0]['standardOpeningHours']['mo']['close'])
|
57
|
+
output["tues_open"] =(tesco_branches['results'][i]['location']['openingHours'][0]['standardOpeningHours']['tu']['open'])
|
58
|
+
output["tues_close"] =(tesco_branches['results'][i]['location']['openingHours'][0]['standardOpeningHours']['tu']['close'])
|
59
|
+
output["wed_open"] =(tesco_branches['results'][i]['location']['openingHours'][0]['standardOpeningHours']['we']['open'])
|
60
|
+
output["wed_close"] =(tesco_branches['results'][i]['location']['openingHours'][0]['standardOpeningHours']['we']['close'])
|
61
|
+
output["thurs_open"] =(tesco_branches['results'][i]['location']['openingHours'][0]['standardOpeningHours']['th']['open'])
|
62
|
+
output["thurs_close"] =(tesco_branches['results'][i]['location']['openingHours'][0]['standardOpeningHours']['th']['close'])
|
63
|
+
output["fri_open"] =(tesco_branches['results'][i]['location']['openingHours'][0]['standardOpeningHours']['fr']['open'])
|
64
|
+
output["fri_close"] =(tesco_branches['results'][i]['location']['openingHours'][0]['standardOpeningHours']['fr']['close'])
|
65
|
+
output["sat_open"] =(tesco_branches['results'][i]['location']['openingHours'][0]['standardOpeningHours']['sa']['open'])
|
66
|
+
output["sat_close"] =(tesco_branches['results'][i]['location']['openingHours'][0]['standardOpeningHours']['sa']['close'])
|
67
|
+
output["sun_open"] =(tesco_branches['results'][i]['location']['openingHours'][0]['standardOpeningHours']['su']['open'])
|
68
|
+
output["sun_close"] =(tesco_branches['results'][i]['location']['openingHours'][0]['standardOpeningHours']['su']['close'])
|
69
|
+
output["door_number"] = (tesco_branches['results'][i]['location']['contact']['address']['lines'][0]['lineNumber'])
|
70
|
+
output["address"] = (tesco_branches['results'][i]['location']['contact']['address']['lines'][0]['text'])
|
71
|
+
output["town"] = (tesco_branches['results'][i]['location']['contact']['address']['town'])
|
72
|
+
output["postcode"] = (tesco_branches['results'][i]['location']['contact']['address']['postcode'])
|
73
|
+
output["distance"] = (tesco_branches['results'][i]['distanceFrom']['value'])
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
#puts output["name"]
|
78
|
+
array.push(output)
|
79
|
+
|
80
|
+
|
81
|
+
i += 1
|
82
|
+
|
83
|
+
if i == number
|
84
|
+
break # this will cause execution to exit the loop
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
#puts array[0]["name"]
|
90
|
+
#puts array[1]["name"]
|
91
|
+
#puts array[2]["name"]
|
92
|
+
#puts array[3]["name"]
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
return array
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: locateStore
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 3.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- GSK
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-11-17 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Finds the nearby tesco stores as per given location and return n no.
|
14
|
+
of stores
|
15
|
+
email: suryajapan@email.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/locateStore.rb
|
21
|
+
homepage: http://rubygems.org/gems/locateStore
|
22
|
+
licenses: []
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubygems_version: 3.0.6
|
40
|
+
signing_key:
|
41
|
+
specification_version: 4
|
42
|
+
summary: Find nearby Tesco stores, with address and distance from. Does not print
|
43
|
+
results
|
44
|
+
test_files: []
|