shopify_api 1.1.3 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ == Version 1.2.0
2
+
3
+ * Command-line interface
4
+ * Allow custom params when fetching a single Asset
5
+
1
6
  == Version 1.1.3 (November 4, 2010)
2
7
 
3
8
  * Add ProductSearchEngines resource
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../lib/shopify_api',__FILE__)
3
+ require File.expand_path('../../lib/shopify_api/cli',__FILE__)
4
+ ShopifyAPI::Cli.start(ARGV)
@@ -423,7 +423,9 @@ module ShopifyAPI
423
423
  if args[0].is_a?(Symbol)
424
424
  super
425
425
  else
426
- find(:one, :from => "/admin/assets.#{format.extension}", :params => {:asset => {:key => args[0]}})
426
+ params = {:asset => {:key => args[0]}}
427
+ params = params.merge(args[1][:params]) if args[1] && args[1][:params]
428
+ find(:one, :from => "/admin/assets.#{format.extension}", :params => params)
427
429
  end
428
430
  end
429
431
 
@@ -0,0 +1,156 @@
1
+ require 'thor'
2
+
3
+ module ShopifyAPI
4
+ class Cli < Thor
5
+ include Thor::Actions
6
+
7
+ class ConfigFileError < StandardError
8
+ end
9
+
10
+ desc "list", "list available connections"
11
+ def list
12
+ available_connections.each do |c|
13
+ prefix = default?(c) ? " * " : " "
14
+ puts prefix + c
15
+ end
16
+ end
17
+
18
+ desc "add CONNECTION", "create a config file for a connection named CONNECTION"
19
+ def add(connection)
20
+ file = config_file(connection)
21
+ if File.exist?(file)
22
+ raise ConfigFileError, "There is already a config file at #{file}"
23
+ else
24
+ config = {'protocol' => 'https'}
25
+ config['domain'] = ask("Domain? (leave blank for #{connection}.myshopify.com)")
26
+ config['domain'] = "#{connection}.myshopify.com" if config['domain'].blank?
27
+ puts "\nopen https://#{config['domain']}/admin/api in your browser to get API credentials\n"
28
+ config['api_key'] = ask("API key?")
29
+ config['password'] = ask("Password?")
30
+ create_file(file, config.to_yaml)
31
+ end
32
+ if available_connections.one?
33
+ default(connection)
34
+ end
35
+ end
36
+
37
+ desc "remove CONNECTION", "remove the config file for CONNECTION"
38
+ def remove(connection)
39
+ file = config_file(connection)
40
+ if File.exist?(file)
41
+ remove_file(default_symlink) if default?(connection)
42
+ remove_file(file)
43
+ else
44
+ no_config_file_error(file)
45
+ end
46
+ end
47
+
48
+ desc "edit [CONNECTION]", "open the config file for CONNECTION with your default editor"
49
+ def edit(connection=nil)
50
+ file = config_file(connection)
51
+ if File.exist?(file)
52
+ if ENV['EDITOR'].present?
53
+ `#{ENV['EDITOR']} #{file}`
54
+ else
55
+ puts "Please set an editor in the EDITOR environment variable"
56
+ end
57
+ else
58
+ no_config_file_error(file)
59
+ end
60
+ end
61
+
62
+ desc "show [CONNECTION]", "output the location and contents of the CONNECTION's config file"
63
+ def show(connection=nil)
64
+ connection ||= default_connection
65
+ file = config_file(connection)
66
+ if File.exist?(file)
67
+ puts file
68
+ puts `cat #{file}`
69
+ else
70
+ no_config_file_error(file)
71
+ end
72
+ end
73
+
74
+ desc "default [CONNECTION]", "show the default connection, or make CONNECTION the default"
75
+ def default(connection=nil)
76
+ if connection
77
+ target = config_file(connection)
78
+ if File.exist?(target)
79
+ remove_file(default_symlink)
80
+ `ln -s #{target} #{default_symlink}`
81
+ else
82
+ no_config_file_error(file)
83
+ end
84
+ end
85
+ if File.exist?(default_symlink)
86
+ puts "Default connection is #{default_connection}"
87
+ else
88
+ puts "There is no default connection set"
89
+ end
90
+ end
91
+
92
+ desc "console [CONNECTION]", "start an API console for CONNECTION"
93
+ def console(connection=nil)
94
+ file = config_file(connection)
95
+
96
+ config = YAML.load(File.read(file))
97
+ puts "using #{config['domain']}"
98
+ ShopifyAPI::Base.site = site_from_config(config)
99
+
100
+ require 'irb'
101
+ require 'irb/completion'
102
+ ARGV.clear
103
+ IRB.start
104
+ end
105
+
106
+ private
107
+
108
+ def shop_config_dir
109
+ @shop_config_dir ||= File.join(ENV['HOME'], '.shopify', 'shops')
110
+ end
111
+
112
+ def default_symlink
113
+ @default_symlink ||= File.join(shop_config_dir, 'default')
114
+ end
115
+
116
+ def config_file(connection)
117
+ if connection
118
+ File.join(shop_config_dir, "#{connection}.yml")
119
+ else
120
+ default_symlink
121
+ end
122
+ end
123
+
124
+ def site_from_config(config)
125
+ protocol = config['protocol'] || 'https'
126
+ api_key = config['api_key']
127
+ password = config['password']
128
+ domain = config['domain']
129
+
130
+ ShopifyAPI::Base.site = "#{protocol}://#{api_key}:#{password}@#{domain}/admin"
131
+ end
132
+
133
+ def available_connections
134
+ @available_connections ||= begin
135
+ pattern = File.join(shop_config_dir, "*.yml")
136
+ Dir.glob(pattern).map { |f| File.basename(f, ".yml") }
137
+ end
138
+ end
139
+
140
+ def default_connection_target
141
+ @default_connection_target ||= File.readlink(default_symlink)
142
+ end
143
+
144
+ def default_connection
145
+ @default_connection ||= File.basename(default_connection_target, ".yml")
146
+ end
147
+
148
+ def default?(connection)
149
+ default_connection == connection
150
+ end
151
+
152
+ def no_config_file_error(filename)
153
+ raise ConfigFileError, "There is no config file at #{file}"
154
+ end
155
+ end
156
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{shopify_api}
5
- s.version = "1.1.3"
5
+ s.version = "1.2.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Tobias L\303\274tke", "Cody Fauser", "Dennis Theisen"]
@@ -76,6 +76,7 @@ Copyright (c) 2009 "JadedPixel inc.". See LICENSE for details.
76
76
  "README.rdoc",
77
77
  "Rakefile",
78
78
  "lib/shopify_api.rb",
79
+ "lib/shopify_api/cli.rb",
79
80
  "shopify_api.gemspec",
80
81
  "test/order_test.rb",
81
82
  "test/shopify_api_test.rb",
@@ -92,18 +93,20 @@ Copyright (c) 2009 "JadedPixel inc.". See LICENSE for details.
92
93
  "test/shopify_api_test.rb",
93
94
  "test/test_helper.rb"
94
95
  ]
96
+ s.executables = ['shopify']
95
97
 
96
- if s.respond_to? :specification_version then
98
+ if s.respond_to? :specification_version
97
99
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
98
100
  s.specification_version = 3
99
-
100
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
101
- s.add_runtime_dependency(%q<activeresource>, [">= 2.2.2"])
102
- else
103
- s.add_dependency(%q<activeresource>, [">= 2.2.2"])
104
- end
101
+ end
102
+
103
+ s.add_dependency("activeresource", [">= 2.2.2"])
104
+ s.add_dependency("thor", [">= 0.14.4"])
105
+
106
+ if s.respond_to?(:add_development_dependency)
107
+ s.add_development_dependency("mocha", ">= 0.9.8")
105
108
  else
106
- s.add_dependency(%q<activeresource>, [">= 2.2.2"])
109
+ s.add_dependency("mocha", ">= 0.9.8")
107
110
  end
108
111
  end
109
112
 
@@ -1,5 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'test/unit'
3
+ require 'mocha'
3
4
 
4
5
  $LOAD_PATH.unshift(File.dirname(__FILE__))
5
6
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shopify_api
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
- - 1
9
- - 3
10
- version: 1.1.3
8
+ - 2
9
+ - 0
10
+ version: 1.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Tobias L\xC3\xBCtke"
@@ -36,6 +36,38 @@ dependencies:
36
36
  version: 2.2.2
37
37
  type: :runtime
38
38
  version_requirements: *id001
39
+ - !ruby/object:Gem::Dependency
40
+ name: thor
41
+ prerelease: false
42
+ requirement: &id002 !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ hash: 47
48
+ segments:
49
+ - 0
50
+ - 14
51
+ - 4
52
+ version: 0.14.4
53
+ type: :runtime
54
+ version_requirements: *id002
55
+ - !ruby/object:Gem::Dependency
56
+ name: mocha
57
+ prerelease: false
58
+ requirement: &id003 !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ hash: 43
64
+ segments:
65
+ - 0
66
+ - 9
67
+ - 8
68
+ version: 0.9.8
69
+ type: :development
70
+ version_requirements: *id003
39
71
  description: "= Shopify API\n\n\
40
72
  The Shopify API gem allows Ruby developers to programmatically access the admin section of Shopify stores.\n\n\
41
73
  The API is implemented as XML over HTTP using all four verbs (GET/POST/PUT/DELETE). Each resource, like Order, Product, or Collection, has its own URL and is manipulated in isolation. In other words, we\xE2\x80\x99ve tried to make the API follow the REST principles as much as possible.\n\n\n\
@@ -57,8 +89,8 @@ description: "= Shopify API\n\n\
57
89
  == Copyright\n\n\
58
90
  Copyright (c) 2009 \"JadedPixel inc.\". See LICENSE for details.\n"
59
91
  email: developers@jadedpixel.com
60
- executables: []
61
-
92
+ executables:
93
+ - shopify
62
94
  extensions: []
63
95
 
64
96
  extra_rdoc_files:
@@ -72,10 +104,12 @@ files:
72
104
  - README.rdoc
73
105
  - Rakefile
74
106
  - lib/shopify_api.rb
107
+ - lib/shopify_api/cli.rb
75
108
  - shopify_api.gemspec
76
109
  - test/order_test.rb
77
110
  - test/shopify_api_test.rb
78
111
  - test/test_helper.rb
112
+ - bin/shopify
79
113
  has_rdoc: true
80
114
  homepage: http://github.com/Shopify/shopify_api
81
115
  licenses: []