Sha256: 35b383c41af24b92cebfa8d93814a8543097a38c999f5c2f5c7085513dbfbeeb

Contents?: true

Size: 1.51 KB

Versions: 3

Compression:

Stored size: 1.51 KB

Contents

module TipsanityMerchantExtractor
  module LinkShare
		def call_to_linkshare(merchant_url, token, mid)
      product_name = extract_linkshare(merchant_url)
      linkshare_base_url = "http://productsearch.linksynergy.com/productsearch?"
      query_hash = {token: token, keyword: product_name, mid: mid, exact: product_name.split(" ").pop(2).join(" ")}
      query = URI.encode_www_form query_hash
      request_url = [linkshare_base_url, query].join
      response_xml = Nokogiri::XML open(URI.escape(request_url))
      unless response_xml.xpath("//Errors").empty?
        product = nil
      else
        product = response_xml.xpath("//result")
      end
      yield product
    end

    def extract_linkshare(merchant_url)
      capitalized_product_name = nil
      if is_merchant_linkshare_rakuten?(merchant_url){}
        path = URI(URI.unescape merchant_url).path
        element_array = path.split("/")
        product_name = element_array[element_array.index("p")+1] if element_array.include?("p")
        product_name = element_array[element_array.index("prod")+1] if element_array.include?("prod")
        capitalized_product_name = product_name.gsub(/\d/,'').split('-').delete_if{|x| x==""}.collect{|x| x.capitalize}[0..6].join(" ")
        return capitalized_product_name
      end
    end
    def provide_buy_url(token, mid, merchant_url)
      buy_url = "http://getdeeplink.linksynergy.com/createcustomlink.shtml?token=#{token}&mid=#{mid}&murl=#{merchant_url}"
      Nokogiri::HTML(open(buy_url)).search("p").text
    end
	end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tipsanity_merchant_extractor-0.0.9 lib/tipsanity_merchant_extractor/linkshare.rb
tipsanity_merchant_extractor-0.0.8 lib/tipsanity_merchant_extractor/linkshare.rb
tipsanity_merchant_extractor-0.0.7 lib/tipsanity_merchant_extractor/linkshare.rb