guard-shopify 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ *.gem
@@ -1,25 +1,43 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- guard-shopify (0.0.1)
5
- shopify_api (~> 2.2.0)
4
+ guard-shopify (0.0.2)
5
+ guard (>= 0.10.0)
6
+ ptools (~> 1.2.1)
7
+ shopify_api (~> 3.0.0)
6
8
 
7
9
  GEM
8
10
  remote: http://rubygems.org/
9
11
  specs:
10
- activemodel (3.1.3)
11
- activesupport (= 3.1.3)
12
+ activemodel (3.2.3)
13
+ activesupport (= 3.2.3)
12
14
  builder (~> 3.0.0)
15
+ activeresource (3.2.3)
16
+ activemodel (= 3.2.3)
17
+ activesupport (= 3.2.3)
18
+ activesupport (3.2.3)
13
19
  i18n (~> 0.6)
14
- activeresource (3.1.3)
15
- activemodel (= 3.1.3)
16
- activesupport (= 3.1.3)
17
- activesupport (3.1.3)
18
20
  multi_json (~> 1.0)
19
21
  builder (3.0.0)
22
+ diff-lcs (1.1.3)
23
+ ffi (1.0.11)
24
+ guard (0.10.0)
25
+ ffi (>= 0.5.0)
26
+ thor (~> 0.14.6)
27
+ guard-rspec (0.6.0)
28
+ guard (>= 0.10.0)
20
29
  i18n (0.6.0)
21
- multi_json (1.0.4)
22
- shopify_api (2.2.0)
30
+ multi_json (1.3.4)
31
+ ptools (1.2.2)
32
+ rspec (2.8.0)
33
+ rspec-core (~> 2.8.0)
34
+ rspec-expectations (~> 2.8.0)
35
+ rspec-mocks (~> 2.8.0)
36
+ rspec-core (2.8.0)
37
+ rspec-expectations (2.8.0)
38
+ diff-lcs (~> 1.1.2)
39
+ rspec-mocks (2.8.0)
40
+ shopify_api (3.0.0)
23
41
  activeresource (>= 3.0.0)
24
42
  thor (>= 0.14.4)
25
43
  thor (0.14.6)
@@ -28,4 +46,6 @@ PLATFORMS
28
46
  ruby
29
47
 
30
48
  DEPENDENCIES
49
+ guard-rspec (~> 0.6.0)
31
50
  guard-shopify!
51
+ rspec (~> 2.8.0)
@@ -0,0 +1,36 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2 do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+ # Capybara request specs
17
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
18
+ end
19
+
20
+
21
+ guard 'rspec', :version => 2 do
22
+ watch(%r{^spec/.+_spec\.rb$})
23
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
24
+ watch('spec/spec_helper.rb') { "spec" }
25
+
26
+ # Rails example
27
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
28
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
29
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
30
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
31
+ watch('config/routes.rb') { "spec/routing" }
32
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
33
+ # Capybara request specs
34
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
35
+ end
36
+
data/README.md CHANGED
@@ -9,9 +9,10 @@ Installation
9
9
  Please be sure to have [Guard](https://github.com/guard/guard) installed before you continue.
10
10
 
11
11
  Install the gem:
12
+
12
13
  $ gem install guard-shopify
13
14
 
14
- Add it to your Gemfile (inside development group):
15
+ Add guard-shopify to your Gemfile (inside the development group):
15
16
 
16
17
  ``` ruby
17
18
  group :development do
@@ -19,22 +20,8 @@ group :development do
19
20
  end
20
21
  ```
21
22
 
22
- Add the guard definition to your Guardfile:
23
- $ guard init rspec
24
-
25
- When first run the gem will prompt you to enter your API key, password and store url. Follow [these instructions](http://http://wiki.shopify.com/Shopify_Textmate_Bundle) to get this information (you only need to do it once).
26
-
27
- Hello Hungry Academy
28
- ====================
29
-
30
- I wrote this project for two reasons: I needed a code sample for my hungry academy application and I wanted to make my own client work significantly less painful.
31
-
32
- The best solution that existed before this gem was a Textmate bundle that allows you to upload modifications to Shopify with a keystroke. It sounds like a pretty good solution but Textmate and I broke up a long time ago and even having to save, upload, tab and refresh was a bit laborious for me.
33
-
34
- It occurred to me that a guard could watch my filesystem for changes and upload modifications immediately on saving, allowing me to use vim instead of Textmate.
35
-
36
- This gem is not as full featured as I would like it to be, nor is it well tested, but it is my first independent open source contribution that may actually get used, and I'm quite pleased with this first release.
23
+ Add the guard definition to your Guardfile:
37
24
 
38
- The immediate roadmap for guard-shopify includes test coverage, the ability to upload new files, delete existing files and optionally prompt before uploading changes to Shopify.
25
+ $ guard init guard
39
26
 
40
- I'm only counting the hungry academy section of this file towards the 200 word limit you specified; if that's unacceptable please let me know and I will remove the installation instructions.
27
+ When first run the gem will prompt you to enter your API key, password and store url. Follow [these instructions](http://wiki.shopify.com/Shopify_Textmate_Bundle) to get this information (you only need to do it once).
@@ -4,7 +4,7 @@ require "guard/shopify/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "guard-shopify"
7
- s.version = Guard::Shopify::VERSION
7
+ s.version = Guard::ShopifyVersion::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Jonan Scheffler"]
10
10
  s.email = ["jonanscheffler+rubygems@gmail.com"]
@@ -20,6 +20,9 @@ Gem::Specification.new do |s|
20
20
  s.require_paths = ["lib"]
21
21
 
22
22
  s.add_dependency 'guard', '>= 0.10.0'
23
- s.add_dependency 'shopify_api', '~> 2.2.0'
23
+ s.add_dependency 'shopify_api', '~> 3.0.0'
24
24
  s.add_dependency 'ptools', '~> 1.2.1'
25
+
26
+ s.add_development_dependency 'rspec', '~> 2.8.0'
27
+ s.add_development_dependency 'guard-rspec', '~> 0.6.0'
25
28
  end
@@ -1,4 +1,5 @@
1
1
  require 'guard'
2
+ require 'yaml'
2
3
  require 'guard/guard'
3
4
  require 'shopify_api'
4
5
  require 'ptools'
@@ -6,18 +7,44 @@ require 'ptools'
6
7
  module Guard
7
8
  class Shopify < Guard
8
9
  def start
9
- set_config unless File.exists?("#{ENV['HOME']}/.guard_shopify")
10
+ set_config unless File.exists?(config_file_path)
10
11
  get_credentials_from_config
11
12
  authenticate_with_shopify
12
13
  get_main_theme_id
13
14
  end
14
15
 
16
+ def config_file_path
17
+ "#{ENV['HOME']}/.guard_shopify"
18
+ end
19
+
15
20
  def get_credentials_from_config
16
- credentials = File.read("#{ENV['HOME']}/.guard_shopify").split("\n")
21
+ config = YAML.load_file(config_file_path)
22
+ # Check if config file is old format or new YAML-based one
23
+ unless config['secret']
24
+ config = upgrade_config_file
25
+ end
26
+ @url = config['url']
27
+ @api_key = config['api_key']
28
+ @password = config['password']
29
+ end
30
+
31
+ # Old line-based config file format
32
+ def upgrade_config_file
33
+ puts "Old config file found, upgrading..."
34
+
35
+ credentials = File.read(config_file_path).split("\n")
36
+ config = {}
37
+ config['api_key'] = credentials[0]
38
+ config['password'] = credentials[1]
39
+ config['url'] = credentials[2]
17
40
 
18
- @api_key = credentials[0]
19
- @password = credentials[1]
20
- @url = credentials[2]
41
+ config['secret'] = prompt "Please enter your API Shared Secret"
42
+
43
+ write_config config
44
+
45
+ puts 'Upgraded old config file to new format'
46
+
47
+ config
21
48
  end
22
49
 
23
50
  def authenticate_with_shopify
@@ -26,9 +53,7 @@ module Guard
26
53
 
27
54
  def get_main_theme_id
28
55
  themes = ShopifyAPI::Theme.find(:all)
29
-
30
56
  main_theme = themes.select {|t| t.role == 'main'}.first
31
-
32
57
  @theme_id = main_theme.id
33
58
  end
34
59
 
@@ -67,20 +92,31 @@ module Guard
67
92
 
68
93
  private
69
94
 
95
+ def prompt msg=nil
96
+ print "#{msg || 'Please type'}: "
97
+ gets.chomp
98
+ end
99
+
100
+ def write_config config
101
+ File.open(config_file_path, 'w') {|f| f.write(YAML.dump(config)) }
102
+ end
103
+
70
104
  def set_config
105
+ config = {}
71
106
  puts "This guard needs your API credentials to access your Shopify store."
72
- puts "Please enter your API key:"
73
- api_key = gets.chomp
74
- puts "Please enter your password:"
75
- password = gets.chomp
76
- puts "Please enter your store's url (e.g. awesomesauce.myshopify.com):"
77
- url = gets.chomp
78
- url = url + '.myshopify.com' unless url.include?('myshopify.com')
79
107
 
80
- config = [api_key, password, url].join("\n")
81
-
82
- File.open("#{ENV['HOME']}/.guard_shopify", 'w') {|f| f.write(config) }
83
- puts "Credentials saved to #{ENV['HOME']}/.guard_shopify"
108
+ config['api_key'] = prompt 'Please enter your API key'
109
+
110
+ config['secret'] = prompt 'Please enter your API Shared Secret'
111
+
112
+ config['url'] = prompt "Please enter your store's url (e.g. awesomesauce.myshopify.com)"
113
+
114
+ unless config['url'].include?('myshopify.com')
115
+ config['url'] = "#{config['url']}.myshopify.com"
116
+ end
117
+
118
+ write_config config
119
+ puts "Credentials saved to #{config_file_path}"
84
120
  end
85
121
  end
86
122
  end
@@ -1,5 +1,5 @@
1
1
  module Guard
2
- module Shopify
3
- VERSION = "0.0.2"
2
+ module ShopifyVersion
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -0,0 +1 @@
1
+ The accompanying photo was taken in a purikura machine in Tokyo during RubyKaigi 2011.
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ describe Guard::Shopify do
4
+ before do
5
+ subject.stub!(:authenticate_with_shopify => true)
6
+ end
7
+
8
+ let(:subject) {Guard::Shopify.new}
9
+
10
+ context "run_on_change" do
11
+ let(:path) {'spec/fixtures/explanation.txt'}
12
+
13
+ before do
14
+ ShopifyAPI::Asset.stub!(:find) { true }
15
+ end
16
+
17
+ it "should call upload_binary_asset for binary files" do
18
+ path = 'spec/fixtures/purikura_avatar.jpg'
19
+
20
+ subject.should_receive :upload_binary_asset
21
+ subject.run_on_change([path])
22
+ end
23
+
24
+ it "should call upload_text_asset for text files" do
25
+ subject.should_receive :upload_text_asset
26
+ subject.run_on_change([path])
27
+ end
28
+
29
+ it "should notify the user when a file is changed" do
30
+ ShopifyAPI::Asset.stub!(:find) { false }
31
+ Guard::Notifier.should_receive(:notify).with /#{path}/
32
+ subject.run_on_change([path])
33
+ end
34
+ end
35
+
36
+ context "start" do
37
+ it "should prompt the user for their credentials if the config file doesn't exist" do
38
+ File.stub!(:exists?) { false }
39
+ subject.should_receive(:set_config).and_return true
40
+ subject.start
41
+ end
42
+ end
43
+
44
+ context "set_config" do
45
+ it "should write the credentials to a config file" do
46
+ File.should_receive(:open).with "#{ENV['HOME']}/.guard_shopify", "w"
47
+ subject.stub!(:gets).and_return('Foo')
48
+ subject.send(:set_config)
49
+ end
50
+
51
+ it "should accurately to the user the location of the config file" do
52
+ subject.should_receive(:puts).with "Credentials saved to #{ENV['HOME']}/.guard_shopify"
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,22 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'guard'
4
+ require 'guard/shopify'
5
+ require 'shopify_api'
6
+ require 'ptools'
7
+
8
+ RSpec.configure do |config|
9
+
10
+ config.color_enabled = true
11
+ config.filter_run :focus => true
12
+ config.run_all_when_everything_filtered = true
13
+
14
+ config.before(:each) do
15
+ ENV["GUARD_ENV"] = 'test'
16
+ @project_path = Pathname.new(File.expand_path('../../', __FILE__))
17
+ end
18
+
19
+ config.after(:each) do
20
+ ENV["GUARD_ENV"] = nil
21
+ end
22
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard-shopify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-10 00:00:00.000000000 Z
12
+ date: 2012-05-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: guard
16
- requirement: &70286699669020 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,21 +21,31 @@ dependencies:
21
21
  version: 0.10.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70286699669020
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.10.0
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: shopify_api
27
- requirement: &70286699668200 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ~>
31
36
  - !ruby/object:Gem::Version
32
- version: 2.2.0
37
+ version: 3.0.0
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *70286699668200
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 3.0.0
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: ptools
38
- requirement: &70286699667720 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ~>
@@ -43,7 +53,44 @@ dependencies:
43
53
  version: 1.2.1
44
54
  type: :runtime
45
55
  prerelease: false
46
- version_requirements: *70286699667720
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.2.1
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 2.8.0
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 2.8.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: guard-rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 0.6.0
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 0.6.0
47
94
  description: This gem allows guard to watch a Shopify template directory for changes
48
95
  and then upload them immediately to Shopify using their API.
49
96
  email:
@@ -52,9 +99,11 @@ executables: []
52
99
  extensions: []
53
100
  extra_rdoc_files: []
54
101
  files:
102
+ - .gitignore
55
103
  - .rvmrc
56
104
  - Gemfile
57
105
  - Gemfile.lock
106
+ - Guardfile
58
107
  - LICENSE
59
108
  - README.md
60
109
  - Rakefile
@@ -62,6 +111,10 @@ files:
62
111
  - lib/guard/shopify.rb
63
112
  - lib/guard/shopify/templates/Guardfile
64
113
  - lib/guard/shopify/version.rb
114
+ - spec/fixtures/explanation.txt
115
+ - spec/fixtures/purikura_avatar.jpg
116
+ - spec/guard/shopify_spec.rb
117
+ - spec/spec_helper.rb
65
118
  homepage: https://github.com/1337807/guard-shopify
66
119
  licenses: []
67
120
  post_install_message:
@@ -82,8 +135,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
135
  version: '0'
83
136
  requirements: []
84
137
  rubyforge_project: guard-shopify
85
- rubygems_version: 1.8.10
138
+ rubygems_version: 1.8.23
86
139
  signing_key:
87
140
  specification_version: 3
88
141
  summary: Gem to upload Shopify template modifications.
89
- test_files: []
142
+ test_files:
143
+ - spec/fixtures/explanation.txt
144
+ - spec/fixtures/purikura_avatar.jpg
145
+ - spec/guard/shopify_spec.rb
146
+ - spec/spec_helper.rb