hasoffersv3 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: da538c54d138ea729812c0ba860ad4e207657338
4
- data.tar.gz: eefed68384c2beda2a459d9060ef5b9b7c3b970d
3
+ metadata.gz: 667f1f3af61d4c3eb35c8ca1eebdaa767b9fd0bb
4
+ data.tar.gz: 405df6a514919f645e3529a479fd704d8ff54203
5
5
  SHA512:
6
- metadata.gz: 3a581c12f4dfd240f662b5472381d9e73d56c1b67727810ddac768e04aeb3dd836930194ec312503abdd8c3c791ca14f5bfe6a435656d2fc788ea94c5fcc9014
7
- data.tar.gz: 1ab778d3121d3bf5b006369ce03d4b1483cf35400736bf646f0bad978bfcd62deb1f3d4a001c0085e8401b4abbf48bd8c5ac03f6ec8f16dd674b95ebc336818a
6
+ metadata.gz: 9919ca8819a7b8272242d91bac0f0c0444cde8f320da829883e4ee8f185a67305e923dd0656f63032b6a6d33ade94784efa5f5129e0812c04efda6a18b2af3f9
7
+ data.tar.gz: 41e1bd782835fd46ea53907952a028c3b3826c9c5776ba26d0ef65271845a31b9d5412d8b3b64927f16575dfca2765f1d2907694a1daf934e30b77db070460a9
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.2.4
2
+ - Support "Offer/getTierPayouts" method
3
+ - Support "Affiliate/getAffiliateTier" method
4
+
1
5
  # 0.2.3
2
6
  - Support "Offer/generateTrackingLink" method
3
7
  - Support "Affiliate/create" method
data/hasoffersv3.gemspec CHANGED
@@ -18,10 +18,9 @@ Gem::Specification.new do |s|
18
18
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
19
19
  s.require_paths = ["lib"]
20
20
 
21
- s.add_dependency 'oj' # for faster JSON parsing
22
21
  s.add_dependency 'activesupport' # for to_param method
23
22
  s.add_development_dependency 'webmock'
24
23
  s.add_development_dependency 'rspec', '~> 3.0.0'
25
- s.add_development_dependency "bundler", "~> 1.3"
26
- s.add_development_dependency "rake"
24
+ s.add_development_dependency 'bundler', '~> 1.3'
25
+ s.add_development_dependency 'rake'
27
26
  end
@@ -23,6 +23,11 @@ class HasOffersV3
23
23
  requires! params[:data], [:zipcode, :company]
24
24
  post_request 'create', params
25
25
  end
26
+
27
+ def get_tier(params = {})
28
+ requires! params, [:id]
29
+ post_request 'getAffiliateTier', params
30
+ end
26
31
  end
27
32
  end
28
33
  end
@@ -27,7 +27,7 @@ class HasOffersV3
27
27
  end
28
28
  http_response = execute_request(http, raw_request)
29
29
 
30
- Response.new(http_response)
30
+ Response.new(http_response, @configuration.json_driver)
31
31
  end
32
32
 
33
33
  def execute_request(net_http, raw_request)
@@ -1,13 +1,25 @@
1
1
  class HasOffersV3
2
2
  class Configuration
3
3
 
4
+ def self.default_json_driver
5
+ @_default_json_driver ||=
6
+ if defined?(Oj)
7
+ Oj
8
+ elsif defined?(MultiJson)
9
+ MultiJson
10
+ else
11
+ JSON
12
+ end
13
+ end
14
+
4
15
  DEFAULTS = {
5
16
  host: 'api.hasoffers.com',
6
17
  protocol: 'http',
7
18
  base_path: '/v3',
8
19
  network_id: '',
9
- api_key: ''
10
- }
20
+ api_key: '',
21
+ json_driver: self.default_json_driver
22
+ }.freeze
11
23
 
12
24
  DEFAULTS.keys.each do |option_name|
13
25
  define_method option_name do
@@ -25,7 +37,6 @@ class HasOffersV3
25
37
  defaults = DEFAULTS.dup
26
38
  @options = options.dup
27
39
 
28
-
29
40
  defaults.keys.each do |key|
30
41
  # Symbolize only keys that are needed
31
42
  @options[key] = @options[key.to_s] if @options.has_key?(key.to_s)
@@ -40,5 +51,6 @@ class HasOffersV3
40
51
  def base_uri
41
52
  "#{protocol}://#{host}#{base_path}"
42
53
  end
54
+
43
55
  end
44
56
  end
@@ -49,6 +49,11 @@ class HasOffersV3
49
49
  requires! params, [:offer_id, :affiliate_id]
50
50
  post_request 'generateTrackingLink', params
51
51
  end
52
+
53
+ def get_tier_payouts(params = {})
54
+ requires! params, [:id]
55
+ post_request 'getTierPayouts', params
56
+ end
52
57
  end
53
58
  end
54
59
  end
@@ -1,11 +1,9 @@
1
- require 'oj'
2
-
3
1
  class HasOffersV3
4
2
  class Response
5
3
  attr_reader :body, :http_status_code, :http_message, :http_headers
6
4
 
7
- def initialize(response)
8
- @body = Oj.load(response.body.to_s)
5
+ def initialize(response, json=default_json_driver)
6
+ @body = json.load(response.body.to_s)
9
7
  @http_status_code = response.code
10
8
  @http_message = response.message
11
9
  @http_headers = response.to_hash
@@ -59,14 +57,12 @@ class HasOffersV3
59
57
  end
60
58
  end
61
59
 
62
- protected
63
-
60
+ protected
64
61
  def paginated_response?
65
62
  @body['response']['data'] and @body['response']['data'].is_a?(Hash) and @body['response']['data'].has_key?('pageCount')
66
63
  end
67
64
 
68
- private
69
-
65
+ private
70
66
  def get_error_values(obj)
71
67
  if obj.is_a? Hash
72
68
  obj.values
@@ -74,5 +70,10 @@ class HasOffersV3
74
70
  obj.map { |error| error["err_msg"] || error["publicMessage"] }
75
71
  end
76
72
  end
73
+
74
+ def default_json_driver
75
+ @_default_json_driver ||= ::HasOffersV3::Configuration.default_json_driver
76
+ end
77
+
77
78
  end
78
79
  end
@@ -1,3 +1,3 @@
1
1
  class HasOffersV3
2
- VERSION = '0.2.3'
2
+ VERSION = '0.2.4'
3
3
  end
data/lib/hasoffersv3.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'net/http'
2
+ require 'json'
2
3
 
3
4
  require 'hasoffersv3/client'
4
5
 
@@ -69,4 +69,17 @@ describe HasOffersV3::Affiliate do
69
69
  end
70
70
  end
71
71
 
72
+ describe '.get_tier' do
73
+ it 'should make a proper request call' do
74
+ stub_call
75
+ response = subject.get_tier id: 1
76
+ expect(a_request(:post, url).with(body: hash_including({'Method' => 'getAffiliateTier','id' => '1'}))).to have_been_made
77
+ validate_call response
78
+ end
79
+
80
+ it 'should fail without id' do
81
+ expect { subject.get_tier }.to raise_error ArgumentError
82
+ end
83
+ end
84
+
72
85
  end
@@ -145,4 +145,17 @@ describe HasOffersV3::Offer do
145
145
  end
146
146
  end
147
147
  end
148
+
149
+ describe '.get_tier_payouts' do
150
+ it 'should make a proper request call' do
151
+ stub_call
152
+ response = subject.get_tier_payouts id: 1
153
+ expect(a_request(:post, url).with(body: hash_including({'Method' => 'getTierPayouts','id' => '1'}))).to have_been_made
154
+ validate_call response
155
+ end
156
+
157
+ it 'should fail without id' do
158
+ expect { subject.get_tier_payouts }.to raise_error ArgumentError
159
+ end
160
+ end
148
161
  end
data/spec/spec_helper.rb CHANGED
@@ -34,7 +34,7 @@ def body
34
34
  end
35
35
 
36
36
  def default_return
37
- { status: 200, body: Oj.dump(body) }
37
+ { status: 200, body: JSON.dump(body) }
38
38
  end
39
39
 
40
40
  def data
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hasoffersv3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maximilian Seifert
@@ -9,22 +9,8 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-03-13 00:00:00.000000000 Z
12
+ date: 2015-05-21 00:00:00.000000000 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: oj
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - ">="
19
- - !ruby/object:Gem::Version
20
- version: '0'
21
- type: :runtime
22
- prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- version: '0'
28
14
  - !ruby/object:Gem::Dependency
29
15
  name: activesupport
30
16
  requirement: !ruby/object:Gem::Requirement