RDC 0.1.0 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a07c12269137a5a3dd6bca0cb50d26713609cf1cc7144701cb14a37cfb9b7bd9
4
- data.tar.gz: 57a9febb60d4f25cb0822b38f323666ae471bf3acaad973cd7400e2ddceca99b
3
+ metadata.gz: b304c3994e05cc433c8af2a88279842a90e015b4d3fe5c46211f47cbcdf85960
4
+ data.tar.gz: 849dbf400f434d904bc1e9db349804b301b82272fa5e4169b28088f8c78372c1
5
5
  SHA512:
6
- metadata.gz: d07f8b8b20af061fa3882baf073ae00eab0b7a8fd1c760037ef50a17ae14f2ee16dfff21af7af591b6d9f9c65638b9df427b0b7234f62c70a6e96dc158fe56af
7
- data.tar.gz: 9320d4073c1d2d3e77f9b8e3119734f5cd51033b935e61e1eaf9134e9d5bea5d8930c494b9af3c27db8629977c83110c0bd604dc3f20da802afc15737ae18cf2
6
+ metadata.gz: '04779a8892fa805fb7844a1a4073b6964f0b82a200ebf0b38b001a3243db11e6237175e262ee5ec0fc084ba21fb04932f0e27c2ac6fdfc20995f7566835c0889'
7
+ data.tar.gz: 8408ea6af6f11a3a646bbda0a0451b9cb1124db1bd179e97c93590c8358bb081d0c9cab548f196183aac9117c50cde1a69f094981c610ca60a94f76892c30b2e
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- RDC (0.1.0)
4
+ RDC (0.1.4)
5
5
  activesupport (= 5.2.3)
6
6
  net-sftp (= 3.0.0)
7
- rubyzip (= 2.3.0)
7
+ rubyzip
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
@@ -89,4 +89,4 @@ DEPENDENCIES
89
89
  webmock
90
90
 
91
91
  BUNDLED WITH
92
- 2.1.2
92
+ 2.1.4
data/lib/RDC.rb CHANGED
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "RDC/version"
2
4
  require "RDC/catalog"
3
- require "RDC/restaurant_info"
5
+ require "RDC/order"
6
+ require "RDC/sku"
7
+ require "RDC/cart"
4
8
 
5
9
  module RDC
6
10
  class Error < StandardError; end
@@ -8,6 +12,7 @@ module RDC
8
12
  class << self
9
13
  attr_accessor :api_key, :environment
10
14
  attr_accessor :ftp_username, :ftp_password, :ftp_url
15
+ attr_accessor :prti
11
16
 
12
17
  def root
13
18
  File.dirname __dir__
@@ -5,9 +5,9 @@ require 'RDC/request'
5
5
  module RDC
6
6
  class Cart
7
7
  class << self
8
- def create(sku_id)
9
- request = Request.new("/validate_sku?sku=#{sku_id}")
10
- reponse = request.get
8
+ def create(params)
9
+ request = Request.new("/create_shopping_cart_id")
10
+ reponse = request.get(params)
11
11
  response.json
12
12
  end
13
13
  end
@@ -16,42 +16,38 @@ module RDC
16
16
  end
17
17
 
18
18
  def download_xml_catalog
19
- puts '[RDC] Start Downloading ZIP File from FTP Server.'
20
19
  Net::SFTP.start(RDC.ftp_url, RDC.ftp_username, password: RDC.ftp_password) do |sftp|
21
20
  sftp.download!('/rdc_MemberHub.zip', downloads_directory.join('rdc_MemberHub.zip').to_s)
22
21
  end
23
- puts '[RDC] Finished Downloading ZIP File from FTP Server.'
24
22
  end
25
23
 
26
24
  def extract_zip_file
27
- puts '[RDC] Starting Extracting XML File from ZIP File.'
28
25
  Zip::File.open(downloads_directory.join('rdc_MemberHub.zip')) do |zip_file|
29
26
  zip_file.each do |f|
30
27
  fpath = File.join(downloads_directory.to_s, f.name)
31
28
  zip_file.extract(f, fpath) unless File.exist?(fpath)
32
29
  end
33
30
  end
34
- puts '[RDC] Done Extracting XML File from ZIP File.'
35
31
  end
36
32
 
37
33
  def parse_xml_file
38
- puts '[RDC] Parsing XML'
39
34
  xml_file_path = downloads_directory.join('rdc_MemberHub.xml')
40
35
  @xml = Hash.from_xml(File.open(xml_file_path))
41
- puts '[RDC] Finished parsing XML'
42
36
  end
43
37
 
44
38
  def process_xml_content
45
- puts '[RDC] Starting XML Processing'
46
39
  @catalog = @xml["Catalogs"]["catalog"].collect { |catalog_hash| RDC::Restaurant.new(catalog_hash) }
47
- puts '[RDC] Finished XML Processing'
48
40
  @catalog
49
41
  end
50
42
 
51
43
  private
52
44
 
53
45
  def downloads_directory
54
- @downloads_directory ||= Pathname.new(RDC.root).join('downloads')
46
+ @downloads_directory ||= begin
47
+ directory = Pathname.new(RDC.root).join('downloads')
48
+ FileUtils.mkdir_p directory
49
+ directory
50
+ end
55
51
  end
56
52
  end
57
53
  end
@@ -2,16 +2,17 @@
2
2
 
3
3
  module RDC
4
4
  class Item
5
- attr_accessor :sku, :legacy_sku, :value, :price, :restriction, :restriction_detail
5
+ attr_accessor :sku, :legacy_sku, :value, :price, :restriction, :restriction_detail,
6
+ :available_inventory
6
7
 
7
8
  def initialize(hash_values)
8
- puts "Hash Values :: #{hash_values}"
9
9
  @sku = hash_values['ProductSKU']
10
10
  @legacy_sku = hash_values['LegacyProductSKU']
11
11
  @value = hash_values['ItemValue']
12
12
  @price = hash_values['ItemPrice']
13
13
  @restriction = hash_values['ItemRestriction']
14
14
  @restriction_detail = hash_values['ItemRestrictionDetail']
15
+ @available_inventory = hash_values['ItemAvailableInventory']
15
16
  end
16
17
  end
17
18
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'request'
4
+
5
+ module RDC
6
+ class Order
7
+ class << self
8
+ def process_order_body(params = {})
9
+ request = Request.new("/process_order_body")
10
+ response = request.post(params.merge(prti_params(params)))
11
+ response.json
12
+ end
13
+
14
+ private
15
+
16
+ def prti_params(params)
17
+ {
18
+ prti: RDC.prti,
19
+ partneradid: RDC.prti
20
+ }
21
+ end
22
+ end
23
+ end
24
+ end
@@ -12,9 +12,9 @@ module RDC
12
12
 
13
13
  def base_url
14
14
  if RDC.environment == 'production'
15
- 'http://connect.restaurant.com/api'
15
+ 'http://connect.restaurant.com/api'.freeze
16
16
  else
17
- 'https://dev-connect.restaurant.com/api'
17
+ 'https://dev-connect.restaurant.com/api'.freeze
18
18
  end
19
19
  end
20
20
 
@@ -25,6 +25,13 @@ module RDC
25
25
  self
26
26
  end
27
27
 
28
+ def post(params = {})
29
+ self.response = HTTP.headers(headers)
30
+ .post(url, { json: params })
31
+ self.json = JSON.parse(response.body.to_s, symbolize_names: true)
32
+ self
33
+ end
34
+
28
35
  def url
29
36
  "#{base_url}#{path}"
30
37
  end
@@ -5,16 +5,22 @@ require_relative 'item'
5
5
  module RDC
6
6
  class Restaurant
7
7
  attr_accessor :name, :items, :short_description, :long_description,
8
- :online, :address, :image
8
+ :online, :address, :image, :id, :communication_media,
9
+ :recommended_rank, :rating, :cuisines, :additional_attributes
9
10
 
10
11
  def initialize(hash_values)
11
- puts "Initializing Restaurant #{hash_values['RestaurantName']}"
12
+ @id = hash_values['LegacyRestaurantId']
12
13
  @name = hash_values['RestaurantName']
13
14
  @short_description = hash_values['ShortDescription']
14
15
  @long_description = hash_values['LongDescription']
15
16
  @online = hash_values['OnlineReservation']
17
+ @recommended_rank = hash_values['RecommendedRank']
18
+ @rating = hash_values['Rating']
19
+ @cuisines = hash_values['Cuisine']
20
+ @additional_attributes = hash_values['Attributes']
16
21
 
17
22
  @address = hash_values['LocationAddress']
23
+ @communication_media = hash_values['CommunicationMedia']
18
24
  @image = hash_values.dig('CatalogImagesFullPath', 'MainLogo')
19
25
  @items = Array.wrap(hash_values.dig('Items', 'Item')).collect { |item_hash| RDC::Item.new(item_hash) }
20
26
  end
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'RDC/request'
3
+ require_relative 'request'
4
4
 
5
5
  module RDC
6
6
  class RestaurantInfo
7
7
  class << self
8
8
  def retrieve(restaurant_id)
9
9
  request = Request.new("/restaurant_info/#{restaurant_id}")
10
- reponse = request.get
10
+ response = request.get
11
11
  response.json
12
12
  end
13
13
  end
@@ -1,19 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'RDC/request'
3
+ require_relative 'request'
4
4
 
5
5
  module RDC
6
6
  class Sku
7
7
  class << self
8
8
  def validate(sku_id)
9
- request = Request.new("/validate_sku?sku=#{sku_id}")
10
- reponse = request.get
9
+ request = Request.new("/validate_sku/?sku=#{sku_id}")
10
+ response = request.get
11
11
  response.json
12
12
  end
13
13
 
14
14
  def verify_inventory_and_price(skus)
15
- request = Request.new("/verify_inventory_and_price?sku=#{skus}")
16
- reponse = request.get
15
+ request = Request.new("/verify_inventory_and_price/?sku=#{skus}")
16
+ response = request.get
17
17
  response.json
18
18
  end
19
19
  end
@@ -1,3 +1,3 @@
1
1
  module RDC
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: RDC
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - davidrichey
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2020-12-03 00:00:00.000000000 Z
12
+ date: 2020-12-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -75,6 +75,7 @@ files:
75
75
  - lib/RDC/cart.rb
76
76
  - lib/RDC/catalog.rb
77
77
  - lib/RDC/item.rb
78
+ - lib/RDC/order.rb
78
79
  - lib/RDC/request.rb
79
80
  - lib/RDC/restaurant.rb
80
81
  - lib/RDC/restaurant_info.rb
@@ -102,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
103
  - !ruby/object:Gem::Version
103
104
  version: '0'
104
105
  requirements: []
105
- rubygems_version: 3.0.3
106
+ rubygems_version: 3.1.2
106
107
  signing_key:
107
108
  specification_version: 4
108
109
  summary: Ruby gem that wraps restaurants.com API