Class: Gemgento::AssetFile
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Gemgento::AssetFile
- Defined in:
- app/models/gemgento/asset_file.rb
Overview
Class Method Summary collapse
-
.from_url(url) ⇒ TempFile
Get file from Magento.
-
.valid_url(url) ⇒ Boolean
Check that a url is valid.
Class Method Details
.from_url(url) ⇒ TempFile
Get file from Magento.
44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/models/gemgento/asset_file.rb', line 44 def self.from_url(url) if Gemgento::Config[:magento][:auth_username].blank? open(url) else open(url, http_basic_authentication: [ Gemgento::Config[:magento][:auth_username], Gemgento::Config[:magento][:auth_password] ] ) end end |
.valid_url(url) ⇒ Boolean
Check that a url is valid. Assumes url is pointing to Magento installation.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/models/gemgento/asset_file.rb', line 22 def self.valid_url(url) uri = URI.parse(url) req = Net::HTTP::Get.new(uri) unless Gemgento::Config[:magento][:auth_username].blank? req.basic_auth Gemgento::Config[:magento][:auth_username], Gemgento::Config[:magento][:auth_password] end http = Net::HTTP.new(uri.hostname, uri.port) http.use_ssl = uri.port == 443 res = http.start do |http| http.use_ssl = uri.port == 443 http.request(req) end return res.code == '200' end |