cc-cli 0.0.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 +15 -0
- data/.gitignore +19 -0
- data/.rspec +2 -0
- data/Gemfile +12 -0
- data/Guardfile +24 -0
- data/LICENSE.txt +22 -0
- data/README.md +186 -0
- data/Rakefile +1 -0
- data/bin/cc-cli +5 -0
- data/cc-cli.gemspec +28 -0
- data/circle.yml +11 -0
- data/config/config.yml +31 -0
- data/lib/cc/api/explorer.rb +175 -0
- data/lib/cc/api/explorer/version.rb +7 -0
- data/lib/cc/api/http/http_requestor.rb +50 -0
- data/lib/cc/api/parser/arguments_mapper.rb +44 -0
- data/lib/cc/api/parser/arguments_parser.rb +65 -0
- data/lib/cc/api/parser/json_parser.rb +38 -0
- data/lib/cc/api/presentor/presentor.rb +47 -0
- data/lib/cc/api/util/config_reader.rb +38 -0
- data/lib/cc/api/util/key_chains_getter.rb +80 -0
- data/spec/dummy_data/catalog_categories.json +1 -0
- data/spec/dummy_data/catalog_product_types.json +1 -0
- data/spec/dummy_data/catalog_products.json +1 -0
- data/spec/dummy_data/catalog_stores.json +1 -0
- data/spec/dummy_data/lattice_offers.json +1 -0
- data/spec/dummy_data/lattice_products.json +1 -0
- data/spec/dummy_data/lattice_stores.json +1 -0
- data/spec/dummy_data/store_products.json +1 -0
- data/spec/explorer_spec.rb +238 -0
- data/spec/http/http_requestor_spec.rb +54 -0
- data/spec/parser/arguments_mapper_spec.rb +78 -0
- data/spec/parser/arguments_parser_spec.rb +81 -0
- data/spec/parser/json_parser_spec.rb +108 -0
- data/spec/spec_helper.rb +49 -0
- data/spec/support/arguments_mapper_returning_blank_json.rb +7 -0
- data/spec/support/arguments_mapper_returning_json_with_id_and_skus.rb +7 -0
- data/spec/support/arguments_mapper_returning_page_params.rb +7 -0
- data/spec/support/arguments_parser_returning_expected_result.rb +6 -0
- data/spec/support/json_parser.rb +43 -0
- data/spec/support/stdout_helper.rb +10 -0
- data/spec/support/table_fields_matcher.rb +16 -0
- data/spec/utils/utils_spec.rb +90 -0
- metadata +194 -0
@@ -0,0 +1,16 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
RSpec::Matchers.define :have_ascii_table_row do |expected|
|
3
|
+
parse = ->(actual) {
|
4
|
+
actual.split("\n").map(&:chomp).map do |line|
|
5
|
+
line.scan(/([^┃]+)┃/).flatten.map(&:strip)
|
6
|
+
end
|
7
|
+
}
|
8
|
+
match do |actual|
|
9
|
+
parse[actual].include?(expected)
|
10
|
+
end
|
11
|
+
|
12
|
+
failure_message_for_should do |actual|
|
13
|
+
lines = parse[actual].reject(&:empty?)
|
14
|
+
"expected to find #{expected.inspect} in #{lines.map(&:inspect).join("\n")}"
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cc::Api::Util::KeyChainsGetter do
|
4
|
+
let(:hash) { { :a => { :b => { :d => { :e => { :g => "end"}, :f => "end" } }, :c => "end" } } }
|
5
|
+
let(:target_array) { [{ :c => "end"}] }
|
6
|
+
let(:hash_with_array) { { 'a' => { 'b' => target_array } } }
|
7
|
+
it "returns the key chains of a given hash" do
|
8
|
+
#TODO: What if value is an Array? e.g. { :a => { :b => { :d => { :e => { :g => ["what", "if", "im", "an", "array"]}, :f => "end" } }, :c => "end" } }
|
9
|
+
printed = capture_stdout do
|
10
|
+
res = Cc::Api::Util::KeyChainsGetter.get_key_chains hash, ""
|
11
|
+
end
|
12
|
+
|
13
|
+
printed.should match "\navailable columns\n====================\na.b.d.e.g\na.b.d.f\na.c\n"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns the key chains of a given hash with array of hashes as an element" do
|
17
|
+
printed = capture_stdout do
|
18
|
+
res = Cc::Api::Util::KeyChainsGetter.get_key_chains hash_with_array, ""
|
19
|
+
end
|
20
|
+
|
21
|
+
printed.should match "\navailable columns\n====================\na.b.<index>.c\n"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "ignores a keychain subset and will put a '*' as a postfix" do
|
25
|
+
printed = capture_stdout do
|
26
|
+
res = Cc::Api::Util::KeyChainsGetter.get_key_chains(hash, "", ["a.b.d"])
|
27
|
+
end
|
28
|
+
|
29
|
+
printed.should match "\navailable columns\n====================\na.b.d.\\*\na.c\n"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "returns the target array" do
|
33
|
+
res = Cc::Api::Util::KeyChainsGetter.get_target_array hash_with_array, "a.b"
|
34
|
+
res.should eq target_array
|
35
|
+
end
|
36
|
+
|
37
|
+
it "throws exception with target not found" do
|
38
|
+
printed = capture_stdout do
|
39
|
+
res = Cc::Api::Util::KeyChainsGetter.get_target_array hash_with_array, "a.b.c"
|
40
|
+
end
|
41
|
+
printed.should eq "Target not found.\n"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe Cc::Api::Util::ConfigReader do
|
46
|
+
let(:login) { 'abc' }
|
47
|
+
let(:key) { '123' }
|
48
|
+
|
49
|
+
around(:each) do |example|
|
50
|
+
old_login = ENV['CC_API_LOGIN']
|
51
|
+
old_key = ENV['CC_API_KEY']
|
52
|
+
|
53
|
+
begin
|
54
|
+
ENV['CC_API_LOGIN'] = login
|
55
|
+
ENV['CC_API_KEY'] = key
|
56
|
+
example.run
|
57
|
+
ensure
|
58
|
+
ENV['CC_API_LOGIN'] = old_login
|
59
|
+
ENV['CC_API_KEY'] = old_key
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should return license key hash based from the CC_API_KEY from user's environment" do
|
64
|
+
license = Cc::Api::Util::ConfigReader.license
|
65
|
+
expect(license.username).to eq('abc')
|
66
|
+
expect(license.password).to eq('123')
|
67
|
+
end
|
68
|
+
|
69
|
+
context "env vars not set" do
|
70
|
+
let(:login) { nil }
|
71
|
+
let(:key) { nil }
|
72
|
+
|
73
|
+
it "should raise error if CC_API_KEY from user's environment is not found" do
|
74
|
+
expect {
|
75
|
+
Cc::Api::Util::ConfigReader.license
|
76
|
+
}.to raise_error Cc::Api::Util::LicenseKeysException
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "keys present but blank" do
|
81
|
+
let(:login) { "" }
|
82
|
+
let(:key) { "" }
|
83
|
+
|
84
|
+
it "should raise error if CC_API_KEY is blank" do
|
85
|
+
expect {
|
86
|
+
Cc::Api::Util::ConfigReader.license
|
87
|
+
}.to raise_error Cc::Api::Util::LicenseKeysException
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
metadata
ADDED
@@ -0,0 +1,194 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cc-cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Neil Marion dela Cruz
|
8
|
+
- Michael Xavier
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-04-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: command_line_reporter
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ! '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ! '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: httparty
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: thor
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: bundler
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '1.5'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.5'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rake
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rspec
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
description: This is a command line client for exploring CrystalCommerce APIs
|
99
|
+
email:
|
100
|
+
- developers@crystalcommerce.com
|
101
|
+
executables:
|
102
|
+
- cc-cli
|
103
|
+
extensions: []
|
104
|
+
extra_rdoc_files: []
|
105
|
+
files:
|
106
|
+
- .gitignore
|
107
|
+
- .rspec
|
108
|
+
- Gemfile
|
109
|
+
- Guardfile
|
110
|
+
- LICENSE.txt
|
111
|
+
- README.md
|
112
|
+
- Rakefile
|
113
|
+
- bin/cc-cli
|
114
|
+
- cc-cli.gemspec
|
115
|
+
- circle.yml
|
116
|
+
- config/config.yml
|
117
|
+
- lib/cc/api/explorer.rb
|
118
|
+
- lib/cc/api/explorer/version.rb
|
119
|
+
- lib/cc/api/http/http_requestor.rb
|
120
|
+
- lib/cc/api/parser/arguments_mapper.rb
|
121
|
+
- lib/cc/api/parser/arguments_parser.rb
|
122
|
+
- lib/cc/api/parser/json_parser.rb
|
123
|
+
- lib/cc/api/presentor/presentor.rb
|
124
|
+
- lib/cc/api/util/config_reader.rb
|
125
|
+
- lib/cc/api/util/key_chains_getter.rb
|
126
|
+
- spec/dummy_data/catalog_categories.json
|
127
|
+
- spec/dummy_data/catalog_product_types.json
|
128
|
+
- spec/dummy_data/catalog_products.json
|
129
|
+
- spec/dummy_data/catalog_stores.json
|
130
|
+
- spec/dummy_data/lattice_offers.json
|
131
|
+
- spec/dummy_data/lattice_products.json
|
132
|
+
- spec/dummy_data/lattice_stores.json
|
133
|
+
- spec/dummy_data/store_products.json
|
134
|
+
- spec/explorer_spec.rb
|
135
|
+
- spec/http/http_requestor_spec.rb
|
136
|
+
- spec/parser/arguments_mapper_spec.rb
|
137
|
+
- spec/parser/arguments_parser_spec.rb
|
138
|
+
- spec/parser/json_parser_spec.rb
|
139
|
+
- spec/spec_helper.rb
|
140
|
+
- spec/support/arguments_mapper_returning_blank_json.rb
|
141
|
+
- spec/support/arguments_mapper_returning_json_with_id_and_skus.rb
|
142
|
+
- spec/support/arguments_mapper_returning_page_params.rb
|
143
|
+
- spec/support/arguments_parser_returning_expected_result.rb
|
144
|
+
- spec/support/json_parser.rb
|
145
|
+
- spec/support/stdout_helper.rb
|
146
|
+
- spec/support/table_fields_matcher.rb
|
147
|
+
- spec/utils/utils_spec.rb
|
148
|
+
homepage: https://github.com/crystalcommerce/cc-cli
|
149
|
+
licenses:
|
150
|
+
- MIT
|
151
|
+
metadata: {}
|
152
|
+
post_install_message:
|
153
|
+
rdoc_options: []
|
154
|
+
require_paths:
|
155
|
+
- lib
|
156
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - ! '>='
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '0'
|
161
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - ! '>='
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
requirements: []
|
167
|
+
rubyforge_project:
|
168
|
+
rubygems_version: 2.2.2
|
169
|
+
signing_key:
|
170
|
+
specification_version: 4
|
171
|
+
summary: CrystalCommerce API Explorer
|
172
|
+
test_files:
|
173
|
+
- spec/dummy_data/catalog_categories.json
|
174
|
+
- spec/dummy_data/catalog_product_types.json
|
175
|
+
- spec/dummy_data/catalog_products.json
|
176
|
+
- spec/dummy_data/catalog_stores.json
|
177
|
+
- spec/dummy_data/lattice_offers.json
|
178
|
+
- spec/dummy_data/lattice_products.json
|
179
|
+
- spec/dummy_data/lattice_stores.json
|
180
|
+
- spec/dummy_data/store_products.json
|
181
|
+
- spec/explorer_spec.rb
|
182
|
+
- spec/http/http_requestor_spec.rb
|
183
|
+
- spec/parser/arguments_mapper_spec.rb
|
184
|
+
- spec/parser/arguments_parser_spec.rb
|
185
|
+
- spec/parser/json_parser_spec.rb
|
186
|
+
- spec/spec_helper.rb
|
187
|
+
- spec/support/arguments_mapper_returning_blank_json.rb
|
188
|
+
- spec/support/arguments_mapper_returning_json_with_id_and_skus.rb
|
189
|
+
- spec/support/arguments_mapper_returning_page_params.rb
|
190
|
+
- spec/support/arguments_parser_returning_expected_result.rb
|
191
|
+
- spec/support/json_parser.rb
|
192
|
+
- spec/support/stdout_helper.rb
|
193
|
+
- spec/support/table_fields_matcher.rb
|
194
|
+
- spec/utils/utils_spec.rb
|