Class: MercatorIcecat::Access

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Attribute Details

#base_uriObject

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_urlObject

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_urlObject

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

#langObject

Returns the value of attribute lang.



6
7
8
# File 'app/models/mercator_icecat/access.rb', line 6

def lang
  @lang
end

#open_uri_optionsObject

Returns the value of attribute open_uri_options.



6
7
8
# File 'app/models/mercator_icecat/access.rb', line 6

def open_uri_options
  @open_uri_options
end

#passwordObject

Returns the value of attribute password.



6
7
8
# File 'app/models/mercator_icecat/access.rb', line 6

def password
  @password
end

#typObject

Returns the value of attribute typ.



6
7
8
# File 'app/models/mercator_icecat/access.rb', line 6

def typ
  @typ
end

#userObject

Returns the value of attribute user.



6
7
8
# File 'app/models/mercator_icecat/access.rb', line 6

def user
  @user
end

#vendorObject

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, open_uri_options.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, open_uri_options.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_optionsObject

— Class Methods — #



19
20
21
# File 'app/models/mercator_icecat/access.rb', line 19

def self.open_uri_options
  {: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), open_uri_options).read if product_id
  return open(BASE_URL + "/" + path, open_uri_options).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