santa_maria-product_importer 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1412496366478bf720a9bbf0b14eb3b39468882a
4
+ data.tar.gz: 7a687c0fc18583ea5f39abce255673b68ef1063c
5
+ SHA512:
6
+ metadata.gz: eb55eef8a8aad0e294d2a4de9f6862f2150f8307f54a5a0106bbbe436e3e268ee229c2d1a3f66a38d682ef91701de051715fecc6456cc6f38e1c7bab5f2dea83
7
+ data.tar.gz: 885017558dc416e3becf44543e553055d099557c58b1e4d99bb17cbaae6c8ade46cee866779b91eea27a31f5ac39af628675570f41252fe36d99898f9f3a57b8
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ .idea
13
+
14
+ bin/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ - 2.5.0
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in santa_maria-product_importer.gemspec
6
+ gemspec
@@ -0,0 +1,47 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ santa_maria-product_importer (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.5.2)
10
+ public_suffix (>= 2.0.2, < 4.0)
11
+ crack (0.4.3)
12
+ safe_yaml (~> 1.0.0)
13
+ diff-lcs (1.3)
14
+ hashdiff (0.3.7)
15
+ public_suffix (3.0.1)
16
+ rake (10.5.0)
17
+ rspec (3.7.0)
18
+ rspec-core (~> 3.7.0)
19
+ rspec-expectations (~> 3.7.0)
20
+ rspec-mocks (~> 3.7.0)
21
+ rspec-core (3.7.1)
22
+ rspec-support (~> 3.7.0)
23
+ rspec-expectations (3.7.0)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.7.0)
26
+ rspec-mocks (3.7.0)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.7.0)
29
+ rspec-support (3.7.0)
30
+ safe_yaml (1.0.4)
31
+ webmock (2.3.2)
32
+ addressable (>= 2.3.6)
33
+ crack (>= 0.3.2)
34
+ hashdiff
35
+
36
+ PLATFORMS
37
+ ruby
38
+
39
+ DEPENDENCIES
40
+ bundler (~> 1.16)
41
+ rake (~> 10.0)
42
+ rspec (~> 3.0)
43
+ santa_maria-product_importer!
44
+ webmock (~> 2.0)
45
+
46
+ BUNDLED WITH
47
+ 1.16.1
@@ -0,0 +1,7 @@
1
+ # SantaMaria ProductImporter [![Build Status](https://travis-ci.org/madetech/santa_maria-product_importer.svg?branch=master)](https://travis-ci.org/madetech/santa_maria-product_importer)
2
+
3
+ This provides a consistent Ruby interface around SantaMaria APIs.
4
+
5
+ # Release
6
+
7
+ `bundle exec rake release`
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,15 @@
1
+ module SantaMaria
2
+ module Domain
3
+ class Product
4
+ attr_accessor :global_id, :type, :name, :uri_name, :description, :image_url
5
+
6
+ def initialize(variant_accessor)
7
+ @variant_accessor = variant_accessor
8
+ end
9
+
10
+ def variants
11
+ @variant_accessor.variants_for(global_id)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,29 @@
1
+ module SantaMaria
2
+ module Domain
3
+ class Variant
4
+ attr_accessor :article_number,
5
+ :price,
6
+ :color_id,
7
+ :pack_size,
8
+ :pattern,
9
+ :ean,
10
+ :name
11
+
12
+ attr_writer :valid,
13
+ :on_sale,
14
+ :ready_mix
15
+
16
+ def valid?
17
+ @valid
18
+ end
19
+
20
+ def on_sale?
21
+ @on_sale
22
+ end
23
+
24
+ def ready_mix?
25
+ @ready_mix
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,50 @@
1
+ module SantaMaria
2
+ module Gateway
3
+ class SantaMariaLegacy
4
+ def initialize(endpoint)
5
+
6
+ end
7
+
8
+ def all_products
9
+ response = Net::HTTP.get_response(URI('https://api/api/products/eukdlx'))
10
+
11
+ result = JSON.parse(response.body)
12
+
13
+
14
+ result['products'].each do |p|
15
+ product = SantaMaria::Domain::Product.new(self)
16
+ product.global_id = p['globalId']
17
+ product.type = p['productType']
18
+ product.name = p['name']
19
+ product.uri_name = p['uriFriendlyName']
20
+ product.description = p['localSlogan']
21
+ product.image_url = p.dig('packshots', 'm')
22
+
23
+ yield product
24
+ end
25
+ end
26
+
27
+ def variants_for(global_id)
28
+ response = Net::HTTP.get_response(URI("https://api/api/products/eukdlx/#{global_id}"))
29
+
30
+ product = JSON.parse(response.body)
31
+
32
+ product['packages'].map do |package|
33
+ variant = SantaMaria::Domain::Variant.new
34
+ variant.article_number = package['articleNumber']
35
+ variant.price = package['price']
36
+ variant.name = package['colorTranslation']
37
+ variant.color_id = package['colorId']
38
+ variant.pack_size = package['friendlyPackSize']
39
+ variant.pattern = package['patternId']
40
+ variant.ean = package['EANCode']
41
+ variant.valid = package['validEcomData']
42
+ variant.on_sale = package['readyForSale']
43
+ variant.ready_mix = !package['tintedOrReadyMix'].eql?('Tinted')
44
+
45
+ variant
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,71 @@
1
+ module SantaMaria
2
+ module Gateway
3
+ class SantaMariaV2
4
+ def initialize(endpoint)
5
+
6
+ end
7
+
8
+ def all_products
9
+ response = Net::HTTP.get_response(URI('https://api/api/v2/products'))
10
+
11
+ result = JSON.parse(response.body)
12
+
13
+
14
+ result['products'].each do |product|
15
+ yield new_product(product)
16
+ end
17
+ end
18
+
19
+ def variants_for(global_id)
20
+ response = Net::HTTP.get_response(URI("https://api/api/v2/products/#{global_id}"))
21
+
22
+ product = JSON.parse(response.body)
23
+
24
+ variants = []
25
+
26
+ product['sku'].each do |sku|
27
+ if sku['colorIds'].nil?
28
+ variants << new_variant(sku)
29
+ else
30
+ sku['colorIds'].each do |color|
31
+ variant = new_variant(sku)
32
+
33
+ variant.name = color.dig('colorCollectionColors', 0, 'colorTranslation')
34
+ variant.color_id = color.dig('colorCollectionColors', 0, 'colorCollectionColorID')
35
+
36
+ variants << variant
37
+ end
38
+ end
39
+ end
40
+
41
+ variants
42
+ end
43
+
44
+ private
45
+
46
+ def new_product(product_data)
47
+ product = SantaMaria::Domain::Product.new(self)
48
+ product.global_id = product_data['globalId']
49
+ product.type = product_data['productType']
50
+ product.name = product_data['name']
51
+ product.uri_name = product_data['uri']
52
+ product.description = product_data['localSlogan']
53
+ product.image_url = product_data.dig('packshots', 0, 'm')
54
+ product
55
+ end
56
+
57
+ def new_variant(sku)
58
+ variant = SantaMaria::Domain::Variant.new
59
+ variant.article_number = sku['articleNumber']
60
+ variant.price = sku['price']
61
+ variant.pack_size = sku['friendlyPackSizeTranslation']
62
+ variant.pattern = sku.dig('pattern', 0, 'name')
63
+ variant.ean = sku['eanCode']
64
+ variant.valid = sku['validEcomData']
65
+ variant.on_sale = sku['readyForSale']
66
+ variant.ready_mix = !sku['tintedOrReadyMix'].eql?('Tinted')
67
+ variant
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,5 @@
1
+ module SantaMaria
2
+ module ProductImporter
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,48 @@
1
+ module SantaMaria
2
+ module UseCase
3
+ class FetchProducts
4
+ def initialize(santa_maria:)
5
+ @santa_maria = santa_maria
6
+ end
7
+
8
+ def execute(presenter)
9
+ products = []
10
+ santa_maria.all_products do |product|
11
+ presenter.product(
12
+ id: product.global_id,
13
+ type: product.type,
14
+ name: product.name,
15
+ uri_name: product.uri_name,
16
+ description: product.description,
17
+ image_url: product.image_url
18
+ )
19
+ products << product
20
+ end
21
+
22
+ products.each do |product|
23
+ product.variants.each do |variant|
24
+ presenter.variant(
25
+ id: product.global_id,
26
+ article_number: variant.article_number,
27
+ price: variant.price,
28
+ valid: variant.valid?,
29
+ on_sale: variant.on_sale?,
30
+ color_id: variant.color_id == '' ? nil : variant.color_id,
31
+ ready_mix: variant.ready_mix?,
32
+ pack_size: variant.pack_size,
33
+ pattern: variant.pattern == '' ? nil : variant.pattern,
34
+ ean: variant.ean == '' ? nil : variant.ean,
35
+ name: variant.name
36
+ )
37
+ end
38
+ end
39
+
40
+ {}
41
+ end
42
+
43
+ private
44
+
45
+ attr_reader :santa_maria
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,26 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'santa_maria/product_importer/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'santa_maria-product_importer'
7
+ spec.version = SantaMaria::ProductImporter::VERSION
8
+ spec.authors = ['Craig J. Bass']
9
+ spec.email = ['craig@madetech.com']
10
+
11
+ spec.summary = %q{SantaMaria API libary}
12
+ spec.description = %q{This provides a consistent Ruby interface around SantaMaria APIs.}
13
+ spec.homepage = 'https://github.com/madetech/santa_maria-product_importer'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.16'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'rspec', '~> 3.0'
25
+ spec.add_development_dependency 'webmock', '~> 2.0'
26
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: santa_maria-product_importer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Craig J. Bass
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-01-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
69
+ description: This provides a consistent Ruby interface around SantaMaria APIs.
70
+ email:
71
+ - craig@madetech.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - README.md
82
+ - Rakefile
83
+ - lib/santa_maria/domain/product.rb
84
+ - lib/santa_maria/domain/variant.rb
85
+ - lib/santa_maria/gateway/santa_maria_legacy.rb
86
+ - lib/santa_maria/gateway/santa_maria_v2.rb
87
+ - lib/santa_maria/product_importer/version.rb
88
+ - lib/santa_maria/use_case/fetch_products.rb
89
+ - santa_maria-product_importer.gemspec
90
+ homepage: https://github.com/madetech/santa_maria-product_importer
91
+ licenses: []
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.6.13
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: SantaMaria API libary
113
+ test_files: []