Module: ShopifyTheme
- Includes:
- HTTParty
- Defined in:
- lib/shopify_theme.rb,
lib/shopify_theme/cli.rb,
lib/shopify_theme/version.rb
Defined Under Namespace
Classes: Cli
Constant Summary collapse
- NOOPParser =
Proc.new {|data, format| {} }
- VERSION =
"0.0.10"
Class Method Summary collapse
- .asset_list ⇒ Object
- .check_config ⇒ Object
- .config ⇒ Object
- .delete_asset(asset) ⇒ Object
- .get_asset(asset) ⇒ Object
- .ignore_files ⇒ Object
- .is_binary_data?(string) ⇒ Boolean
- .path ⇒ Object
- .send_asset(data) ⇒ Object
- .shopify ⇒ Object
Class Method Details
.asset_list ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/shopify_theme.rb', line 7 def self.asset_list # HTTParty parser chokes on assest listing, have it noop # and then use a rel JSON parser. response = shopify.get(path, :parser => NOOPParser) assets = JSON.parse(response.body)["assets"].collect {|a| a['key'] } # Remove any .css files if a .css.liquid file exists assets.reject{|a| assets.include?("#{a}.liquid") } end |
.check_config ⇒ Object
50 51 52 |
# File 'lib/shopify_theme.rb', line 50 def self.check_config shopify.get(path).code == 200 end |
.config ⇒ Object
30 31 32 |
# File 'lib/shopify_theme.rb', line 30 def self.config @config ||= YAML.load(File.read('config.yml')) end |
.delete_asset(asset) ⇒ Object
26 27 28 |
# File 'lib/shopify_theme.rb', line 26 def self.delete_asset(asset) shopify.delete(path, :body =>{:asset => {:key => asset}}) end |
.get_asset(asset) ⇒ Object
16 17 18 19 20 |
# File 'lib/shopify_theme.rb', line 16 def self.get_asset(asset) response = shopify.get(path, :query =>{:asset => {:key => asset}}, :parser => NOOPParser) # HTTParty json parsing is broken? JSON.parse(response.body)["asset"] end |
.ignore_files ⇒ Object
38 39 40 |
# File 'lib/shopify_theme.rb', line 38 def self.ignore_files @ignore_files ||= (config[:ignore_files] || []).compact.collect { |r| Regexp.new(r) } end |
.is_binary_data?(string) ⇒ Boolean
42 43 44 45 46 47 48 |
# File 'lib/shopify_theme.rb', line 42 def self.is_binary_data?(string) if string.respond_to?(:encoding) string.encoding == "US-ASCII" else ( string.count( "^ -~", "^\r\n" ).fdiv(string.size) > 0.3 || string.index( "\x00" ) ) unless string.empty? end end |
.path ⇒ Object
34 35 36 |
# File 'lib/shopify_theme.rb', line 34 def self.path @path ||= config[:theme_id] ? "/admin/themes/#{config[:theme_id]}/assets.json" : "/admin/assets.json" end |
.send_asset(data) ⇒ Object
22 23 24 |
# File 'lib/shopify_theme.rb', line 22 def self.send_asset(data) shopify.put(path, :body =>{:asset => data}) end |
.shopify ⇒ Object
55 56 57 58 59 |
# File 'lib/shopify_theme.rb', line 55 def self.shopify basic_auth config[:api_key], config[:password] base_uri "https://#{config[:store]}" ShopifyTheme end |