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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 864370413f5c959a91d3013c2bbd89418211b8fc
4
- data.tar.gz: 889d9b0e0749aa56cfe5c66a839852afb68a646d
3
+ metadata.gz: 7f45235349a6c97a462c17563cef742995d5e760
4
+ data.tar.gz: 2a84f7af983f2869b1ae863f9ed8d9ea5a7a0d03
5
5
  SHA512:
6
- metadata.gz: 329bebb51663f4e98febdaf0f13df7e939e245c86245ae2403affbdfe4b4c6937c5034bc161823295e19f76ccbc1c89ec540ed6b74af81a2cec909b6d348f8d5
7
- data.tar.gz: f35088360d515cbd29951eeedd33ae24b81d276c88c1f0fad2f0f9ad24f89b3c09c3a4fef831085fc4d0ed3a844acdfcca329b481855f7605bb7b06616c69497
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
- # => [#<TescoRb::Item:0x007fae80828fa8
13
- # @AverageSellingUnitWeight=2.402,
14
- # @ContentsMeasureType="KG",
15
- # @ContentsQuantity=1.0,
16
- # @PromotionDescription="25 extra points on any bananas",
17
- # @UnitOfSale=3,
18
- # @UnitQuantity="KG",
19
- # @image="http://img.tesco.com/Groceries/pi/000/0261480000000/IDShot_90x90.jpg",
20
- # @name="Tesco Bananas Loose",
21
- # @price=0.68,
22
- # @tpnb=50502269,
23
- # @unitprice=0.68>
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
- # <TescoRb::Store:0x007fae80ca1ad0
37
- # @address=
38
- # #<TescoRb::Address:0x007fae80ca1300
39
- # @lines=
40
- # [{"lineNumber"=>1, "text"=>"87-93 Gloucester Rd"},
41
- # {"lineNumber"=>2, "text"=>"South Kensington"}],
42
- # @postcode="SW7 4SS",
43
- # @town="London">,
44
- # @altIds={"branchNumber"=>2745},
45
- # @classification={"type"=>"Express", "category"=>"Store"},
46
- # @facilities=[]
47
- # @region={"isoCountryCode"=>"GB"},
48
- # @status={"currentStatus"=>"Trading"}>
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 self.fields
9
- %I( image tpnb PromotionDescription
10
- ContentsMeasureType name UnitOfSale
11
- AverageSellingUnitWeight UnitQuantity
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
- attr_reader(*fields)
16
-
17
- def initialize(location)
18
- set self.class.fields, location
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
- def ==(other)
22
- self.class.fields.all? do |method_name|
23
- send(method_name) == other.send(method_name)
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
@@ -1,3 +1,3 @@
1
1
  module TescoRb
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
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.0
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-21 00:00:00.000000000 Z
11
+ date: 2016-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty