soapy_bing 0.3.0 → 0.3.1

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: 050d78288c2a6684ef1755104627587ba44f6263
4
- data.tar.gz: 84eca8e11161bd4645d2d8ba35a7e42defdf281d
3
+ metadata.gz: 6769b40c74197462ce64b3858e1d9685a96a2afc
4
+ data.tar.gz: e7cd2d208675f7318e838318e9ba3f7598a95d2c
5
5
  SHA512:
6
- metadata.gz: b39872dacbc8cc83a41293ba31cbdbb98ddc22902093f361064b6218224e105c63a4f5e8baf7b86d3867dc10d6bd2dd9a4d5bce5e8a4c62428ab98a97287777a
7
- data.tar.gz: b45e9ef2c03f630a262ef99f67e6267deb3354fd082a601bddbabd111973a69788a81dd03a391342d953b8dc431e4997ccea03110f5adad8f3d3c5a31a4e52a0
6
+ metadata.gz: 9d9c735dccb584cc54a9de1a4827a481393f24a4ab7e086c0e3ac9770d9c0d272fbedda8d8da233e2fcb8a78132663be31a3c58be26c36e1ee5525dfb1e21990
7
+ data.tar.gz: 9c19239300bc2ee50a79a3c87cdb995d24a7e37b7e029c976cc735ce7683088faed872e76f383ba9397d76b46df3175a9fa36ef40ed696cd1d6347a82a9b6aec
@@ -4,15 +4,19 @@ module SoapyBing
4
4
  module Bulk
5
5
  class Campaigns
6
6
  DEFAULT_ENTITIES = %w(CampaignTargets Ads).freeze
7
- POLLING_TRIES = 30
7
+ DEFAULT_POLLING_SETTINGS = {
8
+ tries: 20,
9
+ sleep: ->(n) { n < 7 ? 2**n : 120 }
10
+ }.freeze
8
11
  NotCompleted = Class.new(StandardError)
9
12
 
10
- attr_reader :oauth_credentials, :account, :entities, :status
13
+ attr_reader :oauth_credentials, :account, :entities, :polling_settings, :status
11
14
 
12
15
  def initialize(options)
13
16
  @oauth_credentials = options.fetch(:oauth_credentials)
14
17
  @account = options.fetch(:account)
15
18
  @entities = options.fetch(:entities) || DEFAULT_ENTITIES
19
+ @polling_settings = DEFAULT_POLLING_SETTINGS.merge(options.fetch(:polling_settings) || {})
16
20
  end
17
21
 
18
22
  def rows
@@ -36,7 +40,7 @@ module SoapyBing
36
40
  private
37
41
 
38
42
  def wait_status_complete
39
- Retryable.retryable(tries: POLLING_TRIES, on: NotCompleted) do
43
+ Retryable.retryable(polling_settings.merge(on: NotCompleted)) do
40
44
  fetch_status
41
45
  raise NotCompleted if status['RequestStatus'] != 'Completed'
42
46
  end
@@ -21,11 +21,12 @@ module SoapyBing
21
21
  )
22
22
  end
23
23
 
24
- def bulk_campaigns(entities = nil)
24
+ def bulk_campaigns(entities = nil, polling_settings = {})
25
25
  Bulk::Campaigns.new(
26
26
  oauth_credentials: oauth_credentials,
27
27
  account: account,
28
- entities: entities
28
+ entities: entities,
29
+ polling_settings: polling_settings
29
30
  )
30
31
  end
31
32
 
@@ -3,7 +3,12 @@ module SoapyBing
3
3
  module Soap
4
4
  module Response
5
5
  class GetBulkDownloadStatusResponse < Base
6
+ StatusFailed = Class.new(StandardError)
7
+
6
8
  def extract_payload
9
+ if response['RequestStatus'] == 'Failed'
10
+ raise StatusFailed, response['Errors'].to_s
11
+ end
7
12
  response.slice('PercentComplete', 'RequestStatus', 'ResultFileUrl')
8
13
  end
9
14
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module SoapyBing
3
- VERSION = '0.3.0'
3
+ VERSION = '0.3.1'
4
4
  end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+ RSpec.describe SoapyBing::Soap::Response::GetBulkDownloadStatusResponse do
3
+ subject(:response) { described_class.new(response_hash) }
4
+
5
+ describe '#payload' do
6
+ context 'in progress status response' do
7
+ let(:response_hash) do
8
+ {
9
+ 'Envelope' => {
10
+ 'Body' => {
11
+ 'GetBulkDownloadStatusResponse' => {
12
+ 'Errors' => nil,
13
+ 'PercentComplete' => '42',
14
+ 'RequestStatus' => 'InProgress',
15
+ 'ResultFileUrl' => nil
16
+ }
17
+ }
18
+ }
19
+ }
20
+ end
21
+
22
+ it 'returns status and percent complete' do
23
+ expect(response.payload).to include(
24
+ 'PercentComplete' => '42',
25
+ 'RequestStatus' => 'InProgress',
26
+ 'ResultFileUrl' => nil
27
+ )
28
+ end
29
+ end
30
+
31
+ context 'failed status response' do
32
+ let(:response_hash) do
33
+ {
34
+ 'Envelope' => {
35
+ 'Body' => {
36
+ 'GetBulkDownloadStatusResponse' => {
37
+ 'Errors' => [
38
+ 'OperationError' => {
39
+ 'Code' => '0',
40
+ 'ErrorCode' => 'InternalError',
41
+ 'Message' => 'An internal error has occurred'
42
+ }
43
+ ],
44
+ 'PercentComplete' => '0',
45
+ 'RequestStatus' => 'Failed',
46
+ 'ResultFileUrl' => nil
47
+ }
48
+ }
49
+ }
50
+ }
51
+ end
52
+
53
+ it 'raises a StatusFailed exception with error message' do
54
+ expect { response.payload }.to raise_error(
55
+ described_class::StatusFailed, /An internal error has occurred/
56
+ )
57
+ end
58
+ end
59
+ end
60
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soapy_bing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ad2games GmbH
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-15 00:00:00.000000000 Z
11
+ date: 2016-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erubis
@@ -284,6 +284,7 @@ files:
284
284
  - spec/soapy_bing/soap/request/base_spec.rb
285
285
  - spec/soapy_bing/soap/request/poll_generate_report_request_spec.rb
286
286
  - spec/soapy_bing/soap/response/base_spec.rb
287
+ - spec/soapy_bing/soap/response/get_bulk_download_status_response_spec.rb
287
288
  - spec/soapy_bing/soap/response/payload_spec.rb
288
289
  - spec/soapy_bing/soap/response/poll_generate_report_response_spec.rb
289
290
  - spec/soapy_bing/soap/response/report_status_spec.rb
@@ -352,6 +353,7 @@ test_files:
352
353
  - spec/soapy_bing/soap/request/base_spec.rb
353
354
  - spec/soapy_bing/soap/request/poll_generate_report_request_spec.rb
354
355
  - spec/soapy_bing/soap/response/base_spec.rb
356
+ - spec/soapy_bing/soap/response/get_bulk_download_status_response_spec.rb
355
357
  - spec/soapy_bing/soap/response/payload_spec.rb
356
358
  - spec/soapy_bing/soap/response/poll_generate_report_response_spec.rb
357
359
  - spec/soapy_bing/soap/response/report_status_spec.rb