soapy_cake 1.10.2 → 1.11.0

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: 4a4c20b31ac88064c0be92df9692c52443ab71f6
4
- data.tar.gz: 72be4e6a52cb622aaecd7b00efdac4a19db2347c
3
+ metadata.gz: 0f638bcf63e5c298c8106c4c71bacdbe8acd6927
4
+ data.tar.gz: 264608b47a9493bc9d3251339a6ceaf1d303495c
5
5
  SHA512:
6
- metadata.gz: f29ac1697cef49f1524eeecfde5dabf01cdd6e2f04f328238e91811a2d73239294cd36137d9db4e8bdd21c9dd6a41da2ec1e968334871b6aaf27e6f364507580
7
- data.tar.gz: a198049cfd0655e25a277d88bffed80e4766648c5011ca71be3fb14a4bad14845bcaad6918d90ffa27c10b845792a673138683a351ba8d48595fa60c9aab678b
6
+ metadata.gz: d66e47f6285e02f0e2adde97ee5834d440cb4d67a9f10cd1c36325d73bdacdf2393fa2a29a56e0d4e8ba45af782871467b027f63168051885b7abee9aae02ce3
7
+ data.tar.gz: aa0d393e775190a19e457406bef37d4b6fd8fe05d41ddc4ab56f767de084f38a1b91c253cd17043bd0a70365f2b3ddde6537c5c82cc9de2a61fc77ef1239ef5b
@@ -0,0 +1,56 @@
1
+ module SoapyCake
2
+ class AdminBatched
3
+ class BatchedRequest
4
+ # Both 0 and 1 return the first element. We need to set it to 1,
5
+ # otherwise we get an overlap in the next call. This is not documented in the API spec.
6
+ INITIAL_OFFSET = 1
7
+
8
+ # This value depends on the entity size.
9
+ # When all offers have a lot of info (e.g. geotargeting) we probably need to decrease this.
10
+ LIMIT = 500
11
+
12
+ def initialize(admin, method, opts)
13
+ if opts.key?(:row_limit) || opts.key?(:start_at_row)
14
+ fail Error, 'Cannot set row_limit/start_at_row in batched mode!'
15
+ end
16
+
17
+ @admin = admin
18
+ @method = method
19
+ @opts = opts
20
+ @offset = INITIAL_OFFSET
21
+ @finished = false
22
+ end
23
+
24
+ def to_enum
25
+ Enumerator.new do |y|
26
+ next_batch.each { |row| y << row } until finished
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ attr_reader :admin, :method, :opts, :finished, :offset
33
+
34
+ def next_batch
35
+ result = admin.public_send(method, opts.merge(row_limit: LIMIT, start_at_row: offset))
36
+ @finished = true if result.count < LIMIT
37
+ @offset += LIMIT
38
+ result
39
+ end
40
+ end
41
+
42
+ ALLOWED_METHODS = %i(advertisers affiliates campaigns offers creatives)
43
+
44
+ def method_missing(name, opts = {})
45
+ fail Error, "Invalid method #{name}" unless ALLOWED_METHODS.include?(name)
46
+
47
+ BatchedRequest.new(admin, name, opts).to_enum
48
+ end
49
+
50
+ private
51
+
52
+ def admin
53
+ @admin ||= Admin.new
54
+ end
55
+ end
56
+ end
@@ -20,7 +20,7 @@ module SoapyCake
20
20
 
21
21
  response = Response.new(http_response(request), request.short_response?)
22
22
  response.time_offset = time_offset
23
- response.collection
23
+ response.to_enum
24
24
  end
25
25
 
26
26
  private
@@ -10,13 +10,15 @@ module SoapyCake
10
10
  @short_response = short_response
11
11
  end
12
12
 
13
- def collection
13
+ def to_enum
14
14
  check_errors!
15
15
 
16
16
  return typed_element(sax.at_depth(3).first) if short_response
17
17
 
18
- sax.at_depth(5).map do |element|
19
- typed_element(element)
18
+ Enumerator.new do |y|
19
+ sax.at_depth(5).each do |element|
20
+ y << typed_element(element)
21
+ end
20
22
  end
21
23
  end
22
24
 
@@ -1,3 +1,3 @@
1
1
  module SoapyCake
2
- VERSION = '1.10.2'
2
+ VERSION = '1.11.0'
3
3
  end
data/lib/soapy_cake.rb CHANGED
@@ -15,6 +15,7 @@ require 'soapy_cake/response'
15
15
  require 'soapy_cake/response_value'
16
16
  require 'soapy_cake/client'
17
17
  require 'soapy_cake/admin'
18
+ require 'soapy_cake/admin_batched'
18
19
  require 'soapy_cake/admin_addedit'
19
20
  require 'soapy_cake/admin_track'
20
21
  require 'soapy_cake/affiliate'
@@ -0,0 +1,35 @@
1
+ RSpec.describe SoapyCake::AdminBatched do
2
+ let(:admin) { double('admin') }
3
+
4
+ before :each do
5
+ allow(SoapyCake::Admin).to receive(:new).and_return(admin)
6
+
7
+ stub_const('SoapyCake::AdminBatched::BatchedRequest::LIMIT', 2)
8
+ end
9
+
10
+ it 'returns an enumerator and uses batched CAKE calls' do
11
+ expect(admin).to receive(:offers)
12
+ .with(advertiser: 1, start_at_row: 1, row_limit: 2).and_return(%i(a b))
13
+ expect(admin).to receive(:offers)
14
+ .with(advertiser: 1, start_at_row: 3, row_limit: 2).and_return(%i(c))
15
+
16
+ result = subject.offers(advertiser: 1)
17
+
18
+ expect(result).to be_a(Enumerator)
19
+ expect(result.to_a).to eq(%i(a b c))
20
+ end
21
+
22
+ context 'errors' do
23
+ it 'fails with an invalid method' do
24
+ expect { subject.clicks }.to raise_error(/Invalid method clicks/)
25
+ end
26
+
27
+ it 'fails when row_limit is set' do
28
+ expect { subject.offers(row_limit: 123) }.to raise_error(/Cannot set .* in batched mode/)
29
+ end
30
+
31
+ it 'fails when start_at_row is set' do
32
+ expect { subject.offers(start_at_row: 123) }.to raise_error(/Cannot set .* in batched mode/)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,38 @@
1
+ RSpec.describe SoapyCake::Response do
2
+ let(:xml) do
3
+ <<-EOD
4
+ <?xml version="1.0" encoding="utf-8"?>
5
+ <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
6
+ <soap:Body>
7
+ <SomeResponse>
8
+ <SomeResult>
9
+ <success>true</success>
10
+ <row_count>2</row_count>
11
+ <somes>
12
+ <some>
13
+ <id>123</id>
14
+ </some>
15
+ <some>
16
+ <id>312</id>
17
+ </some>
18
+ </somes>
19
+ </SomeResult>
20
+ </SomeResponse>
21
+ </soap:Body>
22
+ </soap:Envelope>
23
+ EOD
24
+ end
25
+
26
+ subject { described_class.new(xml.strip, false) }
27
+
28
+ it 'returns an enumerator' do
29
+ expect(subject.to_enum).to be_a(Enumerator)
30
+ end
31
+
32
+ it 'parses the CAKE XML structure properly' do
33
+ expect(subject.to_enum.to_a).to eq([
34
+ { id: '123' },
35
+ { id: '312' }
36
+ ])
37
+ end
38
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soapy_cake
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.10.2
4
+ version: 1.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ad2games GmbH
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-16 00:00:00.000000000 Z
11
+ date: 2015-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -183,6 +183,7 @@ files:
183
183
  - lib/soapy_cake.rb
184
184
  - lib/soapy_cake/admin.rb
185
185
  - lib/soapy_cake/admin_addedit.rb
186
+ - lib/soapy_cake/admin_batched.rb
186
187
  - lib/soapy_cake/admin_track.rb
187
188
  - lib/soapy_cake/affiliate.rb
188
189
  - lib/soapy_cake/client.rb
@@ -216,10 +217,12 @@ files:
216
217
  - spec/integration/soapy_cake/admin_spec.rb
217
218
  - spec/integration/soapy_cake/admin_track_spec.rb
218
219
  - spec/lib/soapy_cake/admin_addedit_spec.rb
220
+ - spec/lib/soapy_cake/admin_batched_spec.rb
219
221
  - spec/lib/soapy_cake/admin_spec.rb
220
222
  - spec/lib/soapy_cake/admin_track_spec.rb
221
223
  - spec/lib/soapy_cake/affiliate_spec.rb
222
224
  - spec/lib/soapy_cake/request_spec.rb
225
+ - spec/lib/soapy_cake/response_spec.rb
223
226
  - spec/lib/soapy_cake/response_value_spec.rb
224
227
  - spec/spec_helper.rb
225
228
  - spec/support/admin_method_example.rb
@@ -270,10 +273,12 @@ test_files:
270
273
  - spec/integration/soapy_cake/admin_spec.rb
271
274
  - spec/integration/soapy_cake/admin_track_spec.rb
272
275
  - spec/lib/soapy_cake/admin_addedit_spec.rb
276
+ - spec/lib/soapy_cake/admin_batched_spec.rb
273
277
  - spec/lib/soapy_cake/admin_spec.rb
274
278
  - spec/lib/soapy_cake/admin_track_spec.rb
275
279
  - spec/lib/soapy_cake/affiliate_spec.rb
276
280
  - spec/lib/soapy_cake/request_spec.rb
281
+ - spec/lib/soapy_cake/response_spec.rb
277
282
  - spec/lib/soapy_cake/response_value_spec.rb
278
283
  - spec/spec_helper.rb
279
284
  - spec/support/admin_method_example.rb