Class: ShopifyAPIConsole::Console
- Inherits:
-
Thor
- Object
- Thor
- ShopifyAPIConsole::Console
- Includes:
- Thor::Actions
- Defined in:
- lib/shopify_api_console/console.rb
Defined Under Namespace
Classes: ConfigFileError
Instance Method Summary collapse
- #add(connection) ⇒ Object
- #console(connection = nil) ⇒ Object
- #default(connection = nil) ⇒ Object
- #edit(connection = nil) ⇒ Object
- #list ⇒ Object
- #remove(connection) ⇒ Object
- #show(connection = nil) ⇒ Object
Instance Method Details
#add(connection) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/shopify_api_console/console.rb', line 22 def add(connection) file = config_file(connection) if File.exist?(file) raise ConfigFileError, "There is already a config file at #{file}" else config = {'protocol' => 'https'} config['domain'] = ask("Domain? (leave blank for #{connection}.myshopify.com)") config['domain'] = "#{connection}.myshopify.com" if config['domain'].blank? config['domain'] = "#{config['domain']}.myshopify.com" unless config['domain'].match(/[.:]/) puts "\nopen https://#{config['domain']}/admin/apps/private in your browser to create a private app and get API credentials\n" config['api_key'] = ask("API key?") config['password'] = ask("Password?") if ask("Would you like to use pry as your shell? (y/n)") === "y" config["shell"] = "pry" else config["shell"] = "irb" end create_file(file, config.to_yaml) end if available_connections.one? default(connection) end end |
#console(connection = nil) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/shopify_api_console/console.rb', line 102 def console(connection=nil) file = config_file(connection) config = YAML.load(File.read(file)) puts "using #{config['domain']}" ShopifyAPI::Base.site = site_from_config(config) logger = Logger.new(STDOUT) logger.level = Logger::WARN ActiveResource::Base.logger = logger launch_shell(config) end |
#default(connection = nil) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/shopify_api_console/console.rb', line 84 def default(connection=nil) if connection target = config_file(connection) if File.exist?(target) remove_file(default_symlink) `ln -s #{target} #{default_symlink}` else no_config_file_error(target) end end if File.exist?(default_symlink) puts "Default connection is #{default_connection}" else puts "There is no default connection set" end end |
#edit(connection = nil) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/shopify_api_console/console.rb', line 58 def edit(connection=nil) file = config_file(connection) if File.exist?(file) if ENV['EDITOR'].present? system(ENV['EDITOR'], file) else puts "Please set an editor in the EDITOR environment variable" end else no_config_file_error(file) end end |
#list ⇒ Object
14 15 16 17 18 19 |
# File 'lib/shopify_api_console/console.rb', line 14 def list available_connections.each do |c| prefix = default?(c) ? " * " : " " puts prefix + c end end |
#remove(connection) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/shopify_api_console/console.rb', line 47 def remove(connection) file = config_file(connection) if File.exist?(file) remove_file(default_symlink) if default?(connection) remove_file(file) else no_config_file_error(file) end end |
#show(connection = nil) ⇒ Object
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/shopify_api_console/console.rb', line 72 def show(connection=nil) connection ||= default_connection file = config_file(connection) if File.exist?(file) puts file puts `cat #{file}` else no_config_file_error(file) end end |