shopify_api_console 2.0.0
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 +7 -0
- data/.gitignore +2 -0
- data/.travis.yml +6 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +69 -0
- data/LICENSE +20 -0
- data/README.md +57 -0
- data/Rakefile +42 -0
- data/bin/shopify-api +5 -0
- data/lib/shopify_api_console.rb +3 -0
- data/lib/shopify_api_console/console.rb +183 -0
- data/shipit.rubygems.yml +1 -0
- data/shopify_api_console.gemspec +41 -0
- data/test/console_test.rb +136 -0
- data/test/test_helper.rb +71 -0
- metadata +188 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 78d49083f3fe58eff630686a159b4fd6c660e429cc5836598688cc105013d0ed
|
4
|
+
data.tar.gz: 6e7d838c249cdeed6a3a9f0ac78ee19b59baf2e4a5cadbb527d36eec1b1fcf55
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: eae193f20e4a8bd4a0d839ffc88151de8ab3bd09fed57f4f304f35fdc43d0f7b7960dd797c440b9d153f1949e738da4b04abfe6ec2b6df7599f70d1c94dd98b4
|
7
|
+
data.tar.gz: 92dc95c9c8c630e995f70506ca1780a3b2202593c397f95d5241307edb56d7d893cc1be95f29d1cb19c7de249273da96c3c58fc79c8adb02d1c32069dea3bf42
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
shopify_api_console (2.0.0)
|
5
|
+
activemodel (>= 4.2.2)
|
6
|
+
activesupport (>= 4.2.2)
|
7
|
+
pry (>= 0.9.12.6)
|
8
|
+
shopify_api
|
9
|
+
thor (~> 0.18.1)
|
10
|
+
|
11
|
+
GEM
|
12
|
+
remote: https://rubygems.org/
|
13
|
+
specs:
|
14
|
+
activemodel (5.2.3)
|
15
|
+
activesupport (= 5.2.3)
|
16
|
+
activemodel-serializers-xml (1.0.2)
|
17
|
+
activemodel (> 5.x)
|
18
|
+
activesupport (> 5.x)
|
19
|
+
builder (~> 3.1)
|
20
|
+
activeresource (5.1.0)
|
21
|
+
activemodel (>= 5.0, < 7)
|
22
|
+
activemodel-serializers-xml (~> 1.0)
|
23
|
+
activesupport (>= 5.0, < 7)
|
24
|
+
activesupport (5.2.3)
|
25
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
26
|
+
i18n (>= 0.7, < 2)
|
27
|
+
minitest (~> 5.1)
|
28
|
+
tzinfo (~> 1.1)
|
29
|
+
builder (3.2.3)
|
30
|
+
coderay (1.1.2)
|
31
|
+
concurrent-ruby (1.1.5)
|
32
|
+
fakeweb (1.3.0)
|
33
|
+
graphql (1.9.6)
|
34
|
+
graphql-client (0.14.0)
|
35
|
+
activesupport (>= 3.0, < 6.0)
|
36
|
+
graphql (~> 1.6)
|
37
|
+
i18n (1.6.0)
|
38
|
+
concurrent-ruby (~> 1.0)
|
39
|
+
metaclass (0.0.4)
|
40
|
+
method_source (0.9.2)
|
41
|
+
minitest (5.7.0)
|
42
|
+
mocha (1.1.0)
|
43
|
+
metaclass (~> 0.0.1)
|
44
|
+
pry (0.12.2)
|
45
|
+
coderay (~> 1.1.0)
|
46
|
+
method_source (~> 0.9.0)
|
47
|
+
rack (2.0.7)
|
48
|
+
rake (10.4.2)
|
49
|
+
shopify_api (7.0.1)
|
50
|
+
activeresource (>= 4.1.0, < 6.0.0)
|
51
|
+
graphql-client
|
52
|
+
rack
|
53
|
+
thor (0.18.1)
|
54
|
+
thread_safe (0.3.6)
|
55
|
+
tzinfo (1.2.5)
|
56
|
+
thread_safe (~> 0.1)
|
57
|
+
|
58
|
+
PLATFORMS
|
59
|
+
ruby
|
60
|
+
|
61
|
+
DEPENDENCIES
|
62
|
+
fakeweb
|
63
|
+
minitest (~> 5.0)
|
64
|
+
mocha (>= 0.9.8)
|
65
|
+
rake
|
66
|
+
shopify_api_console!
|
67
|
+
|
68
|
+
BUNDLED WITH
|
69
|
+
1.17.3
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2015 Shopify
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
'Software'), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
17
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
18
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
19
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
20
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
[](https://travis-ci.org/Shopify/shopify_api_console_ruby)
|
2
|
+
|
3
|
+
# This gem has been renamed
|
4
|
+
|
5
|
+
* Name: shopify_cli --> shopify_api_console
|
6
|
+
* GitHub: https://github.com/Shopify/shopify_cli --> https://github.com/Shopify/shopify_api_console_ruby
|
7
|
+
* RubyGems: https://rubygems.org/gems/shopify_cli --> https://rubygems.org/gems/shopify_api_console
|
8
|
+
|
9
|
+
shopify_cli 1.x will not be supported going forward. v1.0.3 will produce a deprecation warning.
|
10
|
+
|
11
|
+
Starting with v2.0, the gem has been renamed to `shopify_api_console`. We recommend switching to shopify_api_console v2.0+ as soon as possible.
|
12
|
+
|
13
|
+
1.x versions will continue to exist on [RubyGems](https://rubygems.org/gems/shopify_cli) and in the [GitHub releases](https://github.com/Shopify/shopify_cli/releases). If you _must_ use one of these releases, make sure to specify a version:
|
14
|
+
|
15
|
+
```
|
16
|
+
gem install shopify_cli -v v1.0.3
|
17
|
+
```
|
18
|
+
|
19
|
+
# Shopify API Console for Ruby
|
20
|
+
|
21
|
+
This package includes the ``shopify-api`` executable to make it easy to open up an interactive console to use the Admin API with a shop.
|
22
|
+
|
23
|
+
```sh
|
24
|
+
gem install shopify_api_console
|
25
|
+
```
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
See the documentation at https://help.shopify.com/en/api/guides/using-the-api-console
|
30
|
+
|
31
|
+
## Getting started
|
32
|
+
|
33
|
+
1. Obtain a private API key and password to use with your shop (step 2 in "Getting Started")
|
34
|
+
|
35
|
+
2. Use the ``shopify-api`` script to save the credentials for the shop to quickly log in.
|
36
|
+
|
37
|
+
```bash
|
38
|
+
shopify-api add yourshopname
|
39
|
+
```
|
40
|
+
|
41
|
+
Follow the prompts for the shop domain, API key and password.
|
42
|
+
|
43
|
+
3. Start the console for the connection.
|
44
|
+
|
45
|
+
```bash
|
46
|
+
shopify-api console
|
47
|
+
```
|
48
|
+
|
49
|
+
```bash
|
50
|
+
shopify-api help
|
51
|
+
```
|
52
|
+
|
53
|
+
## Contributing
|
54
|
+
|
55
|
+
After checking out the source, run:
|
56
|
+
|
57
|
+
`$ bundle install && bundle exec rake test`
|
data/Rakefile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rake'
|
4
|
+
require "bundler/gem_tasks"
|
5
|
+
|
6
|
+
require 'rake/testtask'
|
7
|
+
Rake::TestTask.new(:test) do |test|
|
8
|
+
test.libs << 'lib' << 'test'
|
9
|
+
test.pattern = 'test/**/*_test.rb'
|
10
|
+
test.verbose = true
|
11
|
+
end
|
12
|
+
|
13
|
+
begin
|
14
|
+
require 'rcov/rcovtask'
|
15
|
+
Rcov::RcovTask.new do |test|
|
16
|
+
test.libs << 'test'
|
17
|
+
test.pattern = 'test/**/*_test.rb'
|
18
|
+
test.verbose = true
|
19
|
+
end
|
20
|
+
rescue LoadError
|
21
|
+
task :rcov do
|
22
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
task :default => :test
|
28
|
+
|
29
|
+
require 'rdoc/task'
|
30
|
+
Rake::RDocTask.new do |rdoc|
|
31
|
+
if File.exist?('VERSION.yml')
|
32
|
+
config = YAML.load(File.read('VERSION.yml'))
|
33
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
34
|
+
else
|
35
|
+
version = ""
|
36
|
+
end
|
37
|
+
|
38
|
+
rdoc.rdoc_dir = 'rdoc'
|
39
|
+
rdoc.title = "shopify_api #{version}"
|
40
|
+
rdoc.rdoc_files.include('README*')
|
41
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
42
|
+
end
|
data/bin/shopify-api
ADDED
@@ -0,0 +1,183 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'abbrev'
|
3
|
+
require 'yaml'
|
4
|
+
require 'shopify_api'
|
5
|
+
|
6
|
+
module ShopifyAPIConsole
|
7
|
+
class Console < Thor
|
8
|
+
include Thor::Actions
|
9
|
+
|
10
|
+
class ConfigFileError < StandardError
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "list", "list available connections"
|
14
|
+
def list
|
15
|
+
available_connections.each do |c|
|
16
|
+
prefix = default?(c) ? " * " : " "
|
17
|
+
puts prefix + c
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "add CONNECTION", "create a config file for a connection named CONNECTION"
|
22
|
+
def add(connection)
|
23
|
+
file = config_file(connection)
|
24
|
+
if File.exist?(file)
|
25
|
+
raise ConfigFileError, "There is already a config file at #{file}"
|
26
|
+
else
|
27
|
+
config = {'protocol' => 'https'}
|
28
|
+
config['domain'] = ask("Domain? (leave blank for #{connection}.myshopify.com)")
|
29
|
+
config['domain'] = "#{connection}.myshopify.com" if config['domain'].blank?
|
30
|
+
config['domain'] = "#{config['domain']}.myshopify.com" unless config['domain'].match(/[.:]/)
|
31
|
+
puts "\nopen https://#{config['domain']}/admin/apps/private in your browser to create a private app and get API credentials\n"
|
32
|
+
config['api_key'] = ask("API key?")
|
33
|
+
config['password'] = ask("Password?")
|
34
|
+
if ask("Would you like to use pry as your shell? (y/n)") === "y"
|
35
|
+
config["shell"] = "pry"
|
36
|
+
else
|
37
|
+
config["shell"] = "irb"
|
38
|
+
end
|
39
|
+
create_file(file, config.to_yaml)
|
40
|
+
end
|
41
|
+
if available_connections.one?
|
42
|
+
default(connection)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
desc "remove CONNECTION", "remove the config file for CONNECTION"
|
47
|
+
def remove(connection)
|
48
|
+
file = config_file(connection)
|
49
|
+
if File.exist?(file)
|
50
|
+
remove_file(default_symlink) if default?(connection)
|
51
|
+
remove_file(file)
|
52
|
+
else
|
53
|
+
no_config_file_error(file)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
desc "edit [CONNECTION]", "open the config file for CONNECTION with your default editor"
|
58
|
+
def edit(connection=nil)
|
59
|
+
file = config_file(connection)
|
60
|
+
if File.exist?(file)
|
61
|
+
if ENV['EDITOR'].present?
|
62
|
+
system(ENV['EDITOR'], file)
|
63
|
+
else
|
64
|
+
puts "Please set an editor in the EDITOR environment variable"
|
65
|
+
end
|
66
|
+
else
|
67
|
+
no_config_file_error(file)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
desc "show [CONNECTION]", "output the location and contents of the CONNECTION's config file"
|
72
|
+
def show(connection=nil)
|
73
|
+
connection ||= default_connection
|
74
|
+
file = config_file(connection)
|
75
|
+
if File.exist?(file)
|
76
|
+
puts file
|
77
|
+
puts `cat #{file}`
|
78
|
+
else
|
79
|
+
no_config_file_error(file)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
desc "default [CONNECTION]", "show the default connection, or make CONNECTION the default"
|
84
|
+
def default(connection=nil)
|
85
|
+
if connection
|
86
|
+
target = config_file(connection)
|
87
|
+
if File.exist?(target)
|
88
|
+
remove_file(default_symlink)
|
89
|
+
`ln -s #{target} #{default_symlink}`
|
90
|
+
else
|
91
|
+
no_config_file_error(target)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
if File.exist?(default_symlink)
|
95
|
+
puts "Default connection is #{default_connection}"
|
96
|
+
else
|
97
|
+
puts "There is no default connection set"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
desc "console [CONNECTION]", "start an API console for CONNECTION"
|
102
|
+
def console(connection=nil)
|
103
|
+
file = config_file(connection)
|
104
|
+
|
105
|
+
config = YAML.load(File.read(file))
|
106
|
+
puts "using #{config['domain']}"
|
107
|
+
ShopifyAPI::Base.site = site_from_config(config)
|
108
|
+
|
109
|
+
logger = Logger.new(STDOUT)
|
110
|
+
logger.level = Logger::WARN
|
111
|
+
ActiveResource::Base.logger = logger
|
112
|
+
|
113
|
+
launch_shell(config)
|
114
|
+
end
|
115
|
+
|
116
|
+
tasks.keys.abbrev.each do |shortcut, command|
|
117
|
+
map shortcut => command.to_sym
|
118
|
+
end
|
119
|
+
|
120
|
+
private
|
121
|
+
|
122
|
+
def shop_config_dir
|
123
|
+
@shop_config_dir ||= File.join(ENV['HOME'], '.shopify', 'shops')
|
124
|
+
end
|
125
|
+
|
126
|
+
def default_symlink
|
127
|
+
@default_symlink ||= File.join(shop_config_dir, 'default')
|
128
|
+
end
|
129
|
+
|
130
|
+
def config_file(connection)
|
131
|
+
if connection
|
132
|
+
File.join(shop_config_dir, "#{connection}.yml")
|
133
|
+
else
|
134
|
+
default_symlink
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def site_from_config(config)
|
139
|
+
protocol = config['protocol'] || 'https'
|
140
|
+
api_key = config['api_key']
|
141
|
+
password = config['password']
|
142
|
+
domain = config['domain']
|
143
|
+
|
144
|
+
ShopifyAPI::Base.site = "#{protocol}://#{api_key}:#{password}@#{domain}/admin"
|
145
|
+
end
|
146
|
+
|
147
|
+
def launch_shell(config)
|
148
|
+
if config["shell"] === "pry"
|
149
|
+
require 'pry'
|
150
|
+
ARGV.clear
|
151
|
+
Pry.start
|
152
|
+
else
|
153
|
+
require 'irb'
|
154
|
+
require 'irb/completion'
|
155
|
+
ARGV.clear
|
156
|
+
IRB.start
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def available_connections
|
161
|
+
@available_connections ||= begin
|
162
|
+
pattern = File.join(shop_config_dir, "*.yml")
|
163
|
+
Dir.glob(pattern).map { |f| File.basename(f, ".yml") }
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def default_connection_target
|
168
|
+
@default_connection_target ||= File.readlink(default_symlink)
|
169
|
+
end
|
170
|
+
|
171
|
+
def default_connection
|
172
|
+
@default_connection ||= File.basename(default_connection_target, ".yml")
|
173
|
+
end
|
174
|
+
|
175
|
+
def default?(connection)
|
176
|
+
default_connection == connection
|
177
|
+
end
|
178
|
+
|
179
|
+
def no_config_file_error(filename)
|
180
|
+
raise ConfigFileError, "There is no config file at #{filename}"
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
data/shipit.rubygems.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# using the default shipit config
|
@@ -0,0 +1,41 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
require 'shopify_api_console'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = %q{shopify_api_console}
|
6
|
+
s.version = ShopifyAPIConsole::VERSION
|
7
|
+
s.author = "Shopify"
|
8
|
+
|
9
|
+
s.summary = %q{The Shopify Admin API Console gem is a tool for accessing the Shopify Admin API from the terminal}
|
10
|
+
s.description = %q{}
|
11
|
+
s.homepage = %q{https://github.com/Shopify/shopify_api_console_ruby}
|
12
|
+
|
13
|
+
s.extra_rdoc_files = [
|
14
|
+
"LICENSE",
|
15
|
+
"README.md"
|
16
|
+
]
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
|
21
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
22
|
+
s.license = 'MIT'
|
23
|
+
|
24
|
+
s.add_dependency("shopify_api")
|
25
|
+
s.add_dependency("activemodel", ">= 4.2.2")
|
26
|
+
s.add_dependency("activesupport", ">= 4.2.2")
|
27
|
+
s.add_dependency("thor", "~> 0.18.1")
|
28
|
+
s.add_dependency("pry", ">= 0.9.12.6")
|
29
|
+
|
30
|
+
dev_dependencies = [['mocha', '>= 0.9.8'],
|
31
|
+
['fakeweb'],
|
32
|
+
['minitest', '~> 5.0'],
|
33
|
+
['rake']
|
34
|
+
]
|
35
|
+
|
36
|
+
if s.respond_to?(:add_development_dependency)
|
37
|
+
dev_dependencies.each { |dep| s.add_development_dependency(*dep) }
|
38
|
+
else
|
39
|
+
dev_dependencies.each { |dep| s.add_dependency(*dep) }
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'shopify_api_console/console'
|
3
|
+
require 'fileutils'
|
4
|
+
class ConsoleTest < Minitest::Test
|
5
|
+
HOME_DIR = File.expand_path(File.dirname(__FILE__))
|
6
|
+
TEST_HOME = File.join(HOME_DIR, 'files', 'home')
|
7
|
+
CONFIG_DIR = File.join(TEST_HOME, '.shopify', 'shops')
|
8
|
+
DEFAULT_SYMLINK = File.join(CONFIG_DIR, 'default')
|
9
|
+
|
10
|
+
def setup
|
11
|
+
force_remove(TEST_HOME)
|
12
|
+
|
13
|
+
ENV['HOME'] = TEST_HOME
|
14
|
+
@console = ShopifyAPIConsole::Console.new
|
15
|
+
|
16
|
+
FileUtils.mkdir_p(CONFIG_DIR)
|
17
|
+
Dir.chdir(CONFIG_DIR)
|
18
|
+
|
19
|
+
add_config('foo', default: true, config: valid_options.merge(domain: 'foo.myshopify.com'))
|
20
|
+
add_config('bar', config: valid_options.merge(domain: 'bar.myshopify.com'))
|
21
|
+
end
|
22
|
+
|
23
|
+
def teardown
|
24
|
+
Dir.chdir(HOME_DIR)
|
25
|
+
force_remove(TEST_HOME)
|
26
|
+
end
|
27
|
+
|
28
|
+
test "add with blank domain" do
|
29
|
+
standard_add_shop_prompts
|
30
|
+
$stdin.expects(:gets).times(4).returns("", "key", "pass", "y")
|
31
|
+
@console.expects(:puts).with("\nopen https://foo.myshopify.com/admin/apps/private in your browser to create a private app and get API credentials\n")
|
32
|
+
@console.expects(:puts).with("Default connection is foo")
|
33
|
+
|
34
|
+
@console.add('foo')
|
35
|
+
|
36
|
+
config = YAML.load(File.read(config_file('foo')))
|
37
|
+
assert_equal 'foo.myshopify.com', config['domain']
|
38
|
+
assert_equal 'key', config['api_key']
|
39
|
+
assert_equal 'pass', config['password']
|
40
|
+
assert_equal 'pry', config['shell']
|
41
|
+
assert_equal 'https', config['protocol']
|
42
|
+
assert_equal config_file('foo'), File.readlink(DEFAULT_SYMLINK)
|
43
|
+
end
|
44
|
+
|
45
|
+
test "add with explicit domain" do
|
46
|
+
standard_add_shop_prompts
|
47
|
+
$stdin.expects(:gets).times(4).returns("bar.myshopify.com", "key", "pass", "y")
|
48
|
+
@console.expects(:puts).with("\nopen https://bar.myshopify.com/admin/apps/private in your browser to create a private app and get API credentials\n")
|
49
|
+
@console.expects(:puts).with("Default connection is foo")
|
50
|
+
|
51
|
+
@console.add('foo')
|
52
|
+
|
53
|
+
config = YAML.load(File.read(config_file('foo')))
|
54
|
+
assert_equal 'bar.myshopify.com', config['domain']
|
55
|
+
end
|
56
|
+
|
57
|
+
test "add with irb as shell" do
|
58
|
+
standard_add_shop_prompts
|
59
|
+
$stdin.expects(:gets).times(4).returns("bar.myshopify.com", "key", "pass", "fuuuuuuu")
|
60
|
+
@console.expects(:puts).with("\nopen https://bar.myshopify.com/admin/apps/private in your browser to create a private app and get API credentials\n")
|
61
|
+
@console.expects(:puts).with("Default connection is foo")
|
62
|
+
|
63
|
+
@console.add('foo')
|
64
|
+
|
65
|
+
config = YAML.load(File.read(config_file('foo')))
|
66
|
+
assert_equal 'irb', config['shell']
|
67
|
+
end
|
68
|
+
|
69
|
+
test "list" do
|
70
|
+
@console.expects(:puts).with(" bar")
|
71
|
+
@console.expects(:puts).with(" * foo")
|
72
|
+
|
73
|
+
@console.list
|
74
|
+
end
|
75
|
+
|
76
|
+
test "show default" do
|
77
|
+
@console.expects(:puts).with("Default connection is foo")
|
78
|
+
|
79
|
+
@console.default
|
80
|
+
end
|
81
|
+
|
82
|
+
test "set default" do
|
83
|
+
@console.expects(:puts).with("Default connection is bar")
|
84
|
+
|
85
|
+
@console.default('bar')
|
86
|
+
|
87
|
+
assert_equal config_file('bar'), File.readlink(DEFAULT_SYMLINK)
|
88
|
+
end
|
89
|
+
|
90
|
+
test "remove default connection" do
|
91
|
+
@console.remove('foo')
|
92
|
+
|
93
|
+
assert !File.exist?(DEFAULT_SYMLINK)
|
94
|
+
assert !File.exist?(config_file('foo'))
|
95
|
+
assert File.exist?(config_file('bar'))
|
96
|
+
end
|
97
|
+
|
98
|
+
test "remove non-default connection" do
|
99
|
+
@console.remove('bar')
|
100
|
+
|
101
|
+
assert_equal 'foo.yml', File.readlink(DEFAULT_SYMLINK)
|
102
|
+
assert File.exist?(config_file('foo'))
|
103
|
+
assert !File.exist?(config_file('bar'))
|
104
|
+
end
|
105
|
+
|
106
|
+
private
|
107
|
+
|
108
|
+
def valid_options
|
109
|
+
{'domain' => 'snowdevil.myshopify.com', 'api_key' => 'key', 'password' => 'pass', 'shell' => 'pry', 'protocol' => 'https'}
|
110
|
+
end
|
111
|
+
|
112
|
+
def config_file(connection)
|
113
|
+
File.join(CONFIG_DIR, "#{connection}.yml")
|
114
|
+
end
|
115
|
+
|
116
|
+
def add_config(name, config: nil, default: false)
|
117
|
+
File.open("#{name}.yml", 'w') do |file|
|
118
|
+
file.puts config.to_yaml
|
119
|
+
end
|
120
|
+
File.symlink("#{name}.yml", DEFAULT_SYMLINK) if default
|
121
|
+
end
|
122
|
+
|
123
|
+
def standard_add_shop_prompts
|
124
|
+
force_remove("#{CONFIG_DIR}/*")
|
125
|
+
|
126
|
+
$stdout.expects(:print).with("Domain? (leave blank for foo.myshopify.com) ")
|
127
|
+
$stdout.expects(:print).with("API key? ")
|
128
|
+
$stdout.expects(:print).with("Password? ")
|
129
|
+
$stdout.expects(:print).with("Would you like to use pry as your shell? (y/n) ")
|
130
|
+
end
|
131
|
+
|
132
|
+
def force_remove(pattern)
|
133
|
+
`rm -rf #{pattern}`
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'fakeweb'
|
4
|
+
require 'mocha/setup'
|
5
|
+
|
6
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
7
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
8
|
+
require 'shopify_api_console'
|
9
|
+
require 'shopify_api'
|
10
|
+
|
11
|
+
FakeWeb.allow_net_connect = false
|
12
|
+
|
13
|
+
# setup ShopifyAPI with fake api_key and secret
|
14
|
+
|
15
|
+
class Minitest::Test
|
16
|
+
def self.test(string, &block)
|
17
|
+
define_method("test_#{string}", &block)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.should(string, &block)
|
21
|
+
self.test("should_#{string}", &block)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.context(string)
|
25
|
+
yield
|
26
|
+
end
|
27
|
+
|
28
|
+
def setup
|
29
|
+
ActiveResource::Base.format = :json
|
30
|
+
ShopifyAPI.constants.each do |const|
|
31
|
+
begin
|
32
|
+
const = "ShopifyAPI::#{const}".constantize
|
33
|
+
const.format = :json if const.respond_to?(:format=)
|
34
|
+
rescue NameError
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
ShopifyAPI::Base.clear_session
|
39
|
+
ShopifyAPI::Base.site = "https://this-is-my-test-shop.myshopify.com/admin"
|
40
|
+
ShopifyAPI::Base.password = nil
|
41
|
+
ShopifyAPI::Base.user = nil
|
42
|
+
end
|
43
|
+
|
44
|
+
def teardown
|
45
|
+
FakeWeb.clean_registry
|
46
|
+
end
|
47
|
+
|
48
|
+
# Custom Assertions
|
49
|
+
def assert_not(expression)
|
50
|
+
assert_block("Expected <#{expression}> to be false!") { not expression }
|
51
|
+
end
|
52
|
+
|
53
|
+
def load_fixture(name, format=:json)
|
54
|
+
File.read(File.dirname(__FILE__) + "/fixtures/#{name}.#{format}")
|
55
|
+
end
|
56
|
+
|
57
|
+
def fake(endpoint, options={})
|
58
|
+
body = options.has_key?(:body) ? options.delete(:body) : load_fixture(endpoint)
|
59
|
+
format = options.delete(:format) || :json
|
60
|
+
method = options.delete(:method) || :get
|
61
|
+
extension = ".#{options.delete(:extension)||'json'}" unless options[:extension]==false
|
62
|
+
|
63
|
+
url = if options.has_key?(:url)
|
64
|
+
options[:url]
|
65
|
+
else
|
66
|
+
"https://this-is-my-test-shop.myshopify.com/admin/#{endpoint}#{extension}"
|
67
|
+
end
|
68
|
+
|
69
|
+
FakeWeb.register_uri(method, url, {:body => body, :status => 200, :content_type => "text/#{format}", :content_length => 1}.merge(options))
|
70
|
+
end
|
71
|
+
end
|
metadata
ADDED
@@ -0,0 +1,188 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shopify_api_console
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shopify
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-06-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: shopify_api
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activemodel
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 4.2.2
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 4.2.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 4.2.2
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 4.2.2
|
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.18.1
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.18.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.9.12.6
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.9.12.6
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: mocha
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.9.8
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.9.8
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: fakeweb
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: minitest
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '5.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '5.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rake
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: ''
|
140
|
+
email:
|
141
|
+
executables:
|
142
|
+
- shopify-api
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files:
|
145
|
+
- LICENSE
|
146
|
+
- README.md
|
147
|
+
files:
|
148
|
+
- ".gitignore"
|
149
|
+
- ".travis.yml"
|
150
|
+
- Gemfile
|
151
|
+
- Gemfile.lock
|
152
|
+
- LICENSE
|
153
|
+
- README.md
|
154
|
+
- Rakefile
|
155
|
+
- bin/shopify-api
|
156
|
+
- lib/shopify_api_console.rb
|
157
|
+
- lib/shopify_api_console/console.rb
|
158
|
+
- shipit.rubygems.yml
|
159
|
+
- shopify_api_console.gemspec
|
160
|
+
- test/console_test.rb
|
161
|
+
- test/test_helper.rb
|
162
|
+
homepage: https://github.com/Shopify/shopify_api_console_ruby
|
163
|
+
licenses:
|
164
|
+
- MIT
|
165
|
+
metadata: {}
|
166
|
+
post_install_message:
|
167
|
+
rdoc_options:
|
168
|
+
- "--charset=UTF-8"
|
169
|
+
require_paths:
|
170
|
+
- lib
|
171
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
172
|
+
requirements:
|
173
|
+
- - ">="
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
version: '0'
|
176
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
requirements: []
|
182
|
+
rubyforge_project:
|
183
|
+
rubygems_version: 2.7.6
|
184
|
+
signing_key:
|
185
|
+
specification_version: 4
|
186
|
+
summary: The Shopify Admin API Console gem is a tool for accessing the Shopify Admin
|
187
|
+
API from the terminal
|
188
|
+
test_files: []
|