tescoProductSearch 2.2.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/tescoProductSearch.rb +75 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5e297f347c2cdc4e3e567eac87c95c25a35f9fed3d85ff92a38756127a36c3e0
4
+ data.tar.gz: a918d409c4a3dd99496ecf3daafcff3ddda1d64dd317adeb6731c34f20ddf598
5
+ SHA512:
6
+ metadata.gz: ebcd0e86420874d58561b547938732480ad3ee952c50c7f9410c8bb6bae3a9a0385f5a06d026cecec37ba71b2bedc8b536dc9f69c8e752c3450cfce1ddbab21c
7
+ data.tar.gz: 855f63c3f0d0d25970922edbec914bc3f8c929a15a49a9f578eee0232fc4cee96b84385dd910d1f374bfe841b7a441ff854a7c3f4564a2773eeb5b4077d31908
@@ -0,0 +1,75 @@
1
+ # Version 2.1.0
2
+
3
+ require 'net/http'
4
+ require 'json'
5
+
6
+
7
+ class TescoProductSearch
8
+ def self.find(string)
9
+
10
+ number = 5
11
+
12
+ uri = URI("https://dev.tescolabs.com/grocery/products/?query=#{string}&offset=0&limit=#{number}")
13
+
14
+ request = Net::HTTP::Get.new(uri.request_uri)
15
+ # Request headers
16
+ request['Ocp-Apim-Subscription-Key'] = '6e75f710286740aa8fbdb7bebef04143'
17
+ # Request body
18
+ request.body = "{body}"
19
+
20
+ response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
21
+ http.request(request)
22
+ end
23
+
24
+
25
+ array = Array.new
26
+
27
+ #puts response.body
28
+
29
+ product_results = JSON.parse(response.body);
30
+
31
+ count = product_results['uk']['ghs']['products']['results'].count
32
+
33
+ if count == 0
34
+
35
+ return 0
36
+
37
+ elsif count>=1 && count<=5
38
+
39
+ i = 0
40
+ loop do
41
+
42
+ # Create a hash for storing product details
43
+
44
+ result = Hash.new
45
+
46
+ result["price"] = (product_results['uk']['ghs']['products']['results'][i]['price'])
47
+ result["name"] = (product_results['uk']['ghs']['products']['results'][i]['name'])
48
+ result["desc"] = (product_results['uk']['ghs']['products']['results'][i]['description'])
49
+ result["image"] = (product_results['uk']['ghs']['products']['results'][i]['image'])
50
+ result["unitprice"] = (product_results['uk']['ghs']['products']['results'][i]['unitprice'])
51
+ result["quantity"] = (product_results['uk']['ghs']['products']['results'][i]['ContentsQuantity'])
52
+ result["unit"] = (product_results['uk']['ghs']['products']['results'][i]['ContentsMeasureType'])
53
+
54
+ #The hash is pushed into the array
55
+ array.push(result)
56
+
57
+ i += 1
58
+
59
+ if i == count
60
+ break # this will cause execution to exit the loop
61
+ end
62
+ end
63
+
64
+ # Returns the array of hashes as the end result
65
+
66
+ end
67
+
68
+ return array
69
+
70
+ end
71
+ end
72
+
73
+
74
+
75
+
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tescoProductSearch
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Lokesh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-12-06 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Fetches the product desciption, unit price, price, image, quantity of
14
+ a given product in Tesco UK stores. The price is fetched in GBP currency. Results
15
+ limited to 5
16
+ email: lokesh11292@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/tescoProductSearch.rb
22
+ homepage: http://rubygems.org/gems/tescoProductSearch
23
+ licenses: []
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubygems_version: 3.0.6
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Find the price of a given product in Tesco UK
44
+ test_files: []