Class: TipsanityMerchantExtractor::AttributeExtractor

Inherits:
Object
  • Object
show all
Extended by:
UrlFormatter
Defined in:
lib/tipsanity_merchant_extractor/attribute_extractor.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from UrlFormatter

format_url, url_regexp, valid_url

Constructor Details

#initialize(merchant_url, *args) ⇒ AttributeExtractor

end of self methods



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/tipsanity_merchant_extractor/attribute_extractor.rb', line 44

def initialize merchant_url, *args
  @options = args.extract_options!
  @url = merchant_url
  @merchant_url = self.class.format_url @url
  @host_provider = URI(@merchant_url).host
  @errors = []
  case self.class.who_is_merchant(@merchant_url)
  when RegisteredMerchantList::REGISTERED_MERCHANT[:amazon]
  	find_product_amazon @merchant_url

  when RegisteredMerchantList::REGISTERED_MERCHANT[:cjunction][:bestbuy]
  	find_product_cj @merchant_url

  when RegisteredMerchantList::REGISTERED_MERCHANT[:linkshare][0][:rakuten]
    find_product_rakuten @merchant_url, @options[:linkshare][:token], RegisteredMerchantList::REGISTERED_MERCHANT[:linkshare][0][:mid]

  when RegisteredMerchantList::REGISTERED_MERCHANT[:linkshare][1][:tiger_direct]
    find_product_tiger_direct @merchant_url, @options[:linkshare][:token], RegisteredMerchantList::REGISTERED_MERCHANT[:linkshare][1][:mid]

  else
    @product_name = nil
    @description = nil
    @list_price = nil
    @currency_code = nil
    @expiry_date = nil
    @image_url = nil
    @details_url = nil
    @final_price = nil
    @categories = nil
    @errors << "Unable to retrive from api"
  end
end

Instance Attribute Details

#categoriesObject

Returns the value of attribute categories.



8
9
10
# File 'lib/tipsanity_merchant_extractor/attribute_extractor.rb', line 8

def categories
  @categories
end

#currency_codeObject

Returns the value of attribute currency_code.



8
9
10
# File 'lib/tipsanity_merchant_extractor/attribute_extractor.rb', line 8

def currency_code
  @currency_code
end

#descriptionObject

Returns the value of attribute description.



8
9
10
# File 'lib/tipsanity_merchant_extractor/attribute_extractor.rb', line 8

def description
  @description
end

#details_urlObject

Returns the value of attribute details_url.



8
9
10
# File 'lib/tipsanity_merchant_extractor/attribute_extractor.rb', line 8

def details_url
  @details_url
end

#expiry_dateObject

Returns the value of attribute expiry_date.



8
9
10
# File 'lib/tipsanity_merchant_extractor/attribute_extractor.rb', line 8

def expiry_date
  @expiry_date
end

#final_priceObject

Returns the value of attribute final_price.



8
9
10
# File 'lib/tipsanity_merchant_extractor/attribute_extractor.rb', line 8

def final_price
  @final_price
end

#host_providerObject

Returns the value of attribute host_provider.



8
9
10
# File 'lib/tipsanity_merchant_extractor/attribute_extractor.rb', line 8

def host_provider
  @host_provider
end

#image_urlObject

Returns the value of attribute image_url.



8
9
10
# File 'lib/tipsanity_merchant_extractor/attribute_extractor.rb', line 8

def image_url
  @image_url
end

#is_dpObject

Returns the value of attribute is_dp.



8
9
10
# File 'lib/tipsanity_merchant_extractor/attribute_extractor.rb', line 8

def is_dp
  @is_dp
end

#list_priceObject

Returns the value of attribute list_price.



8
9
10
# File 'lib/tipsanity_merchant_extractor/attribute_extractor.rb', line 8

def list_price
  @list_price
end

#merchant_urlObject

Returns the value of attribute merchant_url.



8
9
10
# File 'lib/tipsanity_merchant_extractor/attribute_extractor.rb', line 8

def merchant_url
  @merchant_url
end

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'lib/tipsanity_merchant_extractor/attribute_extractor.rb', line 8

def options
  @options
end

#product_nameObject

Returns the value of attribute product_name.



8
9
10
# File 'lib/tipsanity_merchant_extractor/attribute_extractor.rb', line 8

def product_name
  @product_name
end

#product_tokenObject

Returns the value of attribute product_token.



8
9
10
# File 'lib/tipsanity_merchant_extractor/attribute_extractor.rb', line 8

def product_token
  @product_token
end

#response_objectObject

Returns the value of attribute response_object.



8
9
10
# File 'lib/tipsanity_merchant_extractor/attribute_extractor.rb', line 8

def response_object
  @response_object
end

Class Method Details

.who_is_merchant(merchant_url) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/tipsanity_merchant_extractor/attribute_extractor.rb', line 26

def who_is_merchant(merchant_url)
  case URI(merchant_url).host
  when is_merchant_amazon?(merchant_url)
    RegisteredMerchantList::REGISTERED_MERCHANT[:amazon]
  when is_merchant_cj_bestbuy?(merchant_url)
    RegisteredMerchantList::REGISTERED_MERCHANT[:cjunction][:bestbuy]
  when is_merchant_linkshare_rakuten?(merchant_url)
    RegisteredMerchantList::REGISTERED_MERCHANT[:linkshare][0][:rakuten]
  when is_merchant_linkshare_tiger_direct?(merchant_url)
    RegisteredMerchantList::REGISTERED_MERCHANT[:linkshare][1][:tiger_direct]
  else
    "this merchant is not registered merchant with our system. Please recommend us to affliate with us."
    # URI(merchant_url).host
  end
end