Module: TipsanityMerchantExtractor::TigerDirect

Includes:
LinkShare
Defined in:
lib/tipsanity_merchant_extractor/tiger_direct.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from LinkShare

#call_to_linkshare, #extract_linkshare, #provide_buy_url

Class Method Details

.extended(base) ⇒ Object



5
6
7
8
9
# File 'lib/tipsanity_merchant_extractor/tiger_direct.rb', line 5

def self.extended(base)
  if base == AttributeExtractor
    base.send :include, TigerDirect
  end
end

Instance Method Details

#find_product_tiger_direct(merchant_url, token, mid) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/tipsanity_merchant_extractor/tiger_direct.rb', line 20

def find_product_tiger_direct merchant_url, token, mid
	if is_merchant_linkshare_tiger_direct?(merchant_url){}
		skuid_filter = URI.decode_www_form(URI(merchant_url).query).assoc("EdpNo")
		skuid = skuid_filter ? skuid_filter.last : nil
      if skuid
        begin
          scraped_screen = Nokogiri::HTML(open(merchant_url))
          @product_name = scraped_screen.search("#ProductReview .rightCol .prodName h1").text
          @description = scraped_screen.search("#WriteUp").text.strip
          list_price = scraped_screen.search("#ProductReview .rightCol .prodInfo dd.priceList").first || scraped_screen.search("#ProductReview .rightCol .prodInfo dd.pricemapa").first
          @list_price = list_price.text.gsub(/[$]/, "")#.to_f
          final_price = scraped_screen.search("#ProductReview .rightCol .prodInfo .salePrice").first || list_price
          @final_price = final_price.text.gsub(/[$]/,"")#.to_f 
          @image_url = scraped_screen.search("#ProductReview .leftCol .previewImgHolder a img").first.attributes["src"].value
          @details_url = provide_buy_url(token, mid, merchant_url)
          @categories = scraped_screen.search("#ProductReview .rightCol .breadCrumbs li a").first.text
          @response_object = scraped_screen
          @product_token = skuid
          @errors = []
        rescue
          @errors << "Some errors from api information"
        end
      else
        @errors << "Not valid Uri. Please make sure, Uri contain 'prod' and skuid."
      end
    else
      block_given? ? yield("It is not bestbuy merchant connected with commission junction.") : "It is not bestbuy merchant connected with commission junction."
    end
end

#is_merchant_linkshare_tiger_direct?(merchant_url) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
# File 'lib/tipsanity_merchant_extractor/tiger_direct.rb', line 11

def is_merchant_linkshare_tiger_direct?(merchant_url)
	URI(merchant_url).host
	if URI(merchant_url).host == TipsanityMerchantExtractor::RegisteredMerchantList::REGISTERED_MERCHANT[:linkshare][1][:tiger_direct]
      block_given? ? true : TipsanityMerchantExtractor::RegisteredMerchantList::REGISTERED_MERCHANT[:linkshare][1][:tiger_direct]
    else
      false
    end
end