hasoffersv3 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,24 +1,20 @@
1
- require 'spec_helper'
2
-
3
1
  describe HasOffersV3::Affiliate do
4
- subject { HasOffersV3::Affiliate.new }
5
-
6
2
  let(:url) { api_url 'Affiliate' }
7
3
 
8
4
  before(:each) do |example|
9
5
  stub_call unless example.metadata[:no_stub]
10
6
  end
11
7
 
12
- describe '.find_all' do
13
- it 'should make a proper request call' do
8
+ describe '#find_all' do
9
+ it 'makes a proper request call' do
14
10
  response = subject.find_all
15
11
  expect(a_request(:post, url).with(body: hash_including({'Method' => 'findAll'}))).to have_been_made
16
12
  validate_call response
17
13
  end
18
14
  end
19
15
 
20
- describe '.find_by_id', :no_stub do
21
- it 'should make a proper request call' do
16
+ describe '#find_by_id', :no_stub do
17
+ it 'makes a proper request call' do
22
18
  stub_call :get, nil, Regexp.new(url)
23
19
  response = subject.find_by_id id: 1
24
20
  expect(a_request(:get, url).with(query: hash_including({'Method' => 'findById', 'id' => '1'}))).to have_been_made
@@ -26,42 +22,42 @@ describe HasOffersV3::Affiliate do
26
22
  end
27
23
 
28
24
  context 'when there is no id' do
29
- it 'should raise exception' do
25
+ it 'raises exception' do
30
26
  expect { subject.find_by_id failed_id: 1 }.to raise_error ArgumentError
31
27
  end
32
28
  end
33
29
  end
34
30
 
35
- describe '.update_payment_method_wire' do
36
- it 'should make a proper request call' do
31
+ describe '#update_payment_method_wire' do
32
+ it 'makes a proper request call' do
37
33
  response = subject.update_payment_method_wire
38
34
  expect(a_request(:post, url).with(body: hash_including({'Method' => 'updatePaymentMethodWire'}))).to have_been_made
39
35
  validate_call response
40
36
  end
41
37
  end
42
38
 
43
- describe '.update_payment_method_paypal' do
44
- it 'should make a proper request call' do
39
+ describe '#update_payment_method_paypal' do
40
+ it 'makes a proper request call' do
45
41
  response = subject.update_payment_method_paypal
46
42
  expect(a_request(:post, url).with(body: hash_including({'Method' => 'updatePaymentMethodPaypal'}))).to have_been_made
47
43
  validate_call response
48
44
  end
49
45
  end
50
46
 
51
- describe 'create' do
47
+ describe '#create' do
52
48
  context 'when required params are missing' do
53
- it 'should fail without data' do
49
+ it 'fails without data' do
54
50
  expect { subject.create }.to raise_error ArgumentError
55
51
  end
56
- it 'should fail without data["company"]' do
52
+ it 'fails without data["company"]' do
57
53
  expect { subject.create data: { zipcode: 1234567 }}.to raise_error ArgumentError
58
54
  end
59
- it 'should fail without data["zipcode"]' do
55
+ it 'fails without data["zipcode"]' do
60
56
  expect { subject.create data: { company: 'xyz@applift.com' }}.to raise_error ArgumentError
61
57
  end
62
58
  end
63
59
 
64
- it 'should make a successful request call' do
60
+ it 'makes a successful request call' do
65
61
  response = subject.create data: { company: "xyz@gmail.com", zipcode: "10178" }
66
62
  expect(a_request(:post, url).with(body: hash_including({'Method' => 'create', 'data' => {'company' => 'xyz@gmail.com',
67
63
  'zipcode' => '10178'}}))).to have_been_made
@@ -69,15 +65,15 @@ describe HasOffersV3::Affiliate do
69
65
  end
70
66
  end
71
67
 
72
- describe '.get_tier' do
73
- it 'should make a proper request call' do
68
+ describe '#get_tier' do
69
+ it 'makes a proper request call' do
74
70
  stub_call
75
71
  response = subject.get_tier id: 1
76
72
  expect(a_request(:post, url).with(body: hash_including({'Method' => 'getAffiliateTier','id' => '1'}))).to have_been_made
77
73
  validate_call response
78
74
  end
79
75
 
80
- it 'should fail without id' do
76
+ it 'fails without id' do
81
77
  expect { subject.get_tier }.to raise_error ArgumentError
82
78
  end
83
79
  end
@@ -1,11 +1,8 @@
1
- require 'spec_helper'
2
-
3
1
  describe HasOffersV3::Application do
4
2
  let(:url) { Regexp.new api_url('Application') }
5
-
6
- describe '.get_payout_tiers' do
7
- subject { HasOffersV3::Application }
8
- it 'should make a proper request call' do
3
+
4
+ describe '#get_payout_tiers' do
5
+ it 'makes a proper request call' do
9
6
  stub_call :get
10
7
  response = subject.get_payout_tiers
11
8
  expect(a_request(:get, url).with(query: hash_including({'Method' => 'findAllAffiliateTiers'}))).to have_been_made
@@ -1,18 +1,14 @@
1
- require 'spec_helper'
2
-
3
1
  describe HasOffersV3::Base do
4
- subject { HasOffersV3::Base }
5
-
6
2
  let(:url) { Regexp.new api_url('Base') }
7
3
 
8
- describe :requires! do
9
- it 'raise ArgumentError is parameters are missing' do
4
+ describe "#requires!" do
5
+ it 'raises ArgumentError is parameters are missing' do
10
6
  expect { subject.requires!({}, [:dummy]) }.to raise_error(ArgumentError)
11
7
  end
12
8
  end
13
9
 
14
- describe ".get_request" do
15
- it "should make a proper request" do
10
+ describe "#get_request" do
11
+ it "makes a proper request" do
16
12
  stub_call :get
17
13
  response = subject.get_request 'test'
18
14
  request = a_request(:get, url).with(query: hash_including('Method' => 'test'))
@@ -31,7 +27,7 @@ describe HasOffersV3::Base do
31
27
  HasOffersV3.configuration.protocol = @old_protocol
32
28
  end
33
29
 
34
- it "should make a proper request" do
30
+ it "makes a proper request" do
35
31
  stub_call :get
36
32
  response = subject.get_request 'test'
37
33
  expect(a_request(:get, url).with(query: hash_including('Method' => 'test'))).to have_been_made
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe HasOffersV3::Client do
4
2
 
5
3
  describe '#base_uri' do
@@ -11,7 +9,7 @@ describe HasOffersV3::Client do
11
9
  result
12
10
  }
13
11
 
14
- it 'should be different configs' do
12
+ it 'has different configs' do
15
13
  default_connection = HasOffersV3::Client.new(configuration_to_default_host)
16
14
  expect(default_connection.base_uri).to eq('https://api.hasoffers.com/v3')
17
15
 
@@ -0,0 +1,44 @@
1
+ describe HasOffersV3::Configuration do
2
+ describe '#http_logger' do
3
+ it 'returns an instance of HasOffersV3::Logger' do
4
+ expect(subject.http_logger).to be_instance_of(HasOffersV3::Logger)
5
+ end
6
+
7
+ context 'when logger is default' do
8
+ it 'uses null HTTP logger' do
9
+ expect(subject.http_logger.log).to be_nil
10
+ end
11
+ end
12
+
13
+ context 'when logger is supplied' do
14
+ let(:logger) { double('logger') }
15
+ subject { described_class.new(logger: logger) }
16
+
17
+ it 'uses supplied logger' do
18
+ expect(subject.http_logger.log).to eq logger
19
+ end
20
+ end
21
+ end
22
+
23
+ describe '#base_uri' do
24
+ context 'when configuration is default' do
25
+ it 'builds default base URI' do
26
+ expect(subject.base_uri).to eq 'https://api.hasoffers.com/v3'
27
+ end
28
+ end
29
+
30
+ context 'when configuration is customized' do
31
+ subject do
32
+ described_class.new(
33
+ host: 'api2.hasoffers.com',
34
+ protocol: 'http',
35
+ base_path: '/v4'
36
+ )
37
+ end
38
+
39
+ it 'builds base URI according options' do
40
+ expect(subject.base_uri).to eq 'http://api2.hasoffers.com/v4'
41
+ end
42
+ end
43
+ end
44
+ end
@@ -1,48 +1,31 @@
1
- require 'spec_helper'
2
-
3
1
  describe HasOffersV3::Conversion do
4
- subject { HasOffersV3::Conversion.new }
5
-
6
2
  let(:url) { Regexp.new api_url('Conversion') }
7
3
 
8
4
  before :each do
9
5
  stub_call :get
10
6
  end
11
7
 
12
- describe '.find_all' do
13
- it 'should make a proper request call' do
8
+ describe '#find_all' do
9
+ it 'makes a proper request call' do
14
10
  response = subject.find_all
15
11
  expect(a_request(:get, url).with(query: hash_including({'Method' => 'findAll'}))).to have_been_made
16
12
  validate_call response
17
13
  end
18
14
  end
19
15
 
20
- describe '.find_added_conversions' do
21
- it 'should make a proper request call' do
16
+ describe '#find_added_conversions' do
17
+ it 'makes a proper request call' do
22
18
  response = subject.find_added_conversions
23
19
  expect(a_request(:get, url).with(query: hash_including({'Method' => 'findAddedConversions'}))).to have_been_made
24
20
  validate_call response
25
21
  end
26
22
  end
27
23
 
28
- describe '.find_updated_conversions' do
29
- it 'should make a proper request call' do
24
+ describe '#find_updated_conversions' do
25
+ it 'makes a proper request call' do
30
26
  response = subject.find_updated_conversions
31
27
  expect(a_request(:get, url).with(query: hash_including({'Method' => 'findUpdatedConversions'}))).to have_been_made
32
28
  validate_call response
33
29
  end
34
30
  end
35
-
36
- describe '.findAll' do
37
- it 'should make a proper request call' do
38
- response = subject.find_all
39
- expect(a_request(:get, url).with(query: hash_including({'Method' => 'findAll'}))).to have_been_made
40
- validate_call response
41
- end
42
-
43
- it 'should call find_all method' do
44
- expect(subject).to receive(:find_all).with({test: 1})
45
- subject.find_all test: 1
46
- end
47
- end
48
31
  end
@@ -1,45 +1,41 @@
1
- require 'spec_helper'
2
-
3
1
  describe HasOffersV3::Employee do
4
- subject { HasOffersV3::Employee.new }
5
-
6
2
  let(:url) { api_url 'Employee' }
7
3
 
8
4
  before(:each) do |example|
9
5
  stub_call unless example.metadata[:no_stub]
10
6
  end
11
7
 
12
- describe '.find_all' do
13
- it 'should make a proper request call' do
8
+ describe '#find_all' do
9
+ it 'makes a proper request call' do
14
10
  response = subject.find_all
15
11
  expect(a_request(:post, url).with(body: hash_including({'Method' => 'findAll'}))).to have_been_made
16
12
  validate_call response
17
13
  end
18
14
  end
19
15
 
20
- describe '.find_all_by_ids' do
21
- it 'should make a proper request call' do
16
+ describe '#find_all_by_ids' do
17
+ it 'makes a proper request call' do
22
18
  response = subject.find_all_by_ids ids: [1]
23
19
  expect(a_request(:post, url).with(body: hash_including({'Method' => 'findAllByIds'}))).to have_been_made
24
20
  validate_call response
25
21
  end
26
22
 
27
23
  context 'when there is no id' do
28
- it 'should raise exception' do
24
+ it 'raises exception' do
29
25
  expect { subject.find_all_by_ids }.to raise_error ArgumentError
30
26
  end
31
27
  end
32
28
  end
33
29
 
34
- describe '.find_by_id' do
35
- it 'should make a proper request call' do
30
+ describe '#find_by_id' do
31
+ it 'makes a proper request call' do
36
32
  response = subject.find_by_id id: 1
37
33
  expect(a_request(:post, url).with(body: hash_including({'Method' => 'findById', 'id' => '1'}))).to have_been_made
38
34
  validate_call response
39
35
  end
40
36
 
41
37
  context 'when there is no id' do
42
- it 'should raise exception' do
38
+ it 'raises exception' do
43
39
  expect { subject.find_by_id }.to raise_error ArgumentError
44
40
  end
45
41
  end
@@ -1,21 +1,18 @@
1
- require 'spec_helper'
2
-
3
1
  describe HasOffersV3 do
4
2
 
5
3
  context 'singleton' do
6
- it 'should use default config' do
4
+ it 'uses default config' do
7
5
  subject = HasOffersV3::Offer.client.configuration
8
6
  expect(subject).to eq(HasOffersV3.configuration)
9
7
  end
10
8
  end
11
9
 
12
10
  describe '#configuration' do
13
- it 'should create different connections' do
14
- subject = HasOffersV3.new
11
+ it 'creates different connections' do
15
12
  expect(subject.configuration).to_not eq(HasOffersV3.configuration)
16
13
  end
17
14
 
18
- it 'should use params instead of default' do
15
+ it 'uses params instead of default' do
19
16
  subject = HasOffersV3.new(host: 'example.com')
20
17
  expect(subject.configuration.host).to eq('example.com')
21
18
  expect(subject.configuration.host).to_not eq(HasOffersV3::Configuration::DEFAULTS[:host])
@@ -23,10 +20,8 @@ describe HasOffersV3 do
23
20
  end
24
21
 
25
22
  context 'api' do
26
- subject { HasOffersV3.new }
27
-
28
23
  describe '#offers' do
29
- it 'should get offers for current connection' do
24
+ it 'gets offers for current connection' do
30
25
  offer = double('HasOffersV3::Offer')
31
26
  expect(HasOffersV3::Offer).to receive(:new).and_return(offer)
32
27
  expect(offer).to receive(:find_all)
@@ -0,0 +1,47 @@
1
+ describe HasOffersV3::Logger do
2
+ let(:log) { double('log') }
3
+ subject { described_class.new(log) }
4
+
5
+ describe '.new' do
6
+ it 'initializes properly' do
7
+ expect(subject.log).to eql log
8
+ end
9
+ end
10
+
11
+ describe '#log_request' do
12
+ let(:request) do
13
+ double('request',
14
+ method: 'POST',
15
+ each_capitalized: { 'Header' => 'value' },
16
+ body: 'Var1=value1&Var2=value2'
17
+ )
18
+ end
19
+ let(:uri) { double('uri', to_s: 'http://api.applift.com/path') }
20
+
21
+ it 'logs HTTP request' do
22
+ expected_message = "[HasOffersV3] Request: POST http://api.applift.com/path\nHeader: value\n\nVar1=value1&Var2=value2\n"
23
+ expect(log).to receive(:info).with(expected_message)
24
+
25
+ subject.log_request(request, uri)
26
+ end
27
+ end
28
+
29
+ describe '#log_response' do
30
+ let(:response) do
31
+ double('response',
32
+ http_version: '1.1',
33
+ code: 200,
34
+ message: 'OK',
35
+ each_capitalized: { 'Header' => 'value' },
36
+ body: 'Body of this response'
37
+ )
38
+ end
39
+
40
+ it 'logs HTTP response' do
41
+ expected_message = "[HasOffersV3] Response: HTTP/1.1 200 OK\nHeader: value\n\nBody of this response\n"
42
+ expect(log).to receive(:info).with(expected_message)
43
+
44
+ subject.log_response(response)
45
+ end
46
+ end
47
+ end
@@ -1,26 +1,22 @@
1
- require 'spec_helper'
2
-
3
1
  describe HasOffersV3::OfferPixel do
4
- subject { HasOffersV3::OfferPixel.new }
5
-
6
2
  let(:url) { api_url 'OfferPixel' }
7
3
 
8
- describe '.find_all' do
9
- it 'should make a proper request call' do
4
+ describe '#find_all' do
5
+ it 'makes a proper request call' do
10
6
  stub_call
11
7
  response = subject.find_all
12
8
  expect(a_request(:post, url).with(body: hash_including({'Method' => 'findAll'}))).to have_been_made
13
9
  validate_call response
14
10
  end
15
11
 
16
- it 'should contain filters by type and modified' do
12
+ it 'contains filters by type and modified' do
17
13
  stub_call
18
14
  response = subject.find_all(filters: {type: 'url', modified: {'GREATER_THAN' => '2015-01-01+00:00'}})
19
15
  expect(a_request(:post, url).with(body: hash_including({'Method' => 'findAll', filters: { type: 'url', modified: {'GREATER_THAN' => '2015-01-01+00:00'} }}))).to have_been_made
20
16
  validate_call response
21
17
  end
22
18
 
23
- it 'should sort by modified' do
19
+ it 'sorts by modified' do
24
20
  stub_call
25
21
  response = subject.find_all(sort: {modified: 'asc'})
26
22
  expect(a_request(:post, url).with(body: hash_including({'Method' => 'findAll', sort: {modified: 'asc'}}))).to have_been_made
@@ -28,8 +24,8 @@ describe HasOffersV3::OfferPixel do
28
24
  end
29
25
  end
30
26
 
31
- describe '.find_all_by_ids' do
32
- it 'should make a proper request call' do
27
+ describe '#find_all_by_ids' do
28
+ it 'makes a proper request call' do
33
29
  stub_call
34
30
  response = subject.find_all_by_ids ids: [1]
35
31
  expect(a_request(:post, url).with(body: hash_including({'Method' => 'findAllByIds'}))).to have_been_made
@@ -37,14 +33,14 @@ describe HasOffersV3::OfferPixel do
37
33
  end
38
34
 
39
35
  context 'when there is no id' do
40
- it 'should raise exception' do
36
+ it 'raises exception' do
41
37
  expect { subject.find_all_by_ids }.to raise_error ArgumentError
42
38
  end
43
39
  end
44
40
  end
45
41
 
46
- describe '.find_by_id' do
47
- it 'should make a proper request call' do
42
+ describe '#find_by_id' do
43
+ it 'makes a proper request call' do
48
44
  stub_call
49
45
  response = subject.find_by_id id: [1]
50
46
  expect(a_request(:post, url).with(body: hash_including({'Method' => 'findById'}))).to have_been_made
@@ -52,14 +48,14 @@ describe HasOffersV3::OfferPixel do
52
48
  end
53
49
 
54
50
  context 'when there is no id' do
55
- it 'should raise exception' do
51
+ it 'raises exception' do
56
52
  expect { subject.find_by_id }.to raise_error ArgumentError
57
53
  end
58
54
  end
59
55
  end
60
56
 
61
- describe '.get_allowed_types' do
62
- it 'should make a proper request call' do
57
+ describe '#get_allowed_types' do
58
+ it 'makes a proper request call' do
63
59
  stub_call
64
60
  response = subject.get_allowed_types offer_id: [1]
65
61
  expect(a_request(:post, url).with(body: hash_including({'Method' => 'getAllowedTypes'}))).to have_been_made
@@ -67,7 +63,7 @@ describe HasOffersV3::OfferPixel do
67
63
  end
68
64
 
69
65
  context 'when there is no offer_id' do
70
- it 'should raise exception' do
66
+ it 'raises exception' do
71
67
  expect { subject.get_allowed_types }.to raise_error ArgumentError
72
68
  end
73
69
  end