farleyknight-commission_junction 1.0.4 → 1.1
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/History.txt +4 -0
- data/README.rdoc +3 -1
- data/Rakefile +6 -2
- data/commission_junction.gemspec +18 -11
- data/lib/commission_junction.rb +144 -25
- data/lib/commission_junction/ext.rb +10 -0
- data/lib/commission_junction/migrate.rb +30 -0
- data/lib/commission_junction/search_link.rb +32 -0
- metadata +4 -2
data/History.txt
CHANGED
data/README.rdoc
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
== What?
|
4
4
|
|
5
|
-
A Soap API for CommissionJunction
|
5
|
+
A Soap API for CommissionJunction, plus some local storage capabilities..
|
6
6
|
|
7
7
|
== Where?
|
8
8
|
|
@@ -12,6 +12,8 @@ http://github.com/farleyknight/commission_junction/
|
|
12
12
|
|
13
13
|
This API is mostly based on the Symfony plugin: http://trac.symfony-project.org/wiki/sfCommissionJunctionPlugin
|
14
14
|
|
15
|
+
The storage functionality is still mostly a prototype for now.
|
16
|
+
|
15
17
|
== Git it:
|
16
18
|
|
17
19
|
$ gem sources -a http://gems.github.com
|
data/Rakefile
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
require 'config/requirements'
|
2
|
-
require 'config/hoe' # setup Hoe + all gem configuration
|
3
2
|
|
4
|
-
Dir['tasks/**/*.rake'].each { |rake| load rake }
|
3
|
+
Dir['tasks/**/*.rake'].each { |rake| load rake }
|
4
|
+
|
5
|
+
desc "Rebuilds the rdoc pages"
|
6
|
+
task :rdoc do
|
7
|
+
`rdoc README.rdoc lib/* lib/commission_junction/* -o doc`
|
8
|
+
end
|
data/commission_junction.gemspec
CHANGED
@@ -1,16 +1,23 @@
|
|
1
1
|
|
2
2
|
Gem::Specification.new do |s|
|
3
|
-
s.name
|
4
|
-
s.version
|
5
|
-
s.date
|
6
|
-
s.summary
|
7
|
-
s.email
|
8
|
-
s.homepage
|
9
|
-
s.description
|
10
|
-
s.has_rdoc
|
11
|
-
s.authors
|
12
|
-
s.files
|
13
|
-
|
3
|
+
s.name = "commission_junction"
|
4
|
+
s.version = "1.1"
|
5
|
+
s.date = "2008-09-23"
|
6
|
+
s.summary = "Commission Junction SOAP API"
|
7
|
+
s.email = "farleyknight@gmail.com"
|
8
|
+
s.homepage = "http://github.com/farleyknight/commission_junction/"
|
9
|
+
s.description = "Commission Junction SOAP API"
|
10
|
+
s.has_rdoc = true
|
11
|
+
s.authors = ["Farley Knight"]
|
12
|
+
s.files = [
|
13
|
+
"History.txt", "Manifest.txt", "README.txt", "Rakefile",
|
14
|
+
"commission_junction.gemspec",
|
15
|
+
"lib/commission_junction.rb",
|
16
|
+
"lib/commission_junction/migrate.rb",
|
17
|
+
"lib/commission_junction/search_link.rb",
|
18
|
+
"lib/commission_junction/ext.rb",
|
19
|
+
"examples/based_on_website.rb"]
|
20
|
+
s.rdoc_options = ["--main", "README.rdoc"]
|
14
21
|
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc"]
|
15
22
|
end
|
16
23
|
|
data/lib/commission_junction.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
$:.unshift(File.dirname(__FILE__)) unless
|
2
2
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
3
|
|
4
|
+
require 'yaml'
|
4
5
|
require 'soap/wsdlDriver'
|
5
6
|
require 'commission_junction/ext'
|
6
7
|
|
8
|
+
#
|
9
|
+
# = General Usage
|
7
10
|
#
|
8
11
|
# A fairly simple example of the library
|
9
12
|
# require 'commission_junction'
|
@@ -27,14 +30,14 @@ require 'commission_junction/ext'
|
|
27
30
|
# pp results
|
28
31
|
#
|
29
32
|
# Outputs:
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
33
|
+
# {"totalResults"=>"1200",
|
34
|
+
# "count"=>"10",
|
35
|
+
# "links"=>
|
36
|
+
# {"LinkDetail"=>
|
37
|
+
# [{"threeMonthEPC"=>"-9999999.0",
|
38
|
+
# "sevenDayEPC"=>"-9999999.0",
|
39
|
+
# "promotionType"=>{},
|
40
|
+
# "linkDestination"=>
|
38
41
|
#
|
39
42
|
# Another example, using 'sortBy', shown in the web services documentation
|
40
43
|
# results = cj.searchLinks(:keywords => "kitchen sink", :sortBy => "linkId")
|
@@ -42,26 +45,96 @@ require 'commission_junction/ext'
|
|
42
45
|
# pp results
|
43
46
|
#
|
44
47
|
# Outputs:
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
48
|
+
# {"totalResults"=>"1200",
|
49
|
+
# "count"=>"10",
|
50
|
+
# "links"=>
|
51
|
+
# {"LinkDetail"=>
|
52
|
+
# [{"threeMonthEPC"=>"-9999999.0",
|
53
|
+
# "sevenDayEPC"=>"-9999999.0",
|
54
|
+
# "promotionType"=>{},
|
55
|
+
# "linkDestination"=>
|
56
|
+
# "http://www.vintagetub.com/asp/sinks.asp?utm_id=ID2001",
|
57
|
+
# "relationshipStatus"=>"notjoined",
|
58
|
+
# "linkId"=>"10411673",
|
59
|
+
# "category"=>"bed & bath",
|
60
|
+
# "linkCodeJavascript"=>{},
|
61
|
+
#
|
62
|
+
# = Configuration
|
63
|
+
#
|
64
|
+
# If you don't want to pass your key and id on each instatiation of
|
65
|
+
# of CommissionJunction, create a yaml file:
|
66
|
+
#
|
67
|
+
# $HOME/.commission_junction.yaml
|
68
|
+
#
|
69
|
+
# With $HOME being, of course, your home directory. Then include:
|
70
|
+
#
|
71
|
+
# developerKey: "1234567890abc...."
|
72
|
+
# websiteId: "1234567"
|
73
|
+
#
|
74
|
+
#
|
75
|
+
# = Storage
|
76
|
+
#
|
77
|
+
# For convenience and more "on demand" usage of searchLinks
|
78
|
+
# service, you can set up the ActiveRecord database table
|
79
|
+
# and model, instead of fetching it on every request.
|
80
|
+
#
|
81
|
+
# Here's an example,
|
82
|
+
#
|
83
|
+
# 1) First add your database information to the commission
|
84
|
+
# junction config, mentioned above:
|
85
|
+
#
|
86
|
+
# developerKey: "1234567890abc...."
|
87
|
+
# websiteId: "1234567"
|
88
|
+
#
|
89
|
+
# database:
|
90
|
+
# adapter: mysql
|
91
|
+
# database: commission_junction
|
92
|
+
# username: cj
|
93
|
+
# host: localhost
|
94
|
+
#
|
95
|
+
# 2) Create your database:
|
96
|
+
#
|
97
|
+
# >> mysql -ucj
|
98
|
+
#
|
99
|
+
# mysql> create database commission_junction;
|
100
|
+
#
|
101
|
+
# 3) Then open up irb and run the migration to set up the
|
102
|
+
# table itself
|
103
|
+
#
|
104
|
+
# >> require 'rubygems'
|
105
|
+
# >> require 'commission_junction'
|
106
|
+
# >>
|
107
|
+
# >> CommissionJunction.migrate!
|
108
|
+
#
|
109
|
+
# == CreateSearchLinks: migrating ==============================================
|
110
|
+
# -- create_table(:search_links)
|
111
|
+
# -> 0.1812s
|
112
|
+
# == CreateSearchLinks: migrated (0.1817s) =====================================
|
113
|
+
#
|
114
|
+
# => ["CreateSearchLinks"]
|
115
|
+
#
|
116
|
+
# A more preferable method may be found so this step
|
117
|
+
# may change in the future, but for now it's adequate.
|
118
|
+
#
|
119
|
+
# 4) Next you'll want to start loading it with content.
|
120
|
+
#
|
121
|
+
# require 'commission_junction/search_link'
|
122
|
+
#
|
123
|
+
# SearchLink.update!
|
124
|
+
#
|
125
|
+
# This should start to load your table with all the categories
|
126
|
+
# available from Commission Junction. This may take awhile so
|
127
|
+
# you may want to schedule this at regular intervals instead
|
128
|
+
# of doing so by hand.
|
58
129
|
#
|
130
|
+
# Scheduling section coming soon..
|
131
|
+
#
|
59
132
|
|
60
133
|
class CommissionJunction
|
61
134
|
module VERSION
|
62
135
|
MAJOR = 1
|
63
|
-
MINOR =
|
64
|
-
TINY =
|
136
|
+
MINOR = 1
|
137
|
+
TINY = 0
|
65
138
|
|
66
139
|
STRING = [MAJOR, MINOR, TINY].join('.')
|
67
140
|
end
|
@@ -76,8 +149,18 @@ class CommissionJunction
|
|
76
149
|
'FieldTypesSupport' => 'https://product.api.cj.com/wsdl/version2/supportServiceV2.wsdl'
|
77
150
|
}
|
78
151
|
|
79
|
-
|
80
|
-
|
152
|
+
#
|
153
|
+
# If you've supplied the config file with the proper credentials
|
154
|
+
# then you don't need to pass a key or id.
|
155
|
+
#
|
156
|
+
# Also, any values passed will overwrite the config file's values
|
157
|
+
#
|
158
|
+
def initialize(developerKey = nil, websiteId =nil)
|
159
|
+
if File.exists?(Config.file)
|
160
|
+
parse_config_file!
|
161
|
+
end
|
162
|
+
@developerKey ||= developerKey
|
163
|
+
@websiteId ||= websiteId
|
81
164
|
end
|
82
165
|
|
83
166
|
#
|
@@ -190,6 +273,10 @@ class CommissionJunction
|
|
190
273
|
def getLanguages
|
191
274
|
doOperation('FieldTypesSupport', 'getLanguages', self.instance_variables_hash)
|
192
275
|
end
|
276
|
+
|
277
|
+
def database_enabled?
|
278
|
+
not @database.nil?
|
279
|
+
end
|
193
280
|
|
194
281
|
protected
|
195
282
|
def doOperation(service, method, params)
|
@@ -197,4 +284,36 @@ class CommissionJunction
|
|
197
284
|
driver = factory.create_rpc_driver
|
198
285
|
driver.send(method, params).to_hash["out"]
|
199
286
|
end
|
287
|
+
|
288
|
+
def parse_config_file!
|
289
|
+
config = Config.parse!
|
290
|
+
@developerKey = config["developerKey"]
|
291
|
+
@websiteId = config["websiteId"]
|
292
|
+
@database = config["database"]
|
293
|
+
end
|
294
|
+
|
295
|
+
def self.migrate!
|
296
|
+
db_connect!
|
297
|
+
require 'commission_junction/migrate'
|
298
|
+
end
|
299
|
+
|
300
|
+
def self.db_connect!
|
301
|
+
require 'active_record'
|
302
|
+
config = CommissionJunction::Config.parse!
|
303
|
+
ActiveRecord::Base.establish_connection(config["database"])
|
304
|
+
end
|
305
|
+
|
306
|
+
class Config
|
307
|
+
#
|
308
|
+
# The configuration file should be created at
|
309
|
+
# $HOME/.commission_junction
|
310
|
+
#
|
311
|
+
def self.file
|
312
|
+
File.join(ENV['HOME'], ".commission_junction.yaml")
|
313
|
+
end
|
314
|
+
|
315
|
+
def self.parse!
|
316
|
+
YAML.load(File.read(file))
|
317
|
+
end
|
318
|
+
end
|
200
319
|
end
|
@@ -8,6 +8,16 @@ Array.class_eval do
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
+
Hash.class_eval do
|
12
|
+
def except!(keys)
|
13
|
+
keys.each { |key| delete(key) }
|
14
|
+
end
|
15
|
+
|
16
|
+
def except(keys)
|
17
|
+
clone.except!(keys)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
11
21
|
Object.class_eval do
|
12
22
|
def instance_variables_hash
|
13
23
|
instance_variables.inject({}) do |hash, name|
|
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
class CreateSearchLinks < ActiveRecord::Migration
|
3
|
+
def self.up
|
4
|
+
create_table :search_links do |t|
|
5
|
+
t.string :promotionType
|
6
|
+
t.string :linkDestination
|
7
|
+
t.string :category
|
8
|
+
t.string :language
|
9
|
+
t.string :advertiserName
|
10
|
+
t.string :linkDescription
|
11
|
+
t.string :saleCommission
|
12
|
+
t.string :linkType
|
13
|
+
t.string :linkName
|
14
|
+
t.decimal :clickCommission
|
15
|
+
t.integer :advertiserId
|
16
|
+
t.integer :linkId
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
CreateSearchLinks.migrate(:up)
|
23
|
+
|
24
|
+
# class CreateCategories < ActiveRecord::Migration
|
25
|
+
# def self.up
|
26
|
+
# create_table :categories do
|
27
|
+
# t.string :name
|
28
|
+
# end
|
29
|
+
# end
|
30
|
+
# end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
require 'rubygems'
|
3
|
+
require 'active_record'
|
4
|
+
|
5
|
+
class SearchLink < ActiveRecord::Base
|
6
|
+
establish_connection(CommissionJunction::Config.parse!["database"])
|
7
|
+
|
8
|
+
def self.update!
|
9
|
+
cj = CommissionJunction.new
|
10
|
+
categories = cj.getCategories["string"]
|
11
|
+
categories.each do |category|
|
12
|
+
puts "Querying #{category} for links"
|
13
|
+
results = cj.searchLinks(:category => category, :maxResults => 100)
|
14
|
+
links = results["links"]["LinkDetail"]
|
15
|
+
|
16
|
+
unless links.nil?
|
17
|
+
links.each do |result|
|
18
|
+
SearchLink.create_from_query!(result)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.create_from_query!(result)
|
25
|
+
link = new
|
26
|
+
result.each do |key, value|
|
27
|
+
link.send("#{key}=", value) if key.is_a? Symbol and link.respond_to? key
|
28
|
+
end
|
29
|
+
link.save!
|
30
|
+
link
|
31
|
+
end
|
32
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: farleyknight-commission_junction
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: "1.1"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Farley Knight
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-09-23 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -30,6 +30,8 @@ files:
|
|
30
30
|
- Rakefile
|
31
31
|
- commission_junction.gemspec
|
32
32
|
- lib/commission_junction.rb
|
33
|
+
- lib/commission_junction/migrate.rb
|
34
|
+
- lib/commission_junction/search_link.rb
|
33
35
|
- lib/commission_junction/ext.rb
|
34
36
|
- examples/based_on_website.rb
|
35
37
|
- README.rdoc
|