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 +4 -4
- data/CHANGELOG.md +4 -0
- data/hasoffersv3.gemspec +2 -3
- data/lib/hasoffersv3/affiliate.rb +5 -0
- data/lib/hasoffersv3/client.rb +1 -1
- data/lib/hasoffersv3/configuration.rb +15 -3
- data/lib/hasoffersv3/offer.rb +5 -0
- data/lib/hasoffersv3/response.rb +9 -8
- data/lib/hasoffersv3/version.rb +1 -1
- data/lib/hasoffersv3.rb +1 -0
- data/spec/lib/affiliate_spec.rb +13 -0
- data/spec/lib/offer_spec.rb +13 -0
- data/spec/spec_helper.rb +1 -1
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 667f1f3af61d4c3eb35c8ca1eebdaa767b9fd0bb
|
4
|
+
data.tar.gz: 405df6a514919f645e3529a479fd704d8ff54203
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9919ca8819a7b8272242d91bac0f0c0444cde8f320da829883e4ee8f185a67305e923dd0656f63032b6a6d33ade94784efa5f5129e0812c04efda6a18b2af3f9
|
7
|
+
data.tar.gz: 41e1bd782835fd46ea53907952a028c3b3826c9c5776ba26d0ef65271845a31b9d5412d8b3b64927f16575dfca2765f1d2907694a1daf934e30b77db070460a9
|
data/CHANGELOG.md
CHANGED
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
|
26
|
-
s.add_development_dependency
|
24
|
+
s.add_development_dependency 'bundler', '~> 1.3'
|
25
|
+
s.add_development_dependency 'rake'
|
27
26
|
end
|
data/lib/hasoffersv3/client.rb
CHANGED
@@ -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
|
data/lib/hasoffersv3/offer.rb
CHANGED
@@ -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
|
data/lib/hasoffersv3/response.rb
CHANGED
@@ -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 =
|
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
|
-
|
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
|
-
|
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
|
data/lib/hasoffersv3/version.rb
CHANGED
data/lib/hasoffersv3.rb
CHANGED
data/spec/lib/affiliate_spec.rb
CHANGED
@@ -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
|
data/spec/lib/offer_spec.rb
CHANGED
@@ -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
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.
|
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-
|
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
|