tescoStoreLocator 1.0.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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/tescoStoreLocator.rb +88 -0
  3. metadata +44 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: dd75d1b6f386219b2648d959f04cc0950d438e14aeb3cf263087f47c8762f231
4
+ data.tar.gz: 8e87d7ce4fd55f3c589cd9d1b39de3d708a54c450302929d6aa373ccd13f21f9
5
+ SHA512:
6
+ metadata.gz: 1a4da07210812f1adbe63b41d5e36caf70ff9b3092b28664d9de3dcdd74d906f213fd24420704b2853096d4ebd04ad3a1ac75db5656662d81d8f73f4bb5eebe3
7
+ data.tar.gz: a41a79f77a71ac58a17e2b808e13a25abfbca37edb05e7850e626ac301ce965a2e481352086dc3779c9b2434b02704c1e5ebcd8dd76ddbe55c4930e212957578
@@ -0,0 +1,88 @@
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
+
10
+ def self.find(string, number)
11
+
12
+ uri = URI('https://dev.tescolabs.com/locations/search')
13
+ query = URI.encode_www_form({
14
+ # Request parameters
15
+ 'offset' => '0',
16
+ 'limit' => '10',
17
+ 'sort' => "near:#{string}",
18
+ })
19
+
20
+
21
+ array = Array.new
22
+
23
+
24
+ if uri.query && uri.query.length > 0
25
+ uri.query += '&' + query
26
+ else
27
+ uri.query = query
28
+ end
29
+
30
+ request = Net::HTTP::Get.new(uri.request_uri)
31
+ # Request headers
32
+ request['Ocp-Apim-Subscription-Key'] = '6e75f710286740aa8fbdb7bebef04143'
33
+ # Request body
34
+ request.body = "{body}"
35
+
36
+ #puts uri
37
+
38
+ response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
39
+ http.request(request)
40
+ end
41
+
42
+ tesco_branches = JSON.parse(response.body);
43
+
44
+ i = 0
45
+ loop do
46
+
47
+ output = Hash.new
48
+
49
+ output["name"] =(tesco_branches['results'][i]['location']['name'])
50
+ output["phone"] = (tesco_branches['results'][i]['location']['contact']['phoneNumbers'][0]['number'])
51
+ output["latitude"] = (tesco_branches['results'][i]['location']['geo']['coordinates']['latitude'])
52
+ output["longitude"] = (tesco_branches['results'][i]['location']['geo']['coordinates']['longitude'])
53
+ output["mon_open"] =(tesco_branches['results'][i]['location']['openingHours'][0]['standardOpeningHours']['mo']['open'])
54
+ output["mon_close"] =(tesco_branches['results'][i]['location']['openingHours'][0]['standardOpeningHours']['mo']['close'])
55
+ output["tues_open"] =(tesco_branches['results'][i]['location']['openingHours'][0]['standardOpeningHours']['tu']['open'])
56
+ output["tues_close"] =(tesco_branches['results'][i]['location']['openingHours'][0]['standardOpeningHours']['tu']['close'])
57
+ output["wed_open"] =(tesco_branches['results'][i]['location']['openingHours'][0]['standardOpeningHours']['we']['open'])
58
+ output["wed_close"] =(tesco_branches['results'][i]['location']['openingHours'][0]['standardOpeningHours']['we']['close'])
59
+ output["thurs_open"] =(tesco_branches['results'][i]['location']['openingHours'][0]['standardOpeningHours']['th']['open'])
60
+ output["thurs_close"] =(tesco_branches['results'][i]['location']['openingHours'][0]['standardOpeningHours']['th']['close'])
61
+ output["fri_open"] =(tesco_branches['results'][i]['location']['openingHours'][0]['standardOpeningHours']['fr']['open'])
62
+ output["fri_close"] =(tesco_branches['results'][i]['location']['openingHours'][0]['standardOpeningHours']['fr']['close'])
63
+ output["sat_open"] =(tesco_branches['results'][i]['location']['openingHours'][0]['standardOpeningHours']['sa']['open'])
64
+ output["sat_close"] =(tesco_branches['results'][i]['location']['openingHours'][0]['standardOpeningHours']['sa']['close'])
65
+ output["sun_open"] =(tesco_branches['results'][i]['location']['openingHours'][0]['standardOpeningHours']['su']['open'])
66
+ output["sun_close"] =(tesco_branches['results'][i]['location']['openingHours'][0]['standardOpeningHours']['su']['close'])
67
+ output["door_number"] = (tesco_branches['results'][i]['location']['contact']['address']['lines'][0]['lineNumber'])
68
+ output["address"] = (tesco_branches['results'][i]['location']['contact']['address']['lines'][0]['text'])
69
+ output["town"] = (tesco_branches['results'][i]['location']['contact']['address']['town'])
70
+ output["postcode"] = (tesco_branches['results'][i]['location']['contact']['address']['postcode'])
71
+ output["distance"] = (tesco_branches['results'][i]['distanceFrom']['value'])
72
+
73
+ array.push(output)
74
+
75
+ i += 1
76
+
77
+ if i == number
78
+ break # this will cause execution to exit the loop
79
+ end
80
+
81
+ end
82
+
83
+ return array
84
+
85
+ end
86
+
87
+ end
88
+
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tescoStoreLocator
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - GSK
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-12-10 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/tescoStoreLocator.rb
21
+ homepage: http://rubygems.org/gems/tescoStoreLocator
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: []