tipsanity_merchant_extractor 0.0.1.alpha
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +22 -0
- data/.rspec +1 -0
- data/.travis.yml +2 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +47 -0
- data/Rakefile +6 -0
- data/lib/asin_configuration.rb +10 -0
- data/lib/tipsanity_merchant_extractor/version.rb +3 -0
- data/lib/tipsanity_merchant_extractor.rb +91 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/tipsanity_url_formatter_spec.rb +58 -0
- data/tipsanity_merchant_extractor.gemspec +24 -0
- metadata +105 -0
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
/log/*
|
2
|
+
/vendor/bundle
|
3
|
+
capybara-*.html
|
4
|
+
.sass-cache
|
5
|
+
*.sassc
|
6
|
+
*.gem
|
7
|
+
*.rbc
|
8
|
+
.bundle
|
9
|
+
.config
|
10
|
+
.yardoc
|
11
|
+
Gemfile.lock
|
12
|
+
InstalledFiles
|
13
|
+
_yardoc
|
14
|
+
coverage
|
15
|
+
doc/
|
16
|
+
lib/bundler/man
|
17
|
+
pkg
|
18
|
+
rdoc
|
19
|
+
spec/reports
|
20
|
+
test/tmp
|
21
|
+
test/version_tmp
|
22
|
+
tmp
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Umesh Umesh
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# TipsanityMerchantExtractor [![Build Status](https://www.travis-ci.org/umeshblader3/TipsanityMerchantExtractor.png)](https://www.travis-ci.org/umeshblader3/TipsanityMerchantExtractor)
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'tipsanity_merchant_extractor'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install tipsanity_merchant_extractor
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Initiate a file with config/initializers/asin.rb
|
22
|
+
|
23
|
+
ASIN::Configuration.configure do |config|
|
24
|
+
|
25
|
+
config.secret = 'your secret'
|
26
|
+
|
27
|
+
config.key = 'your key'
|
28
|
+
|
29
|
+
config.associate_tag = 'your tag provided by amazon'
|
30
|
+
|
31
|
+
config.version = 'version provided by amazon' # every details you can simply get from amazon profile.
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
require 'httpi'
|
36
|
+
HTTPI.adapter = :httpclient
|
37
|
+
HTTPI.logger = Rails.logger
|
38
|
+
|
39
|
+
Then start server and have some basic test.
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
1. Fork it
|
44
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
45
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
46
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
47
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
require "tipsanity_merchant_extractor/version"
|
2
|
+
require 'uri'
|
3
|
+
# $LOAD_PATH << './lib'
|
4
|
+
|
5
|
+
# require 'asin_configuration'
|
6
|
+
|
7
|
+
module TipsanityMerchantExtractor
|
8
|
+
module UrlFormatter
|
9
|
+
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}
|
10
|
+
class << self
|
11
|
+
def format_url url
|
12
|
+
URI.unescape url
|
13
|
+
if url.to_s !~ url_regexp && "http://#{url}" =~ url_regexp
|
14
|
+
"http://#{url.gsub(/\A[[:punct:]]*/,'')}"
|
15
|
+
else
|
16
|
+
url
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def url_regexp
|
21
|
+
/http:|https:/ #[http:|https:] means that any of the charactor inside [] is matching.
|
22
|
+
end
|
23
|
+
|
24
|
+
def valid_url url
|
25
|
+
if url =~ url_regexp
|
26
|
+
true
|
27
|
+
else
|
28
|
+
false
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class AttributeExtractor
|
35
|
+
include UrlFormatter
|
36
|
+
attr_accessor :merchant_url, :host_provider, :product_name
|
37
|
+
|
38
|
+
def initialize merchant_url
|
39
|
+
@merchant_url = UrlFormatter.format_url merchant_url
|
40
|
+
@host_provider = URI(@merchant_url).host
|
41
|
+
end
|
42
|
+
|
43
|
+
def who_is_merchant
|
44
|
+
case @host_provider
|
45
|
+
when is_merchant_amazon?
|
46
|
+
REGISTERED_MERCHANT[:amazon]
|
47
|
+
when "www.commissionjunction.com"
|
48
|
+
"commissionjunction"
|
49
|
+
else
|
50
|
+
"this merchant is not registered with system"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def is_merchant_amazon?
|
55
|
+
if @host_provider == REGISTERED_MERCHANT[:amazon]
|
56
|
+
block_given? ? true : @host_provider
|
57
|
+
else
|
58
|
+
false
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def merchant_amazon_path
|
63
|
+
if is_merchant_amazon?{}
|
64
|
+
path = URI(@merchant_url).path
|
65
|
+
else
|
66
|
+
"It is not amazon merchant"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def product_name
|
71
|
+
case who_is_merchant
|
72
|
+
when REGISTERED_MERCHANT[:amazon]
|
73
|
+
client = ASIN::Client.instance
|
74
|
+
product = client.lookup filtered_asin_from_amazon_path
|
75
|
+
product.first.title
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def filtered_asin_from_amazon_path
|
80
|
+
split_path = merchant_amazon_path.split('/')
|
81
|
+
if split_path.include? 'gp'
|
82
|
+
asin = split_path[split_path.index('gp')+2]
|
83
|
+
elsif split_path.include? 'dp'
|
84
|
+
asin = split_path[split_path.index('dp')+1]
|
85
|
+
else
|
86
|
+
"path does not have asin"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "tipsanity_merchant_extractor"
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe TipsanityMerchantExtractor::UrlFormatter do
|
4
|
+
describe "url package" do
|
5
|
+
it "add http:// if it is not privided" do
|
6
|
+
TipsanityMerchantExtractor::UrlFormatter.format_url("example.com").should eq("http://example.com")
|
7
|
+
end
|
8
|
+
|
9
|
+
it "display the message valid url" do
|
10
|
+
TipsanityMerchantExtractor::UrlFormatter.valid_url("https://example.com").should be_true
|
11
|
+
end
|
12
|
+
|
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")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "initialize attribute for url fro api" do
|
20
|
+
it "check whether the url is called is valid of invalid" do
|
21
|
+
@tipsanity_instance = TipsanityMerchantExtractor::AttributeExtractor.new "http://yahoo.com"
|
22
|
+
@tipsanity_instance.host_provider.should eq("yahoo.com")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "amazon.com merchant initiator" do
|
27
|
+
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
|
30
|
+
end
|
31
|
+
|
32
|
+
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
|
35
|
+
end
|
36
|
+
|
37
|
+
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")
|
40
|
+
end
|
41
|
+
|
42
|
+
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
|
+
end
|
46
|
+
|
47
|
+
it "gets the product name from given url of amazon.com on the code gp" do
|
48
|
+
@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"
|
49
|
+
@tipsanity_instance.product_name.should eq("PlayStation 4 (PS4): Standard Edition")
|
50
|
+
end
|
51
|
+
|
52
|
+
it "gets the product name from given url of amazon.com on the code dp" do
|
53
|
+
@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
|
+
@tipsanity_instance.product_name.should eq("Inferno: A Novel (Robert Langdon)")
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'tipsanity_merchant_extractor/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "tipsanity_merchant_extractor"
|
8
|
+
gem.version = TipsanityMerchantExtractor::VERSION
|
9
|
+
gem.authors = ["Umesh Umesh"]
|
10
|
+
gem.email = ["umeshblader@gmail.com"]
|
11
|
+
gem.description = %q{Tipsanity website uses this gem to extract their marchant related information}
|
12
|
+
gem.summary = %q{registered marchant related information.}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency "rake"
|
21
|
+
gem.add_development_dependency "rspec"
|
22
|
+
gem.add_development_dependency "asin"
|
23
|
+
gem.add_development_dependency "httpclient"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tipsanity_merchant_extractor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.alpha
|
5
|
+
prerelease: 6
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Umesh Umesh
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-07-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: &83517210 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *83517210
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &83516450 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *83516450
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: asin
|
38
|
+
requirement: &83515810 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *83515810
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: httpclient
|
49
|
+
requirement: &83515280 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *83515280
|
58
|
+
description: Tipsanity website uses this gem to extract their marchant related information
|
59
|
+
email:
|
60
|
+
- umeshblader@gmail.com
|
61
|
+
executables: []
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files: []
|
64
|
+
files:
|
65
|
+
- .gitignore
|
66
|
+
- .rspec
|
67
|
+
- .travis.yml
|
68
|
+
- CHANGELOG.md
|
69
|
+
- Gemfile
|
70
|
+
- LICENSE.txt
|
71
|
+
- README.md
|
72
|
+
- Rakefile
|
73
|
+
- lib/asin_configuration.rb
|
74
|
+
- lib/tipsanity_merchant_extractor.rb
|
75
|
+
- lib/tipsanity_merchant_extractor/version.rb
|
76
|
+
- spec/spec_helper.rb
|
77
|
+
- spec/tipsanity_url_formatter_spec.rb
|
78
|
+
- tipsanity_merchant_extractor.gemspec
|
79
|
+
homepage: ''
|
80
|
+
licenses: []
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ! '>'
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.3.1
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 1.8.15
|
100
|
+
signing_key:
|
101
|
+
specification_version: 3
|
102
|
+
summary: registered marchant related information.
|
103
|
+
test_files:
|
104
|
+
- spec/spec_helper.rb
|
105
|
+
- spec/tipsanity_url_formatter_spec.rb
|