Module: TipsanityMerchantExtractor::Rakuten

Includes:
LinkShare
Defined in:
lib/tipsanity_merchant_extractor/rakuten.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/rakuten.rb', line 5

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

Instance Method Details

#extract_linkshare_rakuten(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
# File 'lib/tipsanity_merchant_extractor/rakuten.rb', line 20

def extract_linkshare_rakuten(merchant_url, token, mid)
  if is_merchant_linkshare_rakuten?(merchant_url){}
    path_array = URI(merchant_url).path.split('/')
    skuid_stringed = path_array.last.gsub(/\D/, "")
    skuid = skuid_stringed.to_i==0 ? nil : skuid_stringed.to_i
    if skuid
      begin
        scraped_screen = Nokogiri::HTML(open(merchant_url))
        @product_name = scraped_screen.search('#AuthorArtistTitle_productTitle').first.text
        @description = scraped_screen.search('#divDescription').first.text
        @final_price = scraped_screen.search('#spanMainTotalPrice').first.text.gsub(/[$]/, "").to_f
        @list_price = scraped_screen.search('#spanMainListPrice').first ? scraped_screen.search('#spanMainListPrice').first.text.gsub(/[$]/, "").to_f : @final_price 
        @image_url = scraped_screen.search(".holder-image .item.image img").first.attributes["src"].value
        @details_url = provide_buy_url(token, mid, merchant_url)
        @categories = scraped_screen.search('#anchorSimilarProds').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

#find_product_rakuten(merchant_url, token, mid) ⇒ Object



49
50
51
# File 'lib/tipsanity_merchant_extractor/rakuten.rb', line 49

def find_product_rakuten merchant_url, token, mid
  extract_linkshare_rakuten merchant_url, token, mid
end

#is_merchant_linkshare_rakuten?(merchant_url) ⇒ Boolean

Returns:

  • (Boolean)


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

def is_merchant_linkshare_rakuten?(merchant_url)
  is_rakuten = ((URI(merchant_url).host == TipsanityMerchantExtractor::RegisteredMerchantList::REGISTERED_MERCHANT[:linkshare][0][:rakuten]) or !(URI(merchant_url).host.match(/rakuten/).nil?))
  if is_rakuten
    block_given? ? true : ((URI(merchant_url).host == TipsanityMerchantExtractor::RegisteredMerchantList::REGISTERED_MERCHANT[:linkshare][0][:rakuten]) ? TipsanityMerchantExtractor::RegisteredMerchantList::REGISTERED_MERCHANT[:linkshare][0][:rakuten] : URI(merchant_url).host)
  else
    false
  end
end