tesco_rb 0.3.0 → 0.3.1
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.
- checksums.yaml +4 -4
- data/README.org +28 -30
- data/lib/tesco_rb/item.rb +25 -12
- data/lib/tesco_rb/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7f45235349a6c97a462c17563cef742995d5e760
|
|
4
|
+
data.tar.gz: 2a84f7af983f2869b1ae863f9ed8d9ea5a7a0d03
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 47c75eab9ffae157b2a74baa5ec8fea10607e0de4c3b60c5030464d3153321f05db3bd2f59c90028963e98e96f8cb329959cfed343854b31c94354c8de5b9768
|
|
7
|
+
data.tar.gz: e709ab1cf533fd9c12affd8c937e9cb10fa1256e63d2cf674ad91d6e0f844d37fb2de61d8aef76ca4551a88b8a12432baed620564c3255b54c3d4ba94e6b4c21
|
data/README.org
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
* TescoRb
|
|
2
|
+
[[https://api.travis-ci.org/wmmc/tesco_rb.svg]]
|
|
3
|
+
|
|
2
4
|
A ruby gem for interacting with the [[https://devportal.tescolabs.com/docs/services/][Tesco Api]].
|
|
3
5
|
Currently it supports [[https://devportal.tescolabs.com/docs/services/56c73b1bf205fd0ed81dbe7a][Grocery]] & [[https://devportal.tescolabs.com/docs/services/5731ed21611a4b2968547c5f][Store Location]] end points.
|
|
4
6
|
|
|
@@ -9,19 +11,19 @@ client = TescoRb.new(YOUR_API_KEY)
|
|
|
9
11
|
|
|
10
12
|
# To search for items:
|
|
11
13
|
client.search('bananas')
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
#
|
|
21
|
-
#
|
|
22
|
-
#
|
|
23
|
-
#
|
|
24
|
-
#
|
|
14
|
+
# => [#<TescoRb::Item:0x007fae80828fa8
|
|
15
|
+
# @AverageSellingUnitWeight=2.402,
|
|
16
|
+
# @ContentsMeasureType="KG",
|
|
17
|
+
# @ContentsQuantity=1.0,
|
|
18
|
+
# @PromotionDescription="25 extra points on any bananas",
|
|
19
|
+
# @UnitOfSale=3,
|
|
20
|
+
# @UnitQuantity="KG",
|
|
21
|
+
# @image="http://img.tesco.com/Groceries/pi/000/0261480000000/IDShot_90x90.jpg",
|
|
22
|
+
# @name="Tesco Bananas Loose",
|
|
23
|
+
# @price=0.68,
|
|
24
|
+
# @tpnb=50502269,
|
|
25
|
+
# @unitprice=0.68>
|
|
26
|
+
# ..... ]
|
|
25
27
|
|
|
26
28
|
# Another way to search for items:
|
|
27
29
|
client.item(query: 'bananas', limit: 10) # page 1
|
|
@@ -33,19 +35,19 @@ client.store(near: 'SW5 4YY', limit: 5)
|
|
|
33
35
|
client.store(filter: 'isoCountryCode:GB AND category:Store AND facilities:DBT')
|
|
34
36
|
|
|
35
37
|
# An example shop:
|
|
36
|
-
#
|
|
37
|
-
#
|
|
38
|
-
#
|
|
39
|
-
#
|
|
40
|
-
#
|
|
41
|
-
#
|
|
42
|
-
#
|
|
43
|
-
#
|
|
44
|
-
#
|
|
45
|
-
#
|
|
46
|
-
#
|
|
47
|
-
#
|
|
48
|
-
#
|
|
38
|
+
# <TescoRb::Store:0x007fae80ca1ad0
|
|
39
|
+
# @address=
|
|
40
|
+
# #<TescoRb::Address:0x007fae80ca1300
|
|
41
|
+
# @lines=
|
|
42
|
+
# [{"lineNumber"=>1, "text"=>"87-93 Gloucester Rd"},
|
|
43
|
+
# {"lineNumber"=>2, "text"=>"South Kensington"}],
|
|
44
|
+
# @postcode="SW7 4SS",
|
|
45
|
+
# @town="London">,
|
|
46
|
+
# @altIds={"branchNumber"=>2745},
|
|
47
|
+
# @classification={"type"=>"Express", "category"=>"Store"},
|
|
48
|
+
# @facilities=[]
|
|
49
|
+
# @region={"isoCountryCode"=>"GB"},
|
|
50
|
+
# @status={"currentStatus"=>"Trading"}>
|
|
49
51
|
#+END_SRC
|
|
50
52
|
|
|
51
53
|
** Installation
|
|
@@ -69,11 +71,7 @@ $ gem install tesco_rb
|
|
|
69
71
|
#+END_SRC
|
|
70
72
|
|
|
71
73
|
*** Todo
|
|
72
|
-
- ~client.item.search('bananas')~ syntax; add ~.search~ method
|
|
73
|
-
- This would involve creating new 'items' holding class (currently just an Array)
|
|
74
74
|
- DRY / subclass requesters
|
|
75
|
-
- Sort out travis CI
|
|
76
|
-
- More examples about returned objects??
|
|
77
75
|
- OpeningHours Object
|
|
78
76
|
- GeoLocation Object
|
|
79
77
|
- Get rid of linting errors
|
data/lib/tesco_rb/item.rb
CHANGED
|
@@ -5,24 +5,37 @@ module TescoRb
|
|
|
5
5
|
class Item
|
|
6
6
|
include RepresentationHelper
|
|
7
7
|
|
|
8
|
-
def
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
ContentsQuantity price unitprice)
|
|
8
|
+
def initialize(json)
|
|
9
|
+
item = json.each.with_object({}) { |(k, v), hash| hash[underscore(k)] = v }
|
|
10
|
+
create_attr_readers_for item.keys
|
|
11
|
+
set item.keys, item
|
|
13
12
|
end
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
def ==(other)
|
|
15
|
+
instance_variables.all? do |method_name|
|
|
16
|
+
current_var = instance_variable_get method_name.to_sym
|
|
17
|
+
other_var = other.instance_variable_get method_name.to_sym
|
|
18
|
+
current_var == other_var
|
|
19
|
+
end
|
|
19
20
|
end
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def create_attr_readers_for(keys)
|
|
25
|
+
keys.map! { |i| underscore(i) }
|
|
26
|
+
keys.each do |key|
|
|
27
|
+
self.class.class_eval("def #{key};@#{key};end")
|
|
24
28
|
end
|
|
25
29
|
end
|
|
26
30
|
|
|
31
|
+
# kind of nabbed from ActiveSupport
|
|
32
|
+
def underscore(word)
|
|
33
|
+
word.to_s.gsub(/::/, '/').
|
|
34
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
|
35
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
|
36
|
+
tr("-", "_").
|
|
37
|
+
downcase
|
|
38
|
+
end
|
|
39
|
+
|
|
27
40
|
end
|
|
28
41
|
end
|
data/lib/tesco_rb/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tesco_rb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- William Clarke
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-08-
|
|
11
|
+
date: 2016-08-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: httparty
|