itunes-affiliate 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ doc/*
6
+ .yardoc
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ rvm:
2
+ - 1.9.2
3
+ - 1.9.3
data/.yardopts ADDED
@@ -0,0 +1,4 @@
1
+ --no-private
2
+ --markup markdown
3
+ -
4
+ LICENSE
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in itunes-affiliate.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Martin Wawrusch
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ ## itunes-affiliate
2
+ A simple gem that helps with the creation of itunes links, especially when dealing with EPF data. This is a work in progress, first version is really just to have the minimal use case working.
3
+
4
+ Feature requests are welcome.
5
+
6
+ If you use it please test against your affiliate id and provide feedback. Use at your own risk.
7
+
8
+ [![Build Status](http://travis-ci.org/freshfugu/itunes-affiliate.png)](http://travis-ci.org/freshfugu/itunes-affiliate)
9
+
10
+ ## Install
11
+
12
+ Include this in your gemfile
13
+
14
+ gem 'itunes-affiliate'
15
+
16
+ ## Configure
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
+
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
+
26
+ ## Use
27
+ A more detailed description can be found at <http://rubydoc.info/gems/itunes-affiliate>.
28
+
29
+ ###Some Sample Code
30
+ link = ItunesLink.new("http://itunes.apple.com/app/swine-flu-detector/id295517288?uo=5")
31
+
32
+ puts link.affiliate_link(:linkshare)
33
+
34
+
35
+ ## Dependencies
36
+
37
+ ## Acknowledgments
38
+
39
+ ## Trivia
40
+
41
+ This gem was created to the tunes of Nicki Minaj and Jennifer Lopez.
42
+
43
+ ## Build
44
+
45
+ rake build
46
+ rake install
47
+ rake release
48
+ ## Release Notes
49
+
50
+ ### 0.0.1
51
+ * First version
52
+
53
+ ## Contributing to itunes-affiliate
54
+
55
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
56
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
57
+ * Fork the project
58
+ * Start a feature/bugfix branch
59
+ * Commit and push until you are happy with your contribution
60
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
61
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
62
+
63
+ == Copyright
64
+
65
+ Copyright (c) 2011 Martin Wawrusch. See LICENSE for
66
+ further details.
67
+
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core/rake_task'
4
+ desc 'Run the specs'
5
+ RSpec::Core::RakeTask.new do |r|
6
+ r.verbose = false
7
+ end
8
+
9
+ task :default => :spec
@@ -0,0 +1,41 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "itunes_affiliate/version"
4
+
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "itunes-affiliate"
8
+ s.version = ItunesAffiliate::VERSION
9
+ s.platform = Gem::Platform::RUBY
10
+ s.authors = ["Martin Wawrusch"]
11
+ s.email = ["martin@wawrusch.com"]
12
+ s.homepage = "http://github.com/freshfugu/itunes-affiliate"
13
+ s.summary = %q{Easily add affiliate information to your itunes links.}
14
+ s.description = %q{This gem provides you with an ItunesLink class that simplifies adding affiliate information to itunes links.}
15
+ s.extra_rdoc_files = ["LICENSE","README.md"]
16
+ s.rdoc_options = ["--charset=UTF-8"]
17
+ s.rubyforge_project = "itunes-affiliate"
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ s.require_paths = ["lib"]
23
+
24
+ # s.add_runtime_dependency "httparty"
25
+ s.add_development_dependency "rspec", "~> 2.1"
26
+ s.add_development_dependency "rake", "~> 0.8"
27
+ s.add_development_dependency "bundler","~> 1.0.0"
28
+ s.post_install_message=<<eos
29
+ **********************************************************************************
30
+ Thank you for using this gem.
31
+
32
+ Follow @martin_sunset on Twitter for announcements, updates and news
33
+ https://twitter.com/martin_sunset
34
+
35
+ To get the source go to http://github.com/freshfugu/itunes-affiliate
36
+
37
+ **********************************************************************************
38
+ eos
39
+
40
+
41
+ end
@@ -0,0 +1,23 @@
1
+ require "itunes_affiliate/version"
2
+ require "itunes_affiliate/configuration"
3
+ require "itunes_affiliate/itunes_link"
4
+
5
+ module ItunesAffiliate
6
+
7
+ class << self
8
+ attr_accessor :config
9
+
10
+ def configure()
11
+ yield(config)
12
+ end
13
+
14
+ def config
15
+ unless @config
16
+ @config = Configuration.new
17
+ @config.reset
18
+ end
19
+ @config
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,61 @@
1
+
2
+ module ItunesAffiliate
3
+ class Configuration
4
+
5
+ # An array of valid keys in the options hash when configuring
6
+ VALID_OPTIONS_KEYS =[
7
+ :linkshare_key,
8
+ :linkshare_japan_key,
9
+ :tradedoubler_key,
10
+ :dgm_key,
11
+ :linkshare_partner_id,
12
+ :linkshare_japan_partner_id,
13
+ :tradedoubler_partner_id,
14
+ :dgm_partner_id].freeze
15
+
16
+ DEFAULT_LINKSHARE_KEY = ''
17
+ DEFAULT_LINKSHARE_JAPAN_KEY = ''
18
+ DEFAULT_TRADEDOUBLER_KEY = ''
19
+ DEFAULT_DGM_KEY = ''
20
+
21
+ LINKSHARE_PARTNER_ID = 30
22
+ LINKSHARE_JAPAN_PARTNER_ID = 30
23
+ TRADEDOUBLER_PARTNER_ID = 2003
24
+ DGM_PARTNER_ID = 1002
25
+
26
+
27
+ attr_accessor *VALID_OPTIONS_KEYS
28
+
29
+ # When this module is extended, set all configuration options to their default values
30
+ def self.extended(base)
31
+ base.reset
32
+ end
33
+
34
+ # Convenience method to allow configuration options to be set in a block.
35
+ def configure
36
+ yield self
37
+ end
38
+
39
+ # Create a hash of options and their values.
40
+ def options
41
+ options = {}
42
+ VALID_OPTIONS_KEYS.each {|k| options[k] = send(k)}
43
+ options
44
+ end
45
+
46
+ # Reset all configuration options to defaults
47
+ def reset
48
+ self.linkshare_key =DEFAULT_LINKSHARE_KEY
49
+ self.linkshare_japan_key =DEFAULT_LINKSHARE_JAPAN_KEY
50
+ self.tradedoubler_key =DEFAULT_TRADEDOUBLER_KEY
51
+ self.dgm_key =DEFAULT_DGM_KEY
52
+
53
+
54
+ self.linkshare_partner_id = LINKSHARE_PARTNER_ID
55
+ self.linkshare_japan_partner_id =LINKSHARE_JAPAN_PARTNER_ID
56
+ self.tradedoubler_partner_id =TRADEDOUBLER_PARTNER_ID
57
+ self.dgm_partner_id = DGM_PARTNER_ID
58
+
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,41 @@
1
+ require 'uri'
2
+
3
+ module ItunesAffiliate
4
+ class ItunesLink
5
+
6
+ Partners = [:linkshare,:linkshare_japan,:tradedoubler,:dgm].freeze
7
+
8
+ def initialize(source_link)
9
+ raise ArgumentException "You need to provide a source link" if source_link == nil
10
+ @source_link = source_link
11
+ end
12
+
13
+ def affiliate_link(partner)
14
+ case partner
15
+ when :linkshare
16
+ append_to_link @source_link, "&partnerId=#{ItunesAffiliate.config.linkshare_partner_id}&siteID=#{ItunesAffiliate.config.linkshare_key}"
17
+ when :linkshare_japan
18
+ append_to_link @source_link, "&partnerId=#{ItunesAffiliate.config.linkshare_japan_partner_id}&siteID=#{ItunesAffiliate.config.linkshare_japan_key}"
19
+ when :tradedoubler
20
+ append_to_link @source_link, "&partnerId=#{ItunesAffiliate.config.tradedoubler_partner_id}&tduid=#{ItunesAffiliate.config.tradedoubler_key}"
21
+ when :dgm
22
+ append_to_link @source_link, "&partnerId=#{ItunesAffiliate.config.dgm_partner_id}&affToken=#{ItunesAffiliate.config.dgm_key}"
23
+ else
24
+ raise ArgumentException "Unrecognized partner #{partner} must be one of #{Partners}"
25
+ end
26
+ end
27
+
28
+
29
+ private
30
+
31
+ # A total hack, this is a good example of really bad code.
32
+ def append_to_link(link, append_me)
33
+ unless URI.parse(link).query
34
+ append_me[0] = "?"
35
+ end
36
+
37
+ "#{link}#{append_me}"
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ module ItunesAffiliate
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,105 @@
1
+ require 'spec_helper'
2
+ require 'itunes-affiliate'
3
+
4
+ describe ItunesAffiliate::ItunesLink do
5
+ include TestHelpers
6
+
7
+ RawLinkWithoutQuestionMark = "http://itunes.apple.com/app/swine-flu-detector/id295517288"
8
+ RawLinkWithQuestionMark = "http://itunes.apple.com/app/swine-flu-detector/id295517288?uo=5"
9
+
10
+ LinkShareAffiliateCode= "Zi7WWVQYf4o"
11
+ LinkShareJapanAffiliateCode = "5635445dsf"
12
+ TradeDoublerAffiliateCode = 'fdsewr3sd'
13
+ DGMAffiliateCode = 'ewfsdd'
14
+
15
+ before(:all) do
16
+ ItunesAffiliate.configure do |config|
17
+ config.linkshare_key = LinkShareAffiliateCode
18
+ config.linkshare_japan_key =LinkShareJapanAffiliateCode
19
+ config.tradedoubler_key =TradeDoublerAffiliateCode
20
+ config.dgm_key =DGMAffiliateCode
21
+ end
22
+ end
23
+
24
+
25
+ context "when using an itunes link with parameter" do
26
+ before(:each) do
27
+ @link = ItunesAffiliate::ItunesLink.new RawLinkWithQuestionMark
28
+ end
29
+
30
+ it "should create a valid linkshare link" do
31
+ params = link_to_hash @link.affiliate_link(:linkshare)
32
+
33
+ params['siteID'].should == LinkShareAffiliateCode
34
+ params['partnerId'].should == '30'
35
+ params['uo'].should == '5'
36
+ end
37
+
38
+ it "should create a valid linkshare japan link" do
39
+ params = link_to_hash @link.affiliate_link(:linkshare_japan)
40
+
41
+ params['siteID'].should == LinkShareJapanAffiliateCode
42
+ params['partnerId'].should == '30'
43
+ params['uo'].should == '5'
44
+ end
45
+
46
+ it "should create a valid tradedoubler link" do
47
+ params = link_to_hash @link.affiliate_link(:tradedoubler)
48
+
49
+ params['tduid'].should == TradeDoublerAffiliateCode
50
+ params['partnerId'].should == '2003'
51
+ params['uo'].should == '5'
52
+ end
53
+
54
+ it "should create a valid dgm link" do
55
+ params = link_to_hash @link.affiliate_link(:dgm)
56
+
57
+ params['affToken'].should == DGMAffiliateCode
58
+ params['partnerId'].should == '1002'
59
+ params['uo'].should == '5'
60
+ end
61
+ end
62
+
63
+ context "when using an itunes link withOUT parameter" do
64
+ before(:each) do
65
+ @link = ItunesAffiliate::ItunesLink.new RawLinkWithoutQuestionMark
66
+ end
67
+
68
+ it "should create a valid linkshare link" do
69
+ params = link_to_hash @link.affiliate_link(:linkshare)
70
+
71
+ params['siteID'].should == LinkShareAffiliateCode
72
+ params['partnerId'].should == '30'
73
+ end
74
+
75
+ it "should create a valid linkshare japan link" do
76
+ params = link_to_hash @link.affiliate_link(:linkshare_japan)
77
+
78
+ params['siteID'].should == LinkShareJapanAffiliateCode
79
+ params['partnerId'].should == '30'
80
+ end
81
+
82
+ it "should create a valid tradedoubler link" do
83
+ params = link_to_hash @link.affiliate_link(:tradedoubler)
84
+
85
+ params['tduid'].should == TradeDoublerAffiliateCode
86
+ params['partnerId'].should == '2003'
87
+ end
88
+
89
+ it "should create a valid dgm link" do
90
+ params = link_to_hash @link.affiliate_link(:dgm)
91
+
92
+ params['affToken'].should == DGMAffiliateCode
93
+ params['partnerId'].should == '1002'
94
+ end
95
+ end
96
+
97
+
98
+ # Missing specs:
99
+ # Must raise ArgumentException if invalid affiliate link
100
+ # Must raise ArgumentException if no link is passed
101
+ # check invalid url
102
+ # check no params -> make sure url is correct
103
+ # check that the source url is still present
104
+ # select code based on language
105
+ end
@@ -0,0 +1,31 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ require 'rspec'
6
+ require 'itunes-affiliate'
7
+ require 'uri'
8
+
9
+ # Requires supporting files with custom matchers and macros, etc,
10
+ # in ./support/ and its subdirectories.
11
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
12
+
13
+ module TestHelpers
14
+
15
+ def link_to_hash(link)
16
+ res = URI.parse link
17
+ res = res.query ? res.query.split('&') : []
18
+
19
+ params = {}
20
+ res.each {|x| y = x.split("=");params[ y[0]] = y[1] }
21
+
22
+ params
23
+ end
24
+ end
25
+
26
+ RSpec.configure do |config|
27
+ config.color_enabled = true
28
+ end
29
+
30
+
31
+
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: itunes-affiliate
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Martin Wawrusch
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-09-27 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rspec
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: "2.1"
25
+ type: :development
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: "0.8"
36
+ type: :development
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: bundler
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: 1.0.0
47
+ type: :development
48
+ version_requirements: *id003
49
+ description: This gem provides you with an ItunesLink class that simplifies adding affiliate information to itunes links.
50
+ email:
51
+ - martin@wawrusch.com
52
+ executables: []
53
+
54
+ extensions: []
55
+
56
+ extra_rdoc_files:
57
+ - LICENSE
58
+ - README.md
59
+ files:
60
+ - .gitignore
61
+ - .travis.yml
62
+ - .yardopts
63
+ - Gemfile
64
+ - LICENSE
65
+ - README.md
66
+ - Rakefile
67
+ - itunes-affiliate.gemspec
68
+ - lib/itunes-affiliate.rb
69
+ - lib/itunes_affiliate/configuration.rb
70
+ - lib/itunes_affiliate/itunes_link.rb
71
+ - lib/itunes_affiliate/version.rb
72
+ - spec/itunes_link_spec.rb
73
+ - spec/spec_helper.rb
74
+ has_rdoc: true
75
+ homepage: http://github.com/freshfugu/itunes-affiliate
76
+ licenses: []
77
+
78
+ post_install_message: |
79
+ **********************************************************************************
80
+ Thank you for using this gem.
81
+
82
+ Follow @martin_sunset on Twitter for announcements, updates and news
83
+ https://twitter.com/martin_sunset
84
+
85
+ To get the source go to http://github.com/freshfugu/itunes-affiliate
86
+
87
+ **********************************************************************************
88
+
89
+ rdoc_options:
90
+ - --charset=UTF-8
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: "0"
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: "0"
105
+ requirements: []
106
+
107
+ rubyforge_project: itunes-affiliate
108
+ rubygems_version: 1.5.0
109
+ signing_key:
110
+ specification_version: 3
111
+ summary: Easily add affiliate information to your itunes links.
112
+ test_files:
113
+ - spec/itunes_link_spec.rb
114
+ - spec/spec_helper.rb