Class: MercatorIcecat::Access
- Inherits:
-
Object
- Object
- MercatorIcecat::Access
- Defined in:
- app/models/mercator_icecat/access.rb
Constant Summary collapse
- USER =
"donrudl"- PASSWORD =
"cpP42J"- VENDOR =
"HP"- LANG =
"int"- TYP =
"productxml"- BASE_URL =
"http://data.icecat.biz"- FULL_INDEX_URL =
BASE_URL + "/export/freexml/files.index.xml"
- DAILY_INDEX_URL =
BASE_URL + "/export/freexml/daily.index.xml"
Instance Attribute Summary collapse
-
#base_uri ⇒ Object
Returns the value of attribute base_uri.
-
#daily_index_url ⇒ Object
Returns the value of attribute daily_index_url.
-
#full_index_url ⇒ Object
Returns the value of attribute full_index_url.
-
#lang ⇒ Object
Returns the value of attribute lang.
-
#open_uri_options ⇒ Object
Returns the value of attribute open_uri_options.
-
#password ⇒ Object
Returns the value of attribute password.
-
#typ ⇒ Object
Returns the value of attribute typ.
-
#user ⇒ Object
Returns the value of attribute user.
-
#vendor ⇒ Object
Returns the value of attribute vendor.
Class Method Summary collapse
- .download_index(full: false) ⇒ Object
-
.open_uri_options ⇒ Object
— Class Methods — #.
-
.product(product_id: nil, path: nil) ⇒ Object
accepts product_id or path as parameter.
- .product_url(product_id: nil) ⇒ Object
Instance Attribute Details
#base_uri ⇒ Object
Returns the value of attribute base_uri.
6 7 8 |
# File 'app/models/mercator_icecat/access.rb', line 6 def base_uri @base_uri end |
#daily_index_url ⇒ Object
Returns the value of attribute daily_index_url.
6 7 8 |
# File 'app/models/mercator_icecat/access.rb', line 6 def daily_index_url @daily_index_url end |
#full_index_url ⇒ Object
Returns the value of attribute full_index_url.
6 7 8 |
# File 'app/models/mercator_icecat/access.rb', line 6 def full_index_url @full_index_url end |
#lang ⇒ Object
Returns the value of attribute lang.
6 7 8 |
# File 'app/models/mercator_icecat/access.rb', line 6 def lang @lang end |
#open_uri_options ⇒ Object
Returns the value of attribute open_uri_options.
6 7 8 |
# File 'app/models/mercator_icecat/access.rb', line 6 def end |
#password ⇒ Object
Returns the value of attribute password.
6 7 8 |
# File 'app/models/mercator_icecat/access.rb', line 6 def password @password end |
#typ ⇒ Object
Returns the value of attribute typ.
6 7 8 |
# File 'app/models/mercator_icecat/access.rb', line 6 def typ @typ end |
#user ⇒ Object
Returns the value of attribute user.
6 7 8 |
# File 'app/models/mercator_icecat/access.rb', line 6 def user @user end |
#vendor ⇒ Object
Returns the value of attribute vendor.
6 7 8 |
# File 'app/models/mercator_icecat/access.rb', line 6 def vendor @vendor end |
Class Method Details
.download_index(full: false) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/models/mercator_icecat/access.rb', line 23 def self.download_index(full: false) if full file = File.new(Rails.root.join("vendor","catalogs","files.index.xml"), "w") io = open( FULL_INDEX_URL, .merge({"Accept-Encoding" => "gzip"}) ) else file = File.new(Rails.root.join("vendor","catalogs",Date.today.to_s + "-index.xml"), "w") io = open( DAILY_INDEX_URL, .merge({"Accept-Encoding" => "gzip"}) ) end unzipped_io = Zlib::GzipReader.new( io ) unzipped_io.each do |line| file.write line end file.close io.close end |
.open_uri_options ⇒ Object
— Class Methods — #
19 20 21 |
# File 'app/models/mercator_icecat/access.rb', line 19 def self. {:http_basic_authentication => [self::USER, self::PASSWORD]} end |
.product(product_id: nil, path: nil) ⇒ Object
accepts product_id or path as parameter
39 40 41 42 |
# File 'app/models/mercator_icecat/access.rb', line 39 def self.product(product_id: nil, path: nil) # accepts product_id or path as parameter return open(self.product_url(product_id), ).read if product_id return open(BASE_URL + "/" + path, ).read if path end |
.product_url(product_id: nil) ⇒ Object
44 45 46 |
# File 'app/models/mercator_icecat/access.rb', line 44 def self.product_url(product_id: nil) BASE_URL + "/xml_s3/xml_server3.cgi?prod_id=" + product_id + ";vendor=" + VENDOR + ";lang=" + LANG + ";output=" + TYP end |