itunes-affiliate 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -16,12 +16,12 @@ gem 'itunes-affiliate'
16
16
  ## Configure
17
17
  Create an initializer if you use rails in config/initializers named itunes_affiliate.rb and add the following code snippet with your keys. If a key is not present it will be ignored.
18
18
 
19
- ItunesAffiliate.configure do |config|
20
- config.linkshare_key = '<LINKSHARE_KEY>'
21
- config.linkshare_japan_key = '<LINKSHARE_JAPAN_KEY>'
22
- config.tradedoubler_key = '<TRADEDOUBLE_KEY>'
23
- config.dgm_key = '<DGM_KEY>'
24
- end
19
+ ItunesAffiliate.configure do |config|
20
+ config.linkshare_key = '<LINKSHARE_KEY>'
21
+ config.linkshare_japan_key = '<LINKSHARE_JAPAN_KEY>'
22
+ config.tradedoubler_key = '<TRADEDOUBLE_KEY>'
23
+ config.dgm_key = '<DGM_KEY>'
24
+ end
25
25
 
26
26
  ## Use
27
27
  A more detailed description can be found at <http://rubydoc.info/gems/itunes-affiliate>.
@@ -47,6 +47,9 @@ rake install
47
47
  rake release
48
48
  ## Release Notes
49
49
 
50
+ ### 0.0.2
51
+ * Added affiliate_link to ItunesAffiliate as class method.
52
+
50
53
  ### 0.0.1
51
54
  * First version
52
55
 
@@ -19,5 +19,10 @@ module ItunesAffiliate
19
19
  @config
20
20
  end
21
21
 
22
+ def affiliate_link(link,partner)
23
+ return link unless ItunesAffiliate::ItunesLink.is_valid_link?(link)
24
+
25
+ return ItunesAffiliate::ItunesLink.new(link).affiliate_link(partner)
26
+ end
22
27
  end
23
28
  end
@@ -25,6 +25,11 @@ module ItunesAffiliate
25
25
  end
26
26
  end
27
27
 
28
+ def self.is_valid_link?(link)
29
+ uri = URI.parse(link) rescue nil
30
+
31
+ uri != nil && uri.host != nil && uri.host.downcase == "itunes.apple.com"
32
+ end
28
33
 
29
34
  private
30
35
 
@@ -1,3 +1,3 @@
1
1
  module ItunesAffiliate
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -94,7 +94,52 @@ describe ItunesAffiliate::ItunesLink do
94
94
  end
95
95
  end
96
96
 
97
-
97
+ context "when converting through the class method" do
98
+ before(:each) do
99
+ end
100
+
101
+ it "should pass nil values along" do
102
+ res = ItunesAffiliate.affiliate_link(nil,:linkshare)
103
+ res.should be_nil
104
+ end
105
+
106
+ it "should pass empty values along" do
107
+ res = ItunesAffiliate.affiliate_link('',:linkshare)
108
+ res.should == ''
109
+ end
110
+
111
+ it "should pass random urls along" do
112
+ res = ItunesAffiliate.affiliate_link("http://latimes.com",:linkshare)
113
+ res.should == "http://latimes.com"
114
+ end
115
+
116
+ it "should convert itunes urls" do
117
+ params = link_to_hash ItunesAffiliate.affiliate_link(RawLinkWithoutQuestionMark,:linkshare)
118
+ params['siteID'].should == LinkShareAffiliateCode
119
+ params['partnerId'].should == '30'
120
+ end
121
+ end
122
+
123
+ context "testing urls" do
124
+ it "should recognize nil as not an itunes url" do
125
+ ItunesAffiliate::ItunesLink.is_valid_link?(nil).should be(false)
126
+ end
127
+
128
+ it "should recognize empty as not an itunes url" do
129
+ ItunesAffiliate::ItunesLink.is_valid_link?("").should be(false)
130
+ end
131
+
132
+ it "should recognize http://latimes.com as not an itunes url" do
133
+ ItunesAffiliate::ItunesLink.is_valid_link?("http://latimes.com").should be(false)
134
+ end
135
+
136
+
137
+ it "should recognize a valid itunes url." do
138
+ ItunesAffiliate::ItunesLink.is_valid_link?(RawLinkWithoutQuestionMark).should be(true)
139
+ ItunesAffiliate::ItunesLink.is_valid_link?(RawLinkWithQuestionMark).should be(true)
140
+ end
141
+
142
+ end
98
143
  # Missing specs:
99
144
  # Must raise ArgumentException if invalid affiliate link
100
145
  # Must raise ArgumentException if no link is passed
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: itunes-affiliate
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Martin Wawrusch