commercelayer-cli 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b27cda80e9a81029b3d68786542fae661dc0edf17fd96a4605c0aad2b2a800f7
4
+ data.tar.gz: 9a36090bfdde858d9c70306841ba31f31698050784f78c9e39260829e5ff79ee
5
+ SHA512:
6
+ metadata.gz: 99836768ebaefb187adca6727c7d72646e910d02de02cc2aa8089c6bb0e28636f3547ac389b88eb25cb176aa795b7211ffd46e4b90233ec8436473a2fc71cf5b
7
+ data.tar.gz: 32969c9c228efcb51db98a24d1bbfccb05eb513506ae3efd47e8baa2d9a5c8a730ec6e41a28976e1f80621fc61ef2ff888b666cfa765400c923e25748ed2a87c
data/.gitignore ADDED
@@ -0,0 +1,11 @@
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
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.16.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at filippo@commercelayer.io. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
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 commercelayer-cli.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,134 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ commercelayer-cli (0.2.0)
5
+ commercelayer
6
+ dato
7
+ thor
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activemodel (5.2.0)
13
+ activesupport (= 5.2.0)
14
+ activesupport (5.2.0)
15
+ concurrent-ruby (~> 1.0, >= 1.0.2)
16
+ i18n (>= 0.7, < 2)
17
+ minitest (~> 5.1)
18
+ tzinfo (~> 1.1)
19
+ addressable (2.5.2)
20
+ public_suffix (>= 2.0.2, < 4.0)
21
+ cacert (0.5.0)
22
+ commercelayer (0.3.0)
23
+ jsonapi-consumer (~> 1.0)
24
+ oauth2 (~> 1.4.0)
25
+ concurrent-ruby (1.0.5)
26
+ dato (0.6.3)
27
+ activesupport (>= 4.2.7)
28
+ addressable
29
+ cacert
30
+ dotenv
31
+ downloadr
32
+ faraday (>= 0.9.0)
33
+ faraday_middleware (>= 0.9.0)
34
+ fastimage
35
+ imgix (>= 0.3.1)
36
+ json_schema
37
+ listen
38
+ pusher-client
39
+ thor
40
+ toml
41
+ diff-lcs (1.3)
42
+ domain_name (0.5.20180417)
43
+ unf (>= 0.0.5, < 1.0.0)
44
+ dotenv (2.5.0)
45
+ downloadr (0.0.41)
46
+ addressable (~> 2.3)
47
+ rest-client (~> 1.7)
48
+ faraday (0.12.2)
49
+ multipart-post (>= 1.2, < 3)
50
+ faraday_middleware (0.12.2)
51
+ faraday (>= 0.7.4, < 1.0)
52
+ fastimage (2.1.3)
53
+ ffi (1.9.25)
54
+ http-cookie (1.0.3)
55
+ domain_name (~> 0.5)
56
+ i18n (1.0.1)
57
+ concurrent-ruby (~> 1.0)
58
+ imgix (1.1.0)
59
+ addressable
60
+ json (2.1.0)
61
+ json_schema (0.19.1)
62
+ jsonapi-consumer (1.0.1)
63
+ activemodel (>= 3.2)
64
+ activesupport (>= 3.2)
65
+ addressable (~> 2.5.2)
66
+ faraday (>= 0.9)
67
+ faraday_middleware
68
+ jwt (1.5.6)
69
+ listen (3.1.5)
70
+ rb-fsevent (~> 0.9, >= 0.9.4)
71
+ rb-inotify (~> 0.9, >= 0.9.7)
72
+ ruby_dep (~> 1.2)
73
+ mime-types (2.99.3)
74
+ minitest (5.11.3)
75
+ multi_json (1.13.1)
76
+ multi_xml (0.6.0)
77
+ multipart-post (2.0.0)
78
+ netrc (0.11.0)
79
+ oauth2 (1.4.0)
80
+ faraday (>= 0.8, < 0.13)
81
+ jwt (~> 1.0)
82
+ multi_json (~> 1.3)
83
+ multi_xml (~> 0.5)
84
+ rack (>= 1.2, < 3)
85
+ parslet (1.8.2)
86
+ public_suffix (3.0.2)
87
+ pusher-client (0.6.2)
88
+ json
89
+ websocket (~> 1.0)
90
+ rack (2.0.5)
91
+ rake (10.5.0)
92
+ rb-fsevent (0.10.3)
93
+ rb-inotify (0.9.10)
94
+ ffi (>= 0.5.0, < 2)
95
+ rest-client (1.8.0)
96
+ http-cookie (>= 1.0.2, < 2.0)
97
+ mime-types (>= 1.16, < 3.0)
98
+ netrc (~> 0.7)
99
+ rspec (3.7.0)
100
+ rspec-core (~> 3.7.0)
101
+ rspec-expectations (~> 3.7.0)
102
+ rspec-mocks (~> 3.7.0)
103
+ rspec-core (3.7.1)
104
+ rspec-support (~> 3.7.0)
105
+ rspec-expectations (3.7.0)
106
+ diff-lcs (>= 1.2.0, < 2.0)
107
+ rspec-support (~> 3.7.0)
108
+ rspec-mocks (3.7.0)
109
+ diff-lcs (>= 1.2.0, < 2.0)
110
+ rspec-support (~> 3.7.0)
111
+ rspec-support (3.7.1)
112
+ ruby_dep (1.5.0)
113
+ thor (0.20.0)
114
+ thread_safe (0.3.6)
115
+ toml (0.2.0)
116
+ parslet (~> 1.8.0)
117
+ tzinfo (1.2.5)
118
+ thread_safe (~> 0.1)
119
+ unf (0.1.4)
120
+ unf_ext
121
+ unf_ext (0.0.7.5)
122
+ websocket (1.2.8)
123
+
124
+ PLATFORMS
125
+ ruby
126
+
127
+ DEPENDENCIES
128
+ bundler (~> 1.16)
129
+ commercelayer-cli!
130
+ rake (~> 10.0)
131
+ rspec (~> 3.0)
132
+
133
+ BUNDLED WITH
134
+ 1.16.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Filippo Conforti
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Commercelayer::CLI
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/commercelayer/cli`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'commercelayer-cli'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install commercelayer-cli
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/commercelayer-cli. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Commercelayer::CLI project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/commercelayer-cli/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "commercelayer/cli"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,42 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "commercelayer/cli/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "commercelayer-cli"
8
+ spec.version = Commercelayer::CLI::VERSION
9
+ spec.authors = ["Filippo Conforti"]
10
+ spec.email = ["filippo@commercelayer.io"]
11
+
12
+ spec.summary = "commercelayer-cli"
13
+ spec.description = "The Official Commerce Layer CLI"
14
+ spec.homepage = "https://github.com/commercelayer/commercelayer-cli"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ # Specify which files should be added to the gem when it is released.
27
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
28
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
29
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
30
+ end
31
+ spec.bindir = "exe"
32
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ["lib"]
34
+
35
+ spec.add_development_dependency "bundler", "~> 1.16"
36
+ spec.add_development_dependency "rake", "~> 10.0"
37
+ spec.add_development_dependency "rspec", "~> 3.0"
38
+
39
+ spec.add_dependency "thor"
40
+ spec.add_dependency "commercelayer"
41
+ spec.add_dependency "dato"
42
+ end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "commercelayer/cli"
4
+
5
+ Commercelayer::CLI::Base.start(ARGV)
@@ -0,0 +1,225 @@
1
+ module Commercelayer
2
+ module CLI
3
+ module Exporters
4
+ class DatoCMS
5
+
6
+ include Helpers
7
+
8
+ def initialize(options={})
9
+ puts "Clearing item types..."
10
+ client.item_types.all.each do |item_type|
11
+ client.item_types.destroy(item_type[:id])
12
+ end
13
+ puts "Clearing uploads..."
14
+ client.uploads.all.each do |upload|
15
+ client.uploads.destroy(upload[:id])
16
+ end
17
+ end
18
+
19
+ def export!
20
+ create_product_model!
21
+ create_variant_model!
22
+ create_product_model_fields!
23
+ create_variant_model_fields!
24
+ create_records!
25
+ end
26
+
27
+ private
28
+ def create_product_model!
29
+ puts "Creating product model..."
30
+ @product_model = client.item_types.create({
31
+ api_key: "product",
32
+ name: "Product",
33
+ singleton: false,
34
+ all_locales_required: false,
35
+ sortable: true,
36
+ modular_block: false,
37
+ draft_mode_active: false,
38
+ tree: false,
39
+ ordering_direction: nil,
40
+ ordering_field: nil
41
+ })
42
+ end
43
+
44
+ def create_variant_model!
45
+ puts "Creating variant model..."
46
+ @variant_model = client.item_types.create({
47
+ api_key: "variant",
48
+ name: "Variant",
49
+ singleton: false,
50
+ all_locales_required: false,
51
+ sortable: true,
52
+ modular_block: false,
53
+ draft_mode_active: false,
54
+ tree: false,
55
+ ordering_direction: nil,
56
+ ordering_field: nil
57
+ })
58
+ end
59
+
60
+ def create_product_model_fields!
61
+ puts "Creating product model fields..."
62
+ product_model_fields.each do |api_key, options|
63
+ client.fields.create(@product_model[:id], {
64
+ api_key: api_key,
65
+ appeareance: options[:appeareance],
66
+ default_value: nil,
67
+ field_type: options[:field_type],
68
+ hint: options[:hint],
69
+ label: options[:label],
70
+ localized: false,
71
+ position: options[:position],
72
+ validators: options[:validators]
73
+ })
74
+ end
75
+ end
76
+
77
+ def create_variant_model_fields!
78
+ puts "Creating variant model fields..."
79
+ variant_model_fields.each do |api_key, options|
80
+ client.fields.create(@variant_model[:id], {
81
+ api_key: api_key,
82
+ appeareance: options[:appeareance],
83
+ default_value: nil,
84
+ field_type: options[:field_type],
85
+ hint: options[:hint],
86
+ label: options[:label],
87
+ localized: false,
88
+ position: options[:position],
89
+ validators: options[:validators]
90
+ })
91
+ end
92
+ end
93
+
94
+ def product_model_fields
95
+ {
96
+ reference: {
97
+ label: "Reference",
98
+ field_type: "string",
99
+ hint: "The product's reference",
100
+ position: 1,
101
+ validators: {
102
+ required: {},
103
+ unique: {}
104
+ },
105
+ appeareance: { type: "plain" }
106
+ },
107
+ variants: {
108
+ label: "Variants",
109
+ field_type: "links",
110
+ hint: "The product's variants",
111
+ position: 2,
112
+ validators: { items_item_type: { item_types: [@variant_model[:id]] } },
113
+ appeareance: { type: "select" }
114
+ }
115
+ }
116
+ end
117
+
118
+ def variant_model_fields
119
+ {
120
+ product: {
121
+ label: "Product",
122
+ field_type: "link",
123
+ hint: "The reference product",
124
+ position: 1,
125
+ validators: {
126
+ required: {},
127
+ item_item_type: { item_types: [@product_model[:id]] }
128
+ },
129
+ appeareance: { type: "select" }
130
+ },
131
+ code: {
132
+ label: "Code",
133
+ field_type: "string",
134
+ hint: "The variant's code",
135
+ position: 2,
136
+ validators: {
137
+ required: {},
138
+ unique: {}
139
+ },
140
+ appeareance: { type: "plain" }
141
+ },
142
+ name: {
143
+ label: "Name",
144
+ field_type: "string",
145
+ hint: "The variant's name",
146
+ position: 3,
147
+ validators: {
148
+ required: {},
149
+ unique: {}
150
+ },
151
+ appeareance: { type: "plain" }
152
+ },
153
+ description: {
154
+ label: "Description",
155
+ field_type: "text",
156
+ hint: "The variant's description",
157
+ position: 4,
158
+ validators: {},
159
+ appeareance: { type: "plain" }
160
+ },
161
+ image: {
162
+ label: "Image",
163
+ field_type: "file",
164
+ hint: "The variant's image",
165
+ position: 5,
166
+ validators: {},
167
+ appeareance: {}
168
+ }
169
+ }
170
+ end
171
+
172
+ def create_records!
173
+ last_product_reference = nil
174
+ last_product_id = nil
175
+ last_product_variants = []
176
+ Commercelayer::Sku.order(:reference).all.each_total do |sku|
177
+ puts "> #{sku.code}"
178
+ if sku.reference != last_product_reference
179
+ if last_product_id
180
+ client.items.update(last_product_id, {
181
+ reference: last_product_reference,
182
+ variants: last_product_variants
183
+ })
184
+ last_product_variants = []
185
+ end
186
+
187
+ begin
188
+ product = client.items.create({
189
+ item_type: @product_model[:id],
190
+ reference: sku.reference,
191
+ variants: []
192
+ })
193
+ last_product_reference = sku.reference
194
+ last_product_id = product[:id]
195
+ rescue => e
196
+ puts e.inspect
197
+ break
198
+ end
199
+ end
200
+
201
+ begin
202
+ variant = client.items.create({
203
+ item_type: @variant_model[:id],
204
+ product: last_product_id,
205
+ code: sku.code,
206
+ name: sku.name,
207
+ description: sku.description,
208
+ image: client.upload_image(sku.image_url.split("?").first)
209
+ })
210
+ last_product_variants << variant[:id]
211
+ rescue => e
212
+ puts e.inspect
213
+ break
214
+ end
215
+ end
216
+ end
217
+
218
+ def client
219
+ Dato::Site::Client.new(config_data[:dato][:api_key])
220
+ end
221
+
222
+ end
223
+ end
224
+ end
225
+ end
@@ -0,0 +1,24 @@
1
+ require_relative "exporters/datocms"
2
+
3
+ module Commercelayer
4
+ module CLI
5
+ module Exporters
6
+
7
+ def export_data!(destination)
8
+ commercelayer_client.authorize!
9
+ case destination
10
+ when "datocms"
11
+ if yes? "Warning: this will erase your DatoCMS site. Continue?", :yellow
12
+ say "Exporting data to DatoCMS...", :blue
13
+ DatoCMS.new.export!
14
+ else
15
+ say "Nothing to do here. Bye!", :blue
16
+ end
17
+ else
18
+ say "coming soon...", :yellow
19
+ end
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,38 @@
1
+ module Commercelayer
2
+ module CLI
3
+ module Helpers
4
+
5
+ def config_data
6
+ YAML::load_file(config_path).deep_symbolize_keys
7
+ end
8
+
9
+ def config_data_template
10
+ {
11
+ "commercelayer" => {
12
+ "site" => "https://<subdomain>.commercelayer.io",
13
+ "client_id" => "YOUR-COMMERCELAYER-CLIENT-ID",
14
+ "client_secret" => "YOUR-COMMERCELAYER-CLIENT-SECRET",
15
+ "scope" => "market:<market_id>",
16
+ },
17
+ "dato" => {
18
+ "api_key" => "YOUR-DATOCMS-APIKEY"
19
+ }
20
+ }.to_yaml
21
+ end
22
+
23
+ def config_path
24
+ ENV['HOME'] + "/.commercelayer-cli.yml"
25
+ end
26
+
27
+ def commercelayer_client
28
+ Commercelayer::Client.new(
29
+ client_id: config_data[:commercelayer][:client_id],
30
+ client_secret: config_data[:commercelayer][:client_secret],
31
+ scope: config_data[:commercelayer][:scope],
32
+ site: config_data[:commercelayer][:site]
33
+ )
34
+ end
35
+
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,5 @@
1
+ module Commercelayer
2
+ module CLI
3
+ VERSION = "0.2.0"
4
+ end
5
+ end
@@ -0,0 +1,32 @@
1
+ require 'thor'
2
+ require 'commercelayer'
3
+ require 'dato'
4
+
5
+ require "commercelayer/cli/version"
6
+ require "commercelayer/cli/helpers"
7
+ require "commercelayer/cli/exporters"
8
+
9
+ module Commercelayer
10
+ module CLI
11
+ class Base < Thor
12
+
13
+ include Helpers
14
+ include Exporters
15
+ include Thor::Actions
16
+
17
+ desc "init", "Create a config file under $HOME/.commercelayer-cli.yml"
18
+ def init
19
+ create_file(config_path) do
20
+ config_data_template
21
+ end
22
+ end
23
+
24
+ desc "export", "Export data from Commerce Layer to a destination"
25
+ def export
26
+ destination = ask "What is your destination?", limited_to: ["contentful", "datocms", "csv"]
27
+ export_data!(destination)
28
+ end
29
+
30
+ end
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: commercelayer-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Filippo Conforti
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-07-16 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: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: commercelayer
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: dato
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: The Official Commerce Layer CLI
98
+ email:
99
+ - filippo@commercelayer.io
100
+ executables:
101
+ - commercelayer-cli
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".travis.yml"
108
+ - CODE_OF_CONDUCT.md
109
+ - Gemfile
110
+ - Gemfile.lock
111
+ - LICENSE.txt
112
+ - README.md
113
+ - Rakefile
114
+ - bin/console
115
+ - bin/setup
116
+ - commercelayer-cli.gemspec
117
+ - exe/commercelayer-cli
118
+ - lib/commercelayer/cli.rb
119
+ - lib/commercelayer/cli/exporters.rb
120
+ - lib/commercelayer/cli/exporters/datocms.rb
121
+ - lib/commercelayer/cli/helpers.rb
122
+ - lib/commercelayer/cli/version.rb
123
+ homepage: https://github.com/commercelayer/commercelayer-cli
124
+ licenses:
125
+ - MIT
126
+ metadata:
127
+ allowed_push_host: https://rubygems.org
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.7.7
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: commercelayer-cli
148
+ test_files: []