hasoffers 0.1.2 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  pkg
2
2
  doc
3
- Manifest
3
+ Manifest
4
+ hasoffers-0.1.4.gem
data/CHANGELOG CHANGED
@@ -1,4 +1,10 @@
1
- = HasOffers CHANGELOG
1
+ == Version 0.1.4
2
+ * Create a class method to get and set the @@base_uri, with tests
3
+
4
+ == Version 0.1.3
5
+ * Bug fix - it's possible for AffiliateBilling to return an array of nil, instead
6
+ of an array of invoices.
7
+ * Updated various unit tests to fix failing tests while HAS_OFFERS_LIVE is enabled.
2
8
 
3
9
  == Version 0.1.2
4
10
  * Minor bug fix for running without the has_offers.yml config file
@@ -0,0 +1,20 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ hasoffers (0.1.4)
5
+ crack
6
+ yajl-ruby
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ crack (0.3.1)
12
+ rake (0.9.2)
13
+ yajl-ruby (1.1.0)
14
+
15
+ PLATFORMS
16
+ ruby
17
+
18
+ DEPENDENCIES
19
+ hasoffers!
20
+ rake
data/Rakefile CHANGED
@@ -1,2 +1,8 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
8
+ end
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Luke Ludwig"]
10
10
  s.email = ["luke.ludwig@tstmedia.com"]
11
- s.homepage = "https://github.com/ngin/hasoffers"
11
+ s.homepage = "https://github.com/tstmedia/hasoffers"
12
12
  s.summary = %q{Implementation of the HasOffers API for affiliate advertising.}
13
13
  s.description = %q{Implementation of the HasOffers API for affiliate advertising.}
14
14
 
@@ -18,4 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
+ s.add_dependency 'crack'
22
+ s.add_dependency 'yajl-ruby'
23
+ s.add_development_dependency 'rake'
21
24
  end
@@ -11,14 +11,22 @@ module HasOffers
11
11
  get_request(Target, 'findInvoiceStats', params)
12
12
  end
13
13
 
14
+ def simplify_response_data data
15
+ # Data is returned as a hash like this:
16
+ # {
17
+ # "1" => {"AffiliateInvoice" => {<what we really want>}, ... },
18
+ # "2" => {"AffiliateInvoice" => {<what we really want>}, ... }
19
+ # }
20
+ #
21
+ # This function will extract it out.
22
+ data.map { |id, invoice_data| invoice_data["AffiliateInvoice"] }
23
+ end
24
+
14
25
  def find_all_invoices(params)
15
26
  response = get_request(Target, 'findAllInvoices', params)
16
27
  if response.success?
17
28
  # strip out the clutter
18
- data = response.data.map do |invoice|
19
- invoice[1].values.first
20
- end
21
- response.set_data data
29
+ response.set_data simplify_response_data(response.data)
22
30
  end
23
31
  response
24
32
  end
@@ -28,10 +36,7 @@ module HasOffers
28
36
  response = get_request(Target, 'findAllInvoicesByIds', params)
29
37
  if response.success?
30
38
  # strip out the clutter
31
- data = response.data.map do |invoice|
32
- invoice[1].values.first
33
- end
34
- response.set_data data
39
+ response.set_data simplify_response_data(response.data)
35
40
  end
36
41
  response
37
42
  end
@@ -3,12 +3,20 @@ module HasOffers
3
3
 
4
4
  class Base
5
5
 
6
- BaseUri = 'https://api.hasoffers.com/Api'
6
+ @@base_uri = 'https://api.hasoffers.com/Api'
7
7
  @@api_mode = ((defined?(Rails) and Rails.env.production?) or ENV['HAS_OFFERS_LIVE'] == '1') ? :live : :test
8
8
  @@default_params = nil
9
9
 
10
10
  class << self
11
11
 
12
+ def base_uri=(uri)
13
+ @@base_uri = uri
14
+ end
15
+
16
+ def base_uri
17
+ @@base_uri
18
+ end
19
+
12
20
  def initialize_credentials
13
21
  config_file = ENV['HAS_OFFERS_CONFIG_FILE'] || "config/has_offers.yml"
14
22
  if File.exists?(config_file)
@@ -77,12 +85,12 @@ module HasOffers
77
85
  data = build_request_params(target, method, params)
78
86
  if live?
79
87
  if http_method == :post
80
- uri = URI.parse BaseUri
88
+ uri = URI.parse base_uri
81
89
  http = new_http uri
82
90
  raw_request = Net::HTTP::Post.new(uri.request_uri)
83
91
  raw_request.body = query_string data
84
92
  else # assume get
85
- uri = URI.parse("#{BaseUri}?#{query_string(data)}")
93
+ uri = URI.parse("#{base_uri}?#{query_string(data)}")
86
94
  http = new_http uri
87
95
  raw_request = Net::HTTP::Get.new(uri.request_uri)
88
96
  end
@@ -108,4 +116,4 @@ module HasOffers
108
116
 
109
117
  end
110
118
 
111
- end
119
+ end
@@ -80,7 +80,7 @@ module HasOffers
80
80
  protected
81
81
 
82
82
  def paginated_response?
83
- @body['response']['data'] and @body['response']['data'].is_a?(Hash) and @body['response']['data']['pageCount']
83
+ @body['response']['data'] and @body['response']['data'].is_a?(Hash) and @body['response']['data'].has_key?('pageCount')
84
84
  end
85
85
 
86
86
  end
@@ -1,3 +1,3 @@
1
1
  module Hasoffers
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -10,23 +10,22 @@ class AffiliateBillingTest < Test::Unit::TestCase
10
10
  def test_find_all_invoices
11
11
  response = HasOffers::AffiliateBilling.find_all_invoices({})
12
12
  assert_success response
13
- assert response.data.length > 0, "No invoices were returned."
13
+ assert response.data.compact.length > 0, "No invoices were returned."
14
14
  end
15
15
 
16
16
  def test_find_all_invoices_filtered_by_affiliate
17
17
  response = HasOffers::AffiliateBilling.find_all_invoices(
18
- 'filters' => ['AffiliateInvoice.affiliate_id' => '7'],
18
+ 'filters' => ['AffiliateInvoice.affiliate_id' => '1'],
19
19
  'fields' => ['is_paid', 'impressions', 'clicks', 'conversions', 'amount']
20
20
  )
21
21
  assert_success response
22
- assert response.data.length > 0, "No invoices were returned."
22
+ assert response.data.compact.length > 0, "No invoices were returned."
23
23
  end
24
24
 
25
25
  def test_find_all_invoices_by_ids
26
- response = HasOffers::AffiliateBilling.find_all_invoices_by_ids([7,11]
27
- )
26
+ response = HasOffers::AffiliateBilling.find_all_invoices_by_ids([7,11])
28
27
  assert_success response
29
- assert response.data.length > 0, "No invoices were returned."
28
+ assert response.data.compact.length > 0, "No invoices were returned."
30
29
  end
31
30
 
32
31
  def good_params
@@ -0,0 +1,10 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class AdvertiserTest < Test::Unit::TestCase
4
+ def test_set_base_uri
5
+ new_uri = "http://example.com"
6
+ HasOffers::Base.base_uri = new_uri
7
+ assert_equal new_uri, HasOffers::Base.base_uri
8
+ end
9
+ end
10
+
@@ -12,7 +12,9 @@ class ConversionTest < Test::Unit::TestCase
12
12
  end
13
13
 
14
14
  def test_update
15
- response = HasOffers::Conversion.update(1, {'affiliate_id' => '1', 'offer_id' => '1', 'payout' => '11.50', 'revenue' => '6.75'})
15
+ response = HasOffers::Conversion.create(good_params)
16
+ assert_success response
17
+ response = HasOffers::Conversion.update(response.data, {'payout' => '11.50', 'revenue' => '6.75'})
16
18
  assert_success response
17
19
  end
18
20
 
metadata CHANGED
@@ -1,37 +1,60 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: hasoffers
3
- version: !ruby/object:Gem::Version
4
- hash: 31
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 2
10
- version: 0.1.2
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Luke Ludwig
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-03-17 00:00:00 -05:00
19
- default_executable:
20
- dependencies: []
21
-
12
+ date: 2012-02-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: crack
16
+ requirement: &70315768875080 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70315768875080
25
+ - !ruby/object:Gem::Dependency
26
+ name: yajl-ruby
27
+ requirement: &70315768874660 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70315768874660
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ requirement: &70315768874240 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70315768874240
22
47
  description: Implementation of the HasOffers API for affiliate advertising.
23
- email:
48
+ email:
24
49
  - luke.ludwig@tstmedia.com
25
50
  executables: []
26
-
27
51
  extensions: []
28
-
29
52
  extra_rdoc_files: []
30
-
31
- files:
53
+ files:
32
54
  - .gitignore
33
55
  - CHANGELOG
34
56
  - Gemfile
57
+ - Gemfile.lock
35
58
  - README.rdoc
36
59
  - Rakefile
37
60
  - config/has_offers.yml
@@ -51,48 +74,46 @@ files:
51
74
  - test/advertiser_test.rb
52
75
  - test/affiliate_billing_test.rb
53
76
  - test/affiliate_test.rb
77
+ - test/base_test.rb
54
78
  - test/conversion_test.rb
55
79
  - test/offer_test.rb
56
80
  - test/report_test.rb
57
81
  - test/test_helper.rb
58
- has_rdoc: true
59
- homepage: https://github.com/ngin/hasoffers
82
+ homepage: https://github.com/tstmedia/hasoffers
60
83
  licenses: []
61
-
62
84
  post_install_message:
63
85
  rdoc_options: []
64
-
65
- require_paths:
86
+ require_paths:
66
87
  - lib
67
- required_ruby_version: !ruby/object:Gem::Requirement
88
+ required_ruby_version: !ruby/object:Gem::Requirement
68
89
  none: false
69
- requirements:
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- hash: 3
73
- segments:
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ segments:
74
95
  - 0
75
- version: "0"
76
- required_rubygems_version: !ruby/object:Gem::Requirement
96
+ hash: -3016471400862680151
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
98
  none: false
78
- requirements:
79
- - - ">="
80
- - !ruby/object:Gem::Version
81
- hash: 3
82
- segments:
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ segments:
83
104
  - 0
84
- version: "0"
105
+ hash: -3016471400862680151
85
106
  requirements: []
86
-
87
107
  rubyforge_project: hasoffers
88
- rubygems_version: 1.4.2
108
+ rubygems_version: 1.8.13
89
109
  signing_key:
90
110
  specification_version: 3
91
111
  summary: Implementation of the HasOffers API for affiliate advertising.
92
- test_files:
112
+ test_files:
93
113
  - test/advertiser_test.rb
94
114
  - test/affiliate_billing_test.rb
95
115
  - test/affiliate_test.rb
116
+ - test/base_test.rb
96
117
  - test/conversion_test.rb
97
118
  - test/offer_test.rb
98
119
  - test/report_test.rb