tipsanity_merchant_extractor 0.0.4.alpha → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
- ## v0.0.4.alpha
1
+ ## v0.0.5
2
2
 
3
3
  * initial release with amazon api derivatives.
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in tipsanity_merchant_extractor.gemspec
4
- gemspec
4
+ gemspec
@@ -1,115 +1,30 @@
1
1
  require "tipsanity_merchant_extractor/version"
2
- require 'uri'
3
-
4
- # require 'asin_configuration'
2
+ require 'open-uri'
3
+ require 'nori'
4
+ require 'nokogiri'
5
5
 
6
6
  module TipsanityMerchantExtractor
7
- module UrlFormatter
8
- REGISTERED_MERCHANT = {amazon: "www.amazon.com", cjunction: "www.commissionjunction.com", link_share: "www.link_share.com"}#%w{www.amazon.com www.commissionjunction.com www.link_share.com}
9
- class << self
10
- def format_url url
11
- URI.unescape url
12
- if url.to_s !~ url_regexp && "http://#{url}" =~ url_regexp
13
- "http://#{url.gsub(/\A[[:punct:]]*/,'')}"
14
- else
15
- url
16
- end
17
- end
7
+ autoload :UrlFormatter, 'tipsanity_merchant_extractor/url_formatter'
8
+ autoload :AttributeExtractor, 'tipsanity_merchant_extractor/attribute_extractor'
9
+ autoload :Amazon, 'tipsanity_merchant_extractor/amazon'
10
+ autoload :RegisteredMerchantList, 'tipsanity_merchant_extractor/registered_merchant_list'
11
+ autoload :LinkShare, 'tipsanity_merchant_extractor/linkshare'
12
+ autoload :Cj, 'tipsanity_merchant_extractor/cj'
13
+ autoload :Rakuten, 'tipsanity_merchant_extractor/rakuten'
14
+ autoload :BestBuy, 'tipsanity_merchant_extractor/best_buy'
15
+ autoload :OneEightThousandLighting,'tipsanity_merchant_extractor/1800lighting'
18
16
 
19
- def url_regexp
20
- /http:|https:/ #[http:|https:] means that any of the charactor inside [] is matching.
21
- end
17
+ end
22
18
 
23
- def valid_url url
24
- if url =~ url_regexp
25
- true
26
- else
27
- false
28
- end
29
- end
19
+ class Array
20
+ def extract_options!
21
+ if last.is_a?(::Hash)# && last.extractable_options?
22
+ pop
23
+ else
24
+ {}
30
25
  end
31
26
  end
32
-
33
- class AttributeExtractor
34
- include UrlFormatter
35
- attr_accessor :merchant_url,
36
- :host_provider,
37
- :product_name,
38
- :description,
39
- :final_price,
40
- :list_price,
41
- :expiry_date,
42
- :currency_code,
43
- :image_url,
44
- :details_url,
45
- :is_dp
46
-
47
- def initialize merchant_url
48
- @merchant_url = UrlFormatter.format_url merchant_url
49
- @host_provider = URI(@merchant_url).host
50
-
51
- case who_is_merchant
52
- when REGISTERED_MERCHANT[:amazon]
53
- client = ASIN::Client.instance
54
- product = client.lookup filtered_asin_from_amazon_path
55
- @product_name = product.first.title
56
- filtered_asin_from_amazon_path{|is_dp| is_dp == false} ? @description = product.first.review : @description = product.first.raw.EditorialReviews.EditorialReview.first.Content
57
- @list_price = product.first.amount.to_f/100 || product.first.raw.ItemAttributes.ListPrice.Amount.to_f/100
58
- @currency_code = product.first.raw.ItemAttributes.ListPrice.CurrencyCode
59
- @expiry_date = Date.today
60
- @image_url = product.first.image_url || product.first.raw.ImageSets.ImageSet.LargeImage.URL
61
- @details_url = product.first.details_url
62
-
63
- end
64
- end
65
-
66
- def who_is_merchant
67
- case @host_provider
68
- when is_merchant_amazon?
69
- REGISTERED_MERCHANT[:amazon]
70
- when "www.commissionjunction.com"
71
- "commissionjunction"
72
- else
73
- "this merchant is not registered with system"
74
- end
75
- end
76
-
77
- def is_merchant_amazon?
78
- if @host_provider == REGISTERED_MERCHANT[:amazon]
79
- block_given? ? true : @host_provider
80
- else
81
- false
82
- end
83
- end
84
-
85
- def merchant_amazon_path
86
- if is_merchant_amazon?{}
87
- path = URI(@merchant_url).path
88
- else
89
- "It is not amazon merchant"
90
- end
91
- end
92
-
93
- def filtered_asin_from_amazon_path
94
- split_path = merchant_amazon_path.split('/')
95
- if split_path.include? 'gp'
96
- if block_given?
97
- @is_dp = false
98
- yield @is_dp
99
- else
100
- asin = split_path[split_path.index('gp')+2]
101
- end
102
- elsif split_path.include? 'dp'
103
- if block_given?
104
- @is_dp = true
105
- yield @is_dp
106
- else
107
- asin = split_path[split_path.index('dp')+1]
108
- end
109
- else
110
- "path does not have asin"
111
- end
112
- end
27
+ def extractable_options?
28
+ instance_of?(Hash)
113
29
  end
114
-
115
- end
30
+ end
@@ -0,0 +1,28 @@
1
+ module TipsanityMerchantExtractor
2
+ module OneEightThousandLighting
3
+ def is_merchant_cj_one_eight_thousand_lighting?(merchant_url)
4
+ if URI(merchant_url).host == RegisteredMerchantList::REGISTERED_MERCHANT[:cjunction][:one_eight_thousand_lighting]
5
+ block_given? ? true : RegisteredMerchantList::REGISTERED_MERCHANT[:cjunction][:one_eight_thousand_lighting]
6
+ else
7
+ false
8
+ end
9
+ end
10
+
11
+ def extract_cj_one_eight_thousand_lighting(merchant_url)
12
+ if is_merchant_cj_one_eight_thousand_lighting?(merchant_url){}
13
+ path = URI(merchant_url).path
14
+ product_name = path.split("/")[path.split("/").index("site")+1] if path.split("/").include?("site")
15
+ query = URI(merchant_url).query
16
+ yield(product_name, query)
17
+ else
18
+ block_given? ? yield("It is not bestbuy merchant connected with commission junction.") : "It is not bestbuy merchant connected with commission junction."
19
+ end
20
+ end
21
+
22
+ def find_product_one_eight_thousand_lighting merchant_url, cj
23
+ product_name = extract_cj_one_eight_thousand_lighting(merchant_url){|product_name| product_name}
24
+ skuId = extract_cj_one_eight_thousand_lighting(merchant_url){|product_name, query| CGI.parse(query)["skuId"].first}
25
+ cj.product_search("keywords" => product_name, "advertiser-ids" => "notjoined", "advertiser-sku" => skuId).collect{|product| product}.first
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,82 @@
1
+ # require 'asin_configuration'
2
+
3
+ module TipsanityMerchantExtractor
4
+ module Amazon
5
+ def self.extended(base)
6
+ if base == AttributeExtractor
7
+ base.send :include, FindAmazon
8
+ end
9
+ end
10
+
11
+ def is_merchant_amazon?(merchant_url)
12
+ if URI(merchant_url).host == TipsanityMerchantExtractor::RegisteredMerchantList::REGISTERED_MERCHANT[:amazon]
13
+ block_given? ? true : TipsanityMerchantExtractor::RegisteredMerchantList::REGISTERED_MERCHANT[:amazon]
14
+ else
15
+ false
16
+ end
17
+ end
18
+
19
+ def merchant_amazon_path(merchant_url)
20
+ if self.is_merchant_amazon?(merchant_url){}
21
+ path = URI(merchant_url).path
22
+ else
23
+ "It is not amazon merchant"
24
+ end
25
+ end
26
+
27
+ def filtered_asin_from_amazon_path(merchant_url)
28
+ split_path = self.merchant_amazon_path(merchant_url).split('/')
29
+ if split_path.include? 'gp'
30
+ if block_given?
31
+ @is_dp = false
32
+ yield @is_dp
33
+ else
34
+ asin = split_path[split_path.index('gp')+2]
35
+ end
36
+ elsif split_path.include? 'dp'
37
+ if block_given?
38
+ @is_dp = true
39
+ yield @is_dp
40
+ else
41
+ asin = split_path[split_path.index('dp')+1]
42
+ end
43
+ else
44
+ "path does not have asin"
45
+ end
46
+ end
47
+
48
+ module FindAmazon
49
+ include Amazon
50
+ def find_product_amazon(merchannt_url)
51
+ client = ASIN::Client.instance
52
+ product = client.lookup filtered_asin_from_amazon_path(merchant_url)
53
+ unless product.empty?
54
+
55
+ @response_object = product
56
+ @product_name = product.first.title
57
+ # filtered_asin_from_amazon_path{|is_dp| is_dp == false} ? @description = product.first.raw.EditorialReviews.EditorialReview.Content : @description = product.first.raw.EditorialReviews.EditorialReview.first.Content
58
+ @description = product.first.raw.keys.include?("EditorialReviews") ? (product.first.raw.EditorialReviews.EditorialReview.kind_of?(Array) ? product.first.raw.EditorialReviews.EditorialReview.first.Content : product.first.raw.EditorialReviews.EditorialReview.Content) : nil
59
+ @list_price = product.first.amount.to_f/100 || product.first.raw.ItemAttributes.ListPrice.Amount.to_f/100
60
+ @currency_code = product.first.raw.ItemAttributes.ListPrice.CurrencyCode
61
+ @expiry_date = Date.today
62
+ @image_url = product.first.image_url || product.first.raw.ImageSets.ImageSet.LargeImage.URL
63
+ @details_url = product.first.details_url
64
+ @final_price = product.first.raw.include?("OfferSummary") ? product.first.raw.OfferSummary.LowestNewPrice ? product.first.raw.OfferSummary.LowestNewPrice.Amount.to_f/100 : "0.00".to_f : "0.00".to_f
65
+ @categories = product.first.raw.ItemAttributes.Binding
66
+ @product_token = product.first.asin
67
+ else
68
+ @response_object = nil
69
+ @product_name = nil
70
+ @description = nil
71
+ @list_price = nil
72
+ @currency_code = nil
73
+ @expiry_date = nil
74
+ @image_url = nil
75
+ @details_url = nil
76
+ @final_price = nil
77
+ @categories = nil
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,72 @@
1
+ module TipsanityMerchantExtractor
2
+ class AttributeExtractor
3
+ extend UrlFormatter
4
+ [Amazon, LinkShare, Rakuten, BestBuy, Cj].each do |merchant|
5
+ extend merchant
6
+ end
7
+
8
+ attr_accessor :merchant_url,
9
+ :host_provider,
10
+ :product_name,
11
+ :description,
12
+ :final_price,
13
+ :list_price,
14
+ :expiry_date,
15
+ :currency_code,
16
+ :image_url,
17
+ :details_url,
18
+ :is_dp,
19
+ :categories,
20
+ :response_object,
21
+ :product_token,
22
+ :options
23
+ :errors
24
+
25
+ class << self
26
+ def who_is_merchant(merchant_url)
27
+ case URI(merchant_url).host
28
+ when is_merchant_amazon?(merchant_url)
29
+ RegisteredMerchantList::REGISTERED_MERCHANT[:amazon]
30
+ when is_merchant_cj_bestbuy?(merchant_url)
31
+ RegisteredMerchantList::REGISTERED_MERCHANT[:cjunction][:bestbuy]
32
+ when is_merchant_linkshare_rakuten?(merchant_url)
33
+ RegisteredMerchantList::REGISTERED_MERCHANT[:linkshare][0][:rakuten]
34
+ else
35
+ "this merchant is not registered merchant with our system. Please recommend us to affliate with us."
36
+ # URI(merchant_url).host
37
+ end
38
+ end
39
+ end
40
+ # end of self methods
41
+
42
+ def initialize merchant_url, *args
43
+ @options = args.extract_options!
44
+ @url = merchant_url
45
+ @merchant_url = self.class.format_url @url
46
+ @host_provider = URI(@merchant_url).host
47
+ @errors = []
48
+ case self.class.who_is_merchant(@merchant_url)
49
+ when RegisteredMerchantList::REGISTERED_MERCHANT[:amazon]
50
+ find_product_amazon @merchant_url
51
+
52
+ when RegisteredMerchantList::REGISTERED_MERCHANT[:cjunction][:bestbuy]
53
+ find_product_cj @merchant_url
54
+
55
+ when RegisteredMerchantList::REGISTERED_MERCHANT[:linkshare][0][:rakuten]
56
+ find_product_rakuten @merchant_url, @options[:linkshare][:token], RegisteredMerchantList::REGISTERED_MERCHANT[:linkshare][0][:mid]
57
+
58
+ else
59
+ @product_name = nil
60
+ @description = nil
61
+ @list_price = nil
62
+ @currency_code = nil
63
+ @expiry_date = nil
64
+ @image_url = nil
65
+ @details_url = nil
66
+ @final_price = nil
67
+ @categories = nil
68
+ @errors << "Unable to retrive from api"
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,28 @@
1
+ module TipsanityMerchantExtractor
2
+ module BestBuy
3
+ def is_merchant_cj_bestbuy?(merchant_url)
4
+ if URI(merchant_url).host == RegisteredMerchantList::REGISTERED_MERCHANT[:cjunction][:bestbuy]
5
+ block_given? ? true : RegisteredMerchantList::REGISTERED_MERCHANT[:cjunction][:bestbuy]
6
+ else
7
+ false
8
+ end
9
+ end
10
+
11
+ def extract_cj_bestbuy(merchant_url)
12
+ if is_merchant_cj_bestbuy?(merchant_url){}
13
+ path = URI(merchant_url).path
14
+ product_name = path.split("/")[path.split("/").index("site")+1] if path.split("/").include?("site")
15
+ query = URI(merchant_url).query
16
+ yield(product_name, query)
17
+ else
18
+ block_given? ? yield("It is not bestbuy merchant connected with commission junction.") : "It is not bestbuy merchant connected with commission junction."
19
+ end
20
+ end
21
+
22
+ def find_product_best_buy merchant_url, cj, options = {}
23
+ product_name = extract_cj_bestbuy(merchant_url){|product_name| product_name}
24
+ skuId = extract_cj_bestbuy(merchant_url){|product_name, query| CGI.parse(query)["skuId"].first}
25
+ cj.product_search("keywords" => product_name, "advertiser-ids" => options["advertiser-ids"], "advertiser-sku" => skuId).collect{|product| product}.first
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,48 @@
1
+ require 'commission_junction'
2
+
3
+ module TipsanityMerchantExtractor
4
+ module Cj
5
+ include BestBuy
6
+ include OneEightThousandLighting
7
+ def self.extended(base)
8
+ if base == AttributeExtractor
9
+ base.send :include, FindCj
10
+ end
11
+ end
12
+
13
+ def call_to_cj(merchant_url, developer_key, website_id)
14
+
15
+ cj = CommissionJunction.new(developer_key, website_id)
16
+ case AttributeExtractor.who_is_merchant merchant_url
17
+ when RegisteredMerchantList::REGISTERED_MERCHANT[:cjunction][:bestbuy]
18
+ yield find_product_best_buy(merchant_url, cj, {"advertiser-ids" => "notjoined"})
19
+
20
+ when RegisteredMerchantList::REGISTERED_MERCHANT[:cjunction][:one_eight_thousand_lighting]
21
+ yield find_product_one_eight_thousand_lighting(merchant_url, cj, {"advertiser-ids" => "notjoined"})
22
+
23
+ end
24
+ end
25
+
26
+ module FindCj
27
+ include Cj
28
+ def find_product_cj merchant_url
29
+ call_to_cj(merchant_url, @options[:cj][:developer_key], @options[:cj][:website_id]) do |product|
30
+ if product
31
+
32
+ @product_name = product.name
33
+ @description = product.description
34
+ @list_price = product.price
35
+ @currency_code = product.currency
36
+ @image_url = product.image_url
37
+ @details_url = product.buy_url
38
+ @categories = product.advertiser_category
39
+ @response_object = product
40
+ @product_token = self.class.extract_cj_bestbuy(@merchant_url){|product_name, query| CGI.parse(query)["skuId"].first}
41
+ else
42
+ @product_name = @description = @list_price = @currency_code = @image_url = @details_url = @categories = @response_object = nil
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,30 @@
1
+ module TipsanityMerchantExtractor
2
+ module LinkShare
3
+ def call_to_linkshare(merchant_url, token, mid)
4
+ product_name = extract_linkshare(merchant_url)
5
+ linkshare_base_url = "http://productsearch.linksynergy.com/productsearch?"
6
+ query_hash = {token: token, keyword: product_name, mid: mid, exact: product_name.split(" ").pop(2).join(" ")}
7
+ query = URI.encode_www_form query_hash
8
+ request_url = [linkshare_base_url, query].join
9
+ response_xml = Nokogiri::XML open(URI.escape(request_url))
10
+ unless response_xml.xpath("//Errors").empty?
11
+ product = nil
12
+ else
13
+ product = response_xml.xpath("//result")
14
+ end
15
+ yield product
16
+ end
17
+
18
+ def extract_linkshare(merchant_url)
19
+ capitalized_product_name = nil
20
+ if is_merchant_linkshare_rakuten?(merchant_url){}
21
+ path = URI(URI.unescape merchant_url).path
22
+ element_array = path.split("/")
23
+ product_name = element_array[element_array.index("p")+1] if element_array.include?("p")
24
+ product_name = element_array[element_array.index("prod")+1] if element_array.include?("prod")
25
+ capitalized_product_name = product_name.gsub(/\d/,'').split('-').delete_if{|x| x==""}.collect{|x| x.capitalize}[0..6].join(" ")
26
+ return capitalized_product_name
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,54 @@
1
+ module TipsanityMerchantExtractor
2
+ # include LinkShare
3
+
4
+ module Rakuten
5
+ def self.extended(base)
6
+ if base == AttributeExtractor
7
+ base.send :include, Rakuten
8
+ end
9
+ end
10
+
11
+ def is_merchant_linkshare_rakuten?(merchant_url)
12
+ is_rakuten = ((URI(merchant_url).host == TipsanityMerchantExtractor::RegisteredMerchantList::REGISTERED_MERCHANT[:linkshare][0][:rakuten]) or !(URI(merchant_url).host.match(/rakuten/).nil?))
13
+ if is_rakuten
14
+ 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)
15
+ else
16
+ false
17
+ end
18
+ end
19
+
20
+ def extract_linkshare_rakuten(merchant_url, token, mid)
21
+ if is_merchant_linkshare_rakuten?(merchant_url){}
22
+ path_array = URI(merchant_url).path.split('/')
23
+ skuid_stringed = path_array.last.gsub(/\D/, "")
24
+ skuid = skuid_stringed.to_i==0 ? nil : skuid_stringed.to_i
25
+ if skuid
26
+ begin
27
+ scraped_screen = Nokogiri::HTML(open(merchant_url))
28
+ @product_name = scraped_screen.search('#AuthorArtistTitle_productTitle').first.text
29
+ @description = scraped_screen.search('#divDescription').first.text
30
+ @list_price = scraped_screen.search('#spanMainListPrice').first.text.gsub(/$/, "").to_i
31
+ @final_price = scraped_screen.search('#spanMainTotalPrice').first.text.gsub(/$/, "").to_i
32
+ @image_url = scraped_screen.search('#ImageVideo_ImageRepeater_ctl00_Image').first.attributes["src"].value
33
+ buy_url = "http://getdeeplink.linksynergy.com/createcustomlink.shtml?token=#{token}&mid=#{mid}&murl=#{merchant_url}"
34
+ @details_url = Nokogiri::HTML(open(buy_url)).search("p").text# it needs token to retrive buy url
35
+ @categories = scraped_screen.search('#anchorSimilarProds').first.text
36
+ @response_object = scraped_screen
37
+ @product_token = skuid
38
+ @errors = []
39
+ rescue
40
+ @errors << "Some errors from api information"
41
+ end
42
+ else
43
+ @errors << "Not valid Uri. Please make sure, Uri contain 'prod' and skuid."
44
+ end
45
+ else
46
+ block_given? ? yield("It is not bestbuy merchant connected with commission junction.") : "It is not bestbuy merchant connected with commission junction."
47
+ end
48
+ end
49
+
50
+ def find_product_rakuten merchant_url, token, mid
51
+ extract_linkshare_rakuten merchant_url, token, mid
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,21 @@
1
+ module TipsanityMerchantExtractor
2
+ class RegisteredMerchantList
3
+ REGISTERED_MERCHANT = {
4
+ amazon: "www.amazon.com",
5
+ cjunction: {
6
+ bestbuy: 'www.bestbuy.com',
7
+ one_eight_thousand_lighting: 'www.1800lighting.com'
8
+ },
9
+ linkshare: [
10
+ {
11
+ rakuten: "www.rakuten.com",
12
+ mid: 36342
13
+ },
14
+ {
15
+ tigerdirect: "www.tigerdirect.com",
16
+ mid: 14028
17
+ }
18
+ ]
19
+ }#%w{www.amazon.com www.commissionjunction.com www.link_share.com}
20
+ end
21
+ end
@@ -0,0 +1,25 @@
1
+ require 'uri'
2
+ module TipsanityMerchantExtractor
3
+ module UrlFormatter
4
+ def format_url url
5
+ URI.unescape url
6
+ if url.to_s !~ url_regexp && "http://#{url}" =~ url_regexp
7
+ "http://#{url.gsub(/\A[[:punct:]]*/,'')}"
8
+ else
9
+ url
10
+ end
11
+ end
12
+
13
+ def url_regexp
14
+ /http:|https:/ #[http:|https:] means that any of the charactor inside [] is matching.
15
+ end
16
+
17
+ def valid_url url
18
+ if url =~ url_regexp
19
+ true
20
+ else
21
+ false
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,3 +1,3 @@
1
1
  module TipsanityMerchantExtractor
2
- VERSION = "0.0.4.alpha"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -1,19 +1,22 @@
1
1
  require "spec_helper"
2
2
 
3
- describe TipsanityMerchantExtractor::UrlFormatter do
3
+ describe TipsanityMerchantExtractor::AttributeExtractor do
4
4
  describe "url package" do
5
5
  it "add http:// if it is not privided" do
6
- TipsanityMerchantExtractor::UrlFormatter.format_url("example.com").should eq("http://example.com")
6
+ TipsanityMerchantExtractor::AttributeExtractor.format_url("example.com").should eq("http://example.com")
7
7
  end
8
8
 
9
9
  it "display the message valid url" do
10
- TipsanityMerchantExtractor::UrlFormatter.valid_url("https://example.com").should be_true
10
+ TipsanityMerchantExtractor::AttributeExtractor.valid_url("https://example.com").should be_true
11
11
  end
12
12
 
13
13
  it "says who is the marchant for amazon" do
14
- @tipsanity_instance = TipsanityMerchantExtractor::AttributeExtractor.new "http://www.amazon.com/gp/product/B00CMQTVQO/ref=s9_pop_gw_g63_ir05?pf_rd_m=ATVPDKIKX0DER&pf_rd_s=center-2&pf_rd_r=1B2CFTWGZGRQE19V8J1V&pf_rd_t=101&pf_rd_p=1263340922&pf_rd_i=507846"
15
- @tipsanity_instance.who_is_merchant.should eq("www.amazon.com")
14
+ TipsanityMerchantExtractor::AttributeExtractor.who_is_merchant("http://www.amazon.com/gp/product/B00CMQTVQO/ref=s9_pop_gw_g63_ir05?pf_rd_m=ATVPDKIKX0DER&pf_rd_s=center-2&pf_rd_r=1B2CFTWGZGRQE19V8J1V&pf_rd_t=101&pf_rd_p=1263340922&pf_rd_i=507846").should eq("www.amazon.com")
16
15
  end
16
+
17
+ # it "says available merchant" do
18
+ # TipsanityMerchantExtractor::AttributeExtractor::REGISTERED_MERCHANT.should eq('{:amazon=>"www.amazon.com", :cjunction=>{:bestbuy=>"www.bestbuy.com"}, :link_share=>"www.linkshare.com"}')
19
+ # end
17
20
  end
18
21
 
19
22
  describe "initialize attribute for url fro api" do
@@ -23,25 +26,23 @@ describe TipsanityMerchantExtractor::UrlFormatter do
23
26
  end
24
27
  end
25
28
 
26
- describe "amazon.com merchant initiator" do
29
+ describe "merchant initiator" do
27
30
  it "is amazon.com" do
28
- @tipsanity_instance = TipsanityMerchantExtractor::AttributeExtractor.new "http://www.amazon.com/gp/product/B00CMQTVQO/ref=s9_pop_gw_g63_ir05?pf_rd_m=ATVPDKIKX0DER&pf_rd_s=center-2&pf_rd_r=1B2CFTWGZGRQE19V8J1V&pf_rd_t=101&pf_rd_p=1263340922&pf_rd_i=507846"
29
- @tipsanity_instance.is_merchant_amazon?{}.should == true
31
+ # @tipsanity_instance = TipsanityMerchantExtractor::AttributeExtractor.new "http://www.amazon.com/gp/product/B00CMQTVQO/ref=s9_pop_gw_g63_ir05?pf_rd_m=ATVPDKIKX0DER&pf_rd_s=center-2&pf_rd_r=1B2CFTWGZGRQE19V8J1V&pf_rd_t=101&pf_rd_p=1263340922&pf_rd_i=507846"
32
+ TipsanityMerchantExtractor::AttributeExtractor.is_merchant_amazon?("http://www.amazon.com/gp/product/B00CMQTVQO/ref=s9_pop_gw_g63_ir05?pf_rd_m=ATVPDKIKX0DER&pf_rd_s=center-2&pf_rd_r=1B2CFTWGZGRQE19V8J1V&pf_rd_t=101&pf_rd_p=1263340922&pf_rd_i=507846"){}.should == true
30
33
  end
31
34
 
32
35
  it "is not amazon.com" do
33
- @tipsanity_instance = TipsanityMerchantExtractor::AttributeExtractor.new "http://www.yahoo.com/gp/product/B00CMQTVQO/ref=s9_pop_gw_g63_ir05?pf_rd_m=ATVPDKIKX0DER&pf_rd_s=center-2&pf_rd_r=1B2CFTWGZGRQE19V8J1V&pf_rd_t=101&pf_rd_p=1263340922&pf_rd_i=507846"
34
- @tipsanity_instance.is_merchant_amazon?{}.should == false
36
+ # @tipsanity_instance = TipsanityMerchantExtractor::AttributeExtractor.new "http://www.yahoo.com/gp/product/B00CMQTVQO/ref=s9_pop_gw_g63_ir05?pf_rd_m=ATVPDKIKX0DER&pf_rd_s=center-2&pf_rd_r=1B2CFTWGZGRQE19V8J1V&pf_rd_t=101&pf_rd_p=1263340922&pf_rd_i=507846"
37
+ TipsanityMerchantExtractor::AttributeExtractor.is_merchant_amazon?("http://www.yahoo.com/gp/product/B00CMQTVQO/ref=s9_pop_gw_g63_ir05?pf_rd_m=ATVPDKIKX0DER&pf_rd_s=center-2&pf_rd_r=1B2CFTWGZGRQE19V8J1V&pf_rd_t=101&pf_rd_p=1263340922&pf_rd_i=507846"){}.should == false
35
38
  end
36
39
 
37
40
  it "is path of amazon.com" do
38
- @tipsanity_instance = TipsanityMerchantExtractor::AttributeExtractor.new "http://www.amazon.com/gp/product/B00CMQTVQO/ref=s9_pop_gw_g63_ir05?pf_rd_m=ATVPDKIKX0DER&pf_rd_s=center-2&pf_rd_r=1B2CFTWGZGRQE19V8J1V&pf_rd_t=101&pf_rd_p=1263340922&pf_rd_i=507846"
39
- @tipsanity_instance.merchant_amazon_path.should eq("/gp/product/B00CMQTVQO/ref=s9_pop_gw_g63_ir05")
41
+ TipsanityMerchantExtractor::AttributeExtractor.merchant_amazon_path("http://www.amazon.com/Zwipes-Microfiber-Cleaning-Cloths-36-Pack/dp/B000XECJES?SubscriptionId=AKIAIJUCUBHUHOAHW3TA&tag=tipsanity-20&linkCode=xm2&camp=2025&creative=165953&creativeASIN=B000XECJES").should eq("/Zwipes-Microfiber-Cleaning-Cloths-36-Pack/dp/B000XECJES")
40
42
  end
41
43
 
42
44
  it "filter asin from given url" do
43
- @tipsanity_instance = TipsanityMerchantExtractor::AttributeExtractor.new "http://www.amazon.com/gp/product/B00CMQTVQO/ref=s9_pop_gw_g63_ir05?pf_rd_m=ATVPDKIKX0DER&pf_rd_s=center-2&pf_rd_r=1B2CFTWGZGRQE19V8J1V&pf_rd_t=101&pf_rd_p=1263340922&pf_rd_i=507846"
44
- @tipsanity_instance.filtered_asin_from_amazon_path.should eq("B00CMQTVQO")
45
+ TipsanityMerchantExtractor::AttributeExtractor.filtered_asin_from_amazon_path("http://www.amazon.com/Zwipes-Microfiber-Cleaning-Cloths-36-Pack/dp/B000XECJES?SubscriptionId=AKIAIJUCUBHUHOAHW3TA&tag=tipsanity-20&linkCode=xm2&camp=2025&creative=165953&creativeASIN=B000XECJES").should eq("B000XECJES")
45
46
  end
46
47
 
47
48
  it "gets the product name from given url of amazon.com on the code gp" do
@@ -53,6 +54,50 @@ describe TipsanityMerchantExtractor::UrlFormatter do
53
54
  @tipsanity_instance = TipsanityMerchantExtractor::AttributeExtractor.new "http://www.amazon.com/Inferno-Novel-Robert-Langdon-ebook/dp/B00AXIZ4TQ/ref=pd_rhf_gw_s_ts_1_N8P4?ie=UTF8&refRID=0S1YP6CNWXFVPB12N8P4"
54
55
  @tipsanity_instance.product_name.should eq("Inferno: A Novel (Robert Langdon)")
55
56
  end
57
+
58
+ it "gets the product final price from given url of amazon.com on the code dp" do
59
+ @tipsanity_instance = TipsanityMerchantExtractor::AttributeExtractor.new "http://www.amazon.com/Inferno-Novel-Robert-Langdon-ebook/dp/B00AXIZ4TQ/ref=pd_rhf_gw_s_ts_1_N8P4?ie=UTF8&refRID=0S1YP6CNWXFVPB12N8P4"
60
+ @tipsanity_instance.final_price.should eq(0.0)
61
+ end
56
62
 
63
+ it "extract the query from best buy" do
64
+ # @tipsanity_instance = TipsanityMerchantExtractor::AttributeExtractor.new "http://www.bestbuy.com/site/Lens+and+LCD+Screen+Cleaning+Cloth/6732119.p?id=1087340386022&skuId=6732119&st=6732119&cp=1&lp=1"
65
+ TipsanityMerchantExtractor::AttributeExtractor.extract_cj_bestbuy("http://www.bestbuy.com/site/Lens+and+LCD+Screen+Cleaning+Cloth/6732119.p?id=1087340386022&skuId=6732119&st=6732119&cp=1&lp=1"){|a, query| query}.should eq("id=1087340386022&skuId=6732119&st=6732119&cp=1&lp=1")
66
+ end
67
+
68
+ it "extract the product name from best buy" do
69
+ # @tipsanity_instance = TipsanityMerchantExtractor::AttributeExtractor.new "http://www.bestbuy.com/site/Lens+and+LCD+Screen+Cleaning+Cloth/6732119.p?id=1087340386022&skuId=6732119&st=6732119&cp=1&lp=1"
70
+ TipsanityMerchantExtractor::AttributeExtractor.extract_cj_bestbuy("http://www.bestbuy.com/site/Lens+and+LCD+Screen+Cleaning+Cloth/6732119.p?id=1087340386022&skuId=6732119&st=6732119&cp=1&lp=1"){|product_name, query| product_name.gsub("+", " ")}.should eq("Lens and LCD Screen Cleaning Cloth")
71
+ end
72
+
73
+ it "extract sku from query of bestbuy.com" do
74
+ # @tipsanity_instance = TipsanityMerchantExtractor::AttributeExtractor.new "http://www.bestbuy.com/site/Lens+and+LCD+Screen+Cleaning+Cloth/6732119.p?id=1087340386022&skuId=6732119&st=6732119&cp=1&lp=1"
75
+ TipsanityMerchantExtractor::AttributeExtractor.extract_cj_bestbuy("http://www.bestbuy.com/site/Lens+and+LCD+Screen+Cleaning+Cloth/6732119.p?id=1087340386022&skuId=6732119&st=6732119&cp=1&lp=1"){|product_name, query| CGI.parse(query)["skuId"].first}.should eq("6732119")
76
+ end
77
+
78
+ # it "get the product name from bestbuy" do
79
+ # @tipsanity_instance = TipsanityMerchantExtractor::AttributeExtractor.new "http://www.bestbuy.com/site/Lens+and+LCD+Screen+Cleaning+Cloth/6732119.p?id=1087340386022&skuId=6732119&st=6732119&cp=1&lp=1", cj: {developer_key:"008dc8f793ca7bd35171100e2ea7376f514b9345bb6844e689d908bedfadada0c6b8fed3b766913fa22ffdd97553498816471aff50c82cc847dae723ce535dbbe7/008928dbd03df651b41c8322a5212070709d82c7d78703f85d6bf698e7bb9516cd13a1a429cb8e35989291e7a7bbc600db8913a7e4687257f805186af6dd6627b9", website_id: "7191286"}
80
+ # @tipsanity_instance.product_name.should eql("DigiPower - Lens and LCD Screen Cleaning Cloth")
81
+ # end
82
+
83
+ it "extract the product name from rakuten url" do
84
+ TipsanityMerchantExtractor::AttributeExtractor.extract_linkshare("http://www.rakuten.com/prod/v7-pa19s-extreme-guard-iphone-5-case-iphone-white-polycarbonate/247297348.html?sellerid=0").should eql("V Pas Extreme Guard Iphone Case Iphone")
85
+ #http://mambate.shop.rakuten.com/p/7-agptek-android-4-2-quad-core-1024-600-hd-screen-with-1gb-ddr3-4gb/251837691.html is needed to analyse
86
+ # http://www.rakuten.com/prod/v7-vantage-ccv4-carrying-case-backpack-for-13-notebook-black-polyester/246418473.html?sellerid=0 is valid url for now.
87
+ end
88
+
89
+ # it "call linkshare for rakuten to get product name" do
90
+ # @tipsanity_instance = TipsanityMerchantExtractor::AttributeExtractor.new("http://mambate.shop.rakuten.com/p/7-agptek-android-4-2-quad-core-1024-600-hd-screen-with-1gb-ddr3-4gb/251837691.html", linkshare:{token: "23bf03f93e1cbccd9009ab0b9128f2e57a6a245af6c2be5ebcfe6b7285ad9a79"})
91
+ # @tipsanity_instance.product_name.should eql(" 7 AGPtek Android 4.2 Quad Core 1024*600 HD Screen with 1GB RAM HDMI 1080P Tablet + Audio Leather Case for Google Play eBook Reader 3D GAMES ")
92
+ # end
93
+
94
+ it "gives the rakuten url" do
95
+ @tipsanity_instance = TipsanityMerchantExtractor::AttributeExtractor.new("http://www.rakuten.com/prod/v7-pa19s-extreme-guard-iphone-5-case-iphone-white-polycarbonate/247297348.html?sellerid=0", linkshare:{token: "23bf03f93e1cbccd9009ab0b9128f2e57a6a245af6c2be5ebcfe6b7285ad9a79"})
96
+ @tipsanity_instance.details_url.should eql("http://affiliate.rakuten.com/fs-bin/click?id=B/IDdUgQ0Rg&subid=0&offerid=288682.1&type=10&tmpid=6932&RD_PARM1=http%3A%2F%2Fwww.rakuten.com%2Fprod%2Fv7-pa19s-extreme-guard-iphone-5-case-iphone-white-polycarbonate%2F247297348.html%3Fsellerid%3D0")
97
+ end
98
+ it "check whether it is rekutan or not." do
99
+ # TipsanityMerchantExtractor::AttributeExtractor.is_merchant_linkshare_rakuten?("http://mambate.shop.rakuten.com/p/7-agptek-android-4-2-quad-core-1024-600-hd-screen-with-1gb-ddr3-4gb/251837691.html").should eq("www.rakuten.com")
100
+ TipsanityMerchantExtractor::AttributeExtractor.who_is_merchant("http://mambate.shop.rakuten.com/p/7-agptek-android-4-2-quad-core-1024-600-hd-screen-with-1gb-ddr3-4gb/251837691.html").should eq("www.rakuten.com")
101
+ end
57
102
  end
58
103
  end
@@ -18,6 +18,11 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ["lib"]
19
19
 
20
20
  gem.add_dependency "asin"
21
+ gem.add_dependency "commission_junction"
22
+ gem.add_dependency "linkshare"
23
+ gem.add_dependency "nokogiri"
24
+ gem.add_dependency "nori"
25
+ gem.add_dependency "hashie"
21
26
 
22
27
  gem.add_dependency 'httpclient'
23
28
 
metadata CHANGED
@@ -1,19 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tipsanity_merchant_extractor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4.alpha
5
- prerelease: 6
4
+ version: 0.0.5
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Umesh Umesh
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-15 00:00:00.000000000 Z
12
+ date: 2013-10-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: asin
16
- requirement: &70152960 !ruby/object:Gem::Requirement
16
+ requirement: &74521950 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,65 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70152960
24
+ version_requirements: *74521950
25
+ - !ruby/object:Gem::Dependency
26
+ name: commission_junction
27
+ requirement: &74521580 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *74521580
36
+ - !ruby/object:Gem::Dependency
37
+ name: linkshare
38
+ requirement: &74521270 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *74521270
47
+ - !ruby/object:Gem::Dependency
48
+ name: nokogiri
49
+ requirement: &74520860 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *74520860
58
+ - !ruby/object:Gem::Dependency
59
+ name: nori
60
+ requirement: &74519480 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: *74519480
69
+ - !ruby/object:Gem::Dependency
70
+ name: hashie
71
+ requirement: &74518870 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: *74518870
25
80
  - !ruby/object:Gem::Dependency
26
81
  name: httpclient
27
- requirement: &70152610 !ruby/object:Gem::Requirement
82
+ requirement: &74518280 !ruby/object:Gem::Requirement
28
83
  none: false
29
84
  requirements:
30
85
  - - ! '>='
@@ -32,10 +87,10 @@ dependencies:
32
87
  version: '0'
33
88
  type: :runtime
34
89
  prerelease: false
35
- version_requirements: *70152610
90
+ version_requirements: *74518280
36
91
  - !ruby/object:Gem::Dependency
37
92
  name: rake
38
- requirement: &70152300 !ruby/object:Gem::Requirement
93
+ requirement: &74517720 !ruby/object:Gem::Requirement
39
94
  none: false
40
95
  requirements:
41
96
  - - ! '>='
@@ -43,10 +98,10 @@ dependencies:
43
98
  version: '0'
44
99
  type: :development
45
100
  prerelease: false
46
- version_requirements: *70152300
101
+ version_requirements: *74517720
47
102
  - !ruby/object:Gem::Dependency
48
103
  name: rspec
49
- requirement: &70151950 !ruby/object:Gem::Requirement
104
+ requirement: &74517100 !ruby/object:Gem::Requirement
50
105
  none: false
51
106
  requirements:
52
107
  - - ! '>='
@@ -54,10 +109,10 @@ dependencies:
54
109
  version: '0'
55
110
  type: :development
56
111
  prerelease: false
57
- version_requirements: *70151950
112
+ version_requirements: *74517100
58
113
  - !ruby/object:Gem::Dependency
59
114
  name: httpclient
60
- requirement: &70151580 !ruby/object:Gem::Requirement
115
+ requirement: &74516670 !ruby/object:Gem::Requirement
61
116
  none: false
62
117
  requirements:
63
118
  - - ! '>='
@@ -65,7 +120,7 @@ dependencies:
65
120
  version: '0'
66
121
  type: :development
67
122
  prerelease: false
68
- version_requirements: *70151580
123
+ version_requirements: *74516670
69
124
  description: Tipsanity website uses this gem to extract their marchant related information
70
125
  email:
71
126
  - umeshblader@gmail.com
@@ -82,6 +137,15 @@ files:
82
137
  - README.md
83
138
  - Rakefile
84
139
  - lib/tipsanity_merchant_extractor.rb
140
+ - lib/tipsanity_merchant_extractor/1800lighting.rb
141
+ - lib/tipsanity_merchant_extractor/amazon.rb
142
+ - lib/tipsanity_merchant_extractor/attribute_extractor.rb
143
+ - lib/tipsanity_merchant_extractor/best_buy.rb
144
+ - lib/tipsanity_merchant_extractor/cj.rb
145
+ - lib/tipsanity_merchant_extractor/linkshare.rb
146
+ - lib/tipsanity_merchant_extractor/rakuten.rb
147
+ - lib/tipsanity_merchant_extractor/registered_merchant_list.rb
148
+ - lib/tipsanity_merchant_extractor/url_formatter.rb
85
149
  - lib/tipsanity_merchant_extractor/version.rb
86
150
  - spec/spec_helper.rb
87
151
  - spec/tipsanity_url_formatter_spec.rb
@@ -101,9 +165,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
101
165
  required_rubygems_version: !ruby/object:Gem::Requirement
102
166
  none: false
103
167
  requirements:
104
- - - ! '>'
168
+ - - ! '>='
105
169
  - !ruby/object:Gem::Version
106
- version: 1.3.1
170
+ version: '0'
107
171
  requirements: []
108
172
  rubyforge_project:
109
173
  rubygems_version: 1.8.15