itunes-affiliate 0.0.2 → 0.0.3
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 +3 -0
- data/lib/itunes-affiliate.rb +24 -0
- data/lib/itunes_affiliate/itunes_link.rb +13 -1
- data/lib/itunes_affiliate/version.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
data/lib/itunes-affiliate.rb
CHANGED
@@ -2,15 +2,35 @@ require "itunes_affiliate/version"
|
|
2
2
|
require "itunes_affiliate/configuration"
|
3
3
|
require "itunes_affiliate/itunes_link"
|
4
4
|
|
5
|
+
# @author Martin Wawrusch
|
6
|
+
#
|
7
|
+
# A simple gem that helps with the creation of itunes links, especially when dealing with EPF data.
|
8
|
+
#
|
9
|
+
# @example Configuring the keys (in config/initializers/itunes_affiliate.rb)
|
10
|
+
# ItunesAffiliate.configure do |config|
|
11
|
+
# config.linkshare_key = '<LINKSHARE_KEY>'
|
12
|
+
# config.linkshare_japan_key = '<LINKSHARE_JAPAN_KEY>'
|
13
|
+
# config.tradedoubler_key = '<TRADEDOUBLE_KEY>'
|
14
|
+
# config.dgm_key = '<DGM_KEY>'
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
#
|
18
|
+
# @example Add affiliate information to a link and ignore invalid links
|
19
|
+
# link = ItunesAffiliate.affiliate_link("http://itunes.apple.com/app/swine-flu-detector/id295517288",:linkshare)
|
20
|
+
#
|
5
21
|
module ItunesAffiliate
|
6
22
|
|
7
23
|
class << self
|
8
24
|
attr_accessor :config
|
9
25
|
|
26
|
+
# Invoked with blog to configure this gem.
|
27
|
+
# Pass a block with |config| and set the keys
|
10
28
|
def configure()
|
11
29
|
yield(config)
|
12
30
|
end
|
13
31
|
|
32
|
+
# Access the configuration object
|
33
|
+
# @return [Configuration] the configuration object singleton.
|
14
34
|
def config
|
15
35
|
unless @config
|
16
36
|
@config = Configuration.new
|
@@ -19,6 +39,10 @@ module ItunesAffiliate
|
|
19
39
|
@config
|
20
40
|
end
|
21
41
|
|
42
|
+
# Return an affiliate link for a given clean itunes url
|
43
|
+
# @param [String] link the link to which to add the affiliate information.
|
44
|
+
# @param [Symbol] partner the partner, as determined by the store. Valid values are :linkshare,:linkshare_japan,:tradedoubler,:dgm
|
45
|
+
# @return [String] a modified link containing the affiliate information, or the original link if the link is not an itunes clean link.
|
22
46
|
def affiliate_link(link,partner)
|
23
47
|
return link unless ItunesAffiliate::ItunesLink.is_valid_link?(link)
|
24
48
|
|
@@ -3,13 +3,22 @@ require 'uri'
|
|
3
3
|
module ItunesAffiliate
|
4
4
|
class ItunesLink
|
5
5
|
|
6
|
+
# The list of possible affiliate parters, as determined by the store.
|
6
7
|
Partners = [:linkshare,:linkshare_japan,:tradedoubler,:dgm].freeze
|
7
8
|
|
9
|
+
# Initializes a new instance of the ItunesLink class
|
10
|
+
# @param [String] source_link the source link, which should be a valid clean itunes link
|
11
|
+
# @return [ItunesLink] an initialized ItunesLink object.
|
12
|
+
# @raise [ArgumentException] raised when source_link is nil
|
8
13
|
def initialize(source_link)
|
9
|
-
raise ArgumentException "You need to provide a source link"
|
14
|
+
raise ArgumentException "You need to provide a source link" unless source_link
|
10
15
|
@source_link = source_link
|
11
16
|
end
|
12
17
|
|
18
|
+
# Returns an affiliate link
|
19
|
+
# @param [Symbol] partner the partner, as determined by the store. Valid values are :linkshare,:linkshare_japan,:tradedoubler,:dgm
|
20
|
+
# @return [String] a modified link containing the affiliate information, or the original link if the link is not an itunes clean link.
|
21
|
+
# @raise [ArgumentException] raised when the partner is not a valid symbol
|
13
22
|
def affiliate_link(partner)
|
14
23
|
case partner
|
15
24
|
when :linkshare
|
@@ -25,6 +34,9 @@ module ItunesAffiliate
|
|
25
34
|
end
|
26
35
|
end
|
27
36
|
|
37
|
+
# Determines if the link is a valid itunes clean url.
|
38
|
+
# @param [String] link the link that should be checked.
|
39
|
+
# @return [Boolean] true if the link is not nil and has the host itunes.apple.com, otherwise false
|
28
40
|
def self.is_valid_link?(link)
|
29
41
|
uri = URI.parse(link) rescue nil
|
30
42
|
|