linkshare 0.0.9 → 0.1.0

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.
@@ -1,6 +1,7 @@
1
1
  require 'httparty'
2
- require 'fastercsv'
2
+ require 'crack'
3
3
 
4
4
  directory = File.expand_path(File.dirname(__FILE__))
5
5
  require File.join(directory, "linkshare", "base")
6
+ require File.join(directory, "linkshare", "product")
6
7
  require File.join(directory, "linkshare", "commission")
@@ -2,6 +2,8 @@ module Linkshare
2
2
  class Base
3
3
  include HTTParty
4
4
  format :xml
5
+
6
+ attr_reader :total_pages, :total_matches, :page_number
5
7
 
6
8
  @@credentials = {}
7
9
  @@default_params = {}
@@ -23,7 +25,6 @@ module Linkshare
23
25
  @@credentials['pass'] = pass.to_s
24
26
  end
25
27
 
26
-
27
28
  class << self
28
29
  def base_url
29
30
  "http://cli.linksynergy.com/"
@@ -33,33 +34,27 @@ module Linkshare
33
34
  params = default_params.merge(provided_params)
34
35
  invalid_params = params.select{|k,v| !available_params.include?(k.to_s)}.map{|k,v| k}
35
36
  raise ArgumentError.new("Invalid parameters: #{invalid_params.join(', ')}") if invalid_params.length > 0
37
+ params
36
38
  end
37
39
 
38
40
  def get_service(path, query)
39
41
  query.keys.each{|k| query[k.to_s] = query.delete(k)}
40
- query.merge!({'cuserid' => credentials['user_id'], 'cpi' => credentials['pass']})
41
42
 
42
43
  results = []
43
-
44
44
  begin
45
+ # pairs = [] ; query.each_pair{|k,v| pairs << "#{k}=#{v}" } ; p "#{path}&#{pairs.join('&')}"
45
46
  response = get(path, :query => query, :timeout => 30)
46
47
  rescue Timeout::Error
47
48
  nil
48
49
  end
49
50
 
50
- unless validate_response(response)
51
- str = response.body #+ "1x1\t36342\tAdvertiser Y\t2163\t1/31/2002\t8:58\t32\t7.99\t1\t0.39\t2/1/2002\t12:46" #dummy data
52
- str = str.gsub(" \t","\t").gsub("\t\n", "\n").gsub(" ", "_").gsub("($)", "").downcase!
53
-
54
- results = FasterCSV.parse(str, {:col_sep => "\t", :row_sep => "\n", :headers => true})
55
- end
51
+ raise_if_invalid_response(response)
56
52
 
57
- results.map{|r| self.new(r.to_hash)}
58
- end # get
53
+ Crack::XML.parse(response.body)
54
+ end
59
55
 
60
56
  def credentials
61
57
  unless @@credentials && @@credentials.length > 0
62
- # there is no offline or test mode for CJ - so I won't include any credentials in this gem
63
58
  config_file = ["config/linkshare.yml", File.join(ENV['HOME'], '.linkshare.yaml')].select{|f| File.exist?(f)}.first
64
59
 
65
60
  unless File.exist?(config_file)
@@ -69,9 +64,9 @@ module Linkshare
69
64
  end
70
65
  end
71
66
  @@credentials
72
- end # credentails
67
+ end
73
68
 
74
- def validate_response(response)
69
+ def raise_if_invalid_response(response)
75
70
  raise ArgumentError, "There was an error connecting to LinkShare's reporting server." if response.body.include?("REPORTING ERROR")
76
71
  end
77
72
 
@@ -79,6 +74,6 @@ module Linkshare
79
74
  find(params).first
80
75
  end
81
76
 
82
- end # self
83
- end # Base
84
- end # Linkshare
77
+ end
78
+ end
79
+ end
@@ -7,6 +7,7 @@ module Linkshare
7
7
 
8
8
  def find(params = {})
9
9
  validate_params!(params, %w{bdate edate eid nid})
10
+ params.merge!('cuserid' => credentials['user_id'], 'cpi' => credentials['pass'])
10
11
  get_service(service_url, params)
11
12
  end
12
13
 
@@ -0,0 +1,31 @@
1
+ # http://helpcenter.linkshare.com/publisher/questions.php?questionid=652
2
+ module Linkshare
3
+ class Product < Base
4
+
5
+ PARAMS = %w[token cat max maxResults pagenumber mid keyword exact one none sort sorttype] # cat = Category, mid = Advertister
6
+
7
+ BASE_URL = 'http://productsearch.linksynergy.com/productsearch'
8
+
9
+ class << self
10
+ def service_url
11
+ BASE_URL
12
+ end
13
+
14
+ def find(params = {})
15
+ validate_params!(params)
16
+ result = get_service(service_url, params)
17
+ Array.wrap(result['result']['item']).collect{ |product| self.new(product) }
18
+ end
19
+
20
+ def validate_params!(params)
21
+ params.merge!('token' => credentials['token'])
22
+ super(params, PARAMS)
23
+ end
24
+ end
25
+
26
+ def initialize(product)
27
+ super(product)
28
+ end
29
+
30
+ end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module Linkshare
2
- VERSION = "0.0.9"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -6,11 +6,11 @@ Gem::Specification.new do |s|
6
6
  s.name = "linkshare"
7
7
  s.version = Linkshare::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
- s.authors = ["Ian Ehlert"]
10
- s.email = ["ian.ehlert@tstmedia.com"]
11
- s.homepage = ""
12
- s.summary = %q{Ruby gem to hit the Linkshare report api.}
13
- s.description = %q{Ruby gem to hit the Linkshare report api.}
9
+ s.authors = ["Jason Younker"]
10
+ s.email = ["jason@ynkr.org"]
11
+ s.homepage = "http://www.ynkr.org"
12
+ s.summary = %q{Ruby lib to talk to Linkshare api.}
13
+ s.description = %q{Ruby library to interface with Linkshare report and product apis. Forked from Ian Ehlerts linkshare project}
14
14
 
15
15
  s.rubyforge_project = "linkshare"
16
16
 
@@ -19,5 +19,5 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
  s.add_dependency(%q<httparty>)
22
- s.add_dependency(%q<fastercsv>)
22
+ s.add_dependency(%q<crack>)
23
23
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linkshare
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 9
10
- version: 0.0.9
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
- - Ian Ehlert
13
+ - Jason Younker
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
@@ -32,7 +32,7 @@ dependencies:
32
32
  type: :runtime
33
33
  version_requirements: *id001
34
34
  - !ruby/object:Gem::Dependency
35
- name: fastercsv
35
+ name: crack
36
36
  prerelease: false
37
37
  requirement: &id002 !ruby/object:Gem::Requirement
38
38
  none: false
@@ -45,9 +45,9 @@ dependencies:
45
45
  version: "0"
46
46
  type: :runtime
47
47
  version_requirements: *id002
48
- description: Ruby gem to hit the Linkshare report api.
48
+ description: Ruby library to interface with Linkshare report and product apis. Forked from Ian Ehlerts linkshare project
49
49
  email:
50
- - ian.ehlert@tstmedia.com
50
+ - jason@ynkr.org
51
51
  executables: []
52
52
 
53
53
  extensions: []
@@ -62,9 +62,10 @@ files:
62
62
  - lib/linkshare.rb
63
63
  - lib/linkshare/base.rb
64
64
  - lib/linkshare/commission.rb
65
+ - lib/linkshare/product.rb
65
66
  - lib/linkshare/version.rb
66
67
  - linkshare.gemspec
67
- homepage: ""
68
+ homepage: http://www.ynkr.org
68
69
  licenses: []
69
70
 
70
71
  post_install_message:
@@ -96,6 +97,6 @@ rubyforge_project: linkshare
96
97
  rubygems_version: 1.8.10
97
98
  signing_key:
98
99
  specification_version: 3
99
- summary: Ruby gem to hit the Linkshare report api.
100
+ summary: Ruby lib to talk to Linkshare api.
100
101
  test_files: []
101
102