tipsanity_merchant_extractor 0.0.2 → 0.0.3.stable

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,3 @@
1
- ## v0.0.2
1
+ ## v0.0.3.stable
2
2
 
3
3
  * initial release with amazon api derivatives.
@@ -1,3 +1,3 @@
1
1
  module TipsanityMerchantExtractor
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3.stable"
3
3
  end
@@ -1,91 +1,105 @@
1
1
  require "tipsanity_merchant_extractor/version"
2
2
  require 'uri'
3
- # $LOAD_PATH << './lib'
3
+ # $LOAD_PATH << './lib'
4
4
 
5
5
  # require 'asin_configuration'
6
6
 
7
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
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
19
 
20
- def url_regexp
21
- /http:|https:/ #[http:|https:] means that any of the charactor inside [] is matching.
22
- end
20
+ def url_regexp
21
+ /http:|https:/ #[http:|https:] means that any of the charactor inside [] is matching.
22
+ end
23
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
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
33
 
34
- class AttributeExtractor
35
- include UrlFormatter
36
- attr_accessor :merchant_url, :host_provider, :product_name
34
+ class AttributeExtractor
35
+ include UrlFormatter
36
+ attr_accessor :merchant_url,
37
+ :host_provider,
38
+ :product_name,
39
+ :description,
40
+ :final_price,
41
+ :list_price,
42
+ :expiry_date,
43
+ :currency_code,
44
+ :image_url,
45
+ :details_url
37
46
 
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
47
+ def initialize merchant_url
48
+ @merchant_url = UrlFormatter.format_url merchant_url
49
+ @host_provider = URI(@merchant_url).host
53
50
 
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
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
+ @description = product.first.review
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
61
62
 
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
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
69
76
 
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
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
78
84
 
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
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
+ asin = split_path[split_path.index('gp')+2]
97
+ elsif split_path.include? 'dp'
98
+ asin = split_path[split_path.index('dp')+1]
99
+ else
100
+ "path does not have asin"
101
+ end
102
+ end
103
+ end
90
104
 
91
105
  end
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.2
5
- prerelease:
4
+ version: 0.0.3.stable
5
+ prerelease: 6
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-07 00:00:00.000000000 Z
12
+ date: 2013-07-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: asin
16
- requirement: &76184940 !ruby/object:Gem::Requirement
16
+ requirement: &78594360 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *76184940
24
+ version_requirements: *78594360
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: httpclient
27
- requirement: &76184510 !ruby/object:Gem::Requirement
27
+ requirement: &78594000 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *76184510
35
+ version_requirements: *78594000
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &76184150 !ruby/object:Gem::Requirement
38
+ requirement: &78593690 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *76184150
46
+ version_requirements: *78593690
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &76183800 !ruby/object:Gem::Requirement
49
+ requirement: &78593340 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *76183800
57
+ version_requirements: *78593340
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: httpclient
60
- requirement: &76183320 !ruby/object:Gem::Requirement
60
+ requirement: &78592970 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *76183320
68
+ version_requirements: *78592970
69
69
  description: Tipsanity website uses this gem to extract their marchant related information
70
70
  email:
71
71
  - umeshblader@gmail.com
@@ -101,9 +101,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
101
101
  required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  none: false
103
103
  requirements:
104
- - - ! '>='
104
+ - - ! '>'
105
105
  - !ruby/object:Gem::Version
106
- version: '0'
106
+ version: 1.3.1
107
107
  requirements: []
108
108
  rubyforge_project:
109
109
  rubygems_version: 1.8.15