yieldmanager 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +22 -4
- data/VERSION +1 -1
- data/lib/yieldmanager/client.rb +13 -0
- data/spec/yieldmanager/client_spec.rb +25 -0
- data/yieldmanager.gemspec +2 -2
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -7,7 +7,7 @@ Currently it generates a fresh wsdl from the api.yieldmanager.com site the
|
|
7
7
|
first time you use a service (in the future it will use locally-cached
|
8
8
|
copies) and re-uses that wsdl for the life of the Yieldmanager::Client object.
|
9
9
|
|
10
|
-
|
10
|
+
=== Creating a Yieldmanager::Client
|
11
11
|
|
12
12
|
@ym = Yieldmanager::Client(
|
13
13
|
:user => "bob",
|
@@ -15,17 +15,35 @@ copies) and re-uses that wsdl for the life of the Yieldmanager::Client object.
|
|
15
15
|
:api_version => "1.30"
|
16
16
|
)
|
17
17
|
|
18
|
-
|
18
|
+
=== Finding available services
|
19
19
|
|
20
20
|
@ym.available_services
|
21
21
|
|
22
|
-
|
22
|
+
=== Using a service
|
23
23
|
|
24
24
|
@ym.session do |token|
|
25
25
|
currencies = @ym.dictionary.getCurrencies(token)
|
26
26
|
end
|
27
|
+
|
28
|
+
=== Pagination
|
27
29
|
|
28
|
-
|
30
|
+
Some calls return datasets too large to retrieve all at once.
|
31
|
+
Pagination allows you to pull them back incrementally, handling
|
32
|
+
the partial dataset on-the-fly or accumulating it for later use.
|
33
|
+
|
34
|
+
BLOCK_SIZE = 50
|
35
|
+
id = 1
|
36
|
+
@ym.session do |token|
|
37
|
+
@ym.paginate(BLOCK_SIZE) do |block|
|
38
|
+
(lines,tot) = line_item_service.getByBuyer(token,id,BLOCK_SIZE,block)
|
39
|
+
# ...do something with lines...
|
40
|
+
|
41
|
+
# remember to return total!
|
42
|
+
tot
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
=== session vs. start_session/end_session
|
29
47
|
|
30
48
|
The +session+ method opens a session, gives you a token to use in your service
|
31
49
|
calls, then closes the session when the block ends, even if an exception is
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/yieldmanager/client.rb
CHANGED
@@ -79,6 +79,19 @@ module Yieldmanager
|
|
79
79
|
end_session token
|
80
80
|
end
|
81
81
|
end
|
82
|
+
|
83
|
+
# Allows looping over datasets too large to pull back in one call
|
84
|
+
#
|
85
|
+
# Block must return total rows in dataset to know when to stop!
|
86
|
+
def paginate block_size
|
87
|
+
page = 1
|
88
|
+
total = block_size + 1
|
89
|
+
|
90
|
+
begin
|
91
|
+
total = yield page # Need total back from block to know when to stop!
|
92
|
+
page += 1
|
93
|
+
end until (block_size * (page-1)) > total
|
94
|
+
end
|
82
95
|
|
83
96
|
private
|
84
97
|
|
@@ -72,6 +72,31 @@ describe "A new Yieldmanager client" do
|
|
72
72
|
lambda { @ym.dictionary.getCurrencies(my_token) }.should raise_error(SOAP::FaultError)
|
73
73
|
end
|
74
74
|
|
75
|
+
it "paginates" do
|
76
|
+
BLOCK_SIZE = 50
|
77
|
+
id = -1
|
78
|
+
@ym.session do |token|
|
79
|
+
line_item_service = @ym.line_item
|
80
|
+
[
|
81
|
+
{:calls_expected => 2, :dataset_size => 75},
|
82
|
+
{:calls_expected => 1, :dataset_size => 25},
|
83
|
+
{:calls_expected => 1, :dataset_size => 0}
|
84
|
+
].each do |args|
|
85
|
+
line_item_service.
|
86
|
+
should_receive(:getByBuyer).
|
87
|
+
exactly(args[:calls_expected]).times.
|
88
|
+
and_return([[],args[:dataset_size]])
|
89
|
+
@ym.paginate(BLOCK_SIZE) do |block|
|
90
|
+
(lines,tot) = line_item_service.
|
91
|
+
getByBuyer(token,id,BLOCK_SIZE,block)
|
92
|
+
# must return total rows in dataset
|
93
|
+
# so paginate knows when to stop!
|
94
|
+
tot
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
75
100
|
def login_args
|
76
101
|
unless ENV["YIELDMANAGER_USER"] &&
|
77
102
|
ENV["YIELDMANAGER_PASS"] &&
|
data/yieldmanager.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{yieldmanager}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Bill Gathen"]
|
12
|
-
s.date = %q{2009-11-
|
12
|
+
s.date = %q{2009-11-18}
|
13
13
|
s.description = %q{This gem offers full access to YieldManager's API tools (read/write) as well as ad-hoc reporting through the Reportware tool}
|
14
14
|
s.email = %q{bill@billgathen.com}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yieldmanager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bill Gathen
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-18 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|