yieldmanager 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +10 -3
- data/TODO +1 -1
- data/VERSION +1 -1
- data/lib/yieldmanager/report.rb +25 -10
- data/spec/reports/sample_report.xml +20 -0
- data/spec/yieldmanager/report_spec.rb +11 -4
- data/yieldmanager.gemspec +3 -2
- metadata +3 -2
data/README.rdoc
CHANGED
@@ -60,8 +60,8 @@ the partial dataset on-the-fly or accumulating it for later use.
|
|
60
60
|
|
61
61
|
=== Pulling reports
|
62
62
|
|
63
|
-
Accessing reportware assumes you've used the "Get
|
64
|
-
functionality in the UI to get your request XML
|
63
|
+
Accessing reportware assumes you've used the "Get request XML"
|
64
|
+
functionality in the UI to get your request XML, or have
|
65
65
|
crafted one from scratch. Assuming it's in a variable called
|
66
66
|
*request_xml*, you'd access the data this way:
|
67
67
|
|
@@ -73,12 +73,19 @@ crafted one from scratch. Assuming it's in a variable called
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
+
Column data can be accessed either by index or column name:
|
77
|
+
|
78
|
+
report.headers # => ['advertiser_name','seller_imps']
|
79
|
+
report.data[0][0] # => "Bob's Ads"
|
80
|
+
report.data[0].by_name('advertiser_name') # => "Bob's Ads"
|
81
|
+
report.data[0].by_name(:advertiser_name) # => "Bob's Ads"
|
82
|
+
|
76
83
|
*NOTE* Any totals columns your xml requests will be interpreted
|
77
84
|
as ordinary data.
|
78
85
|
|
79
86
|
=== session vs. start_session/end_session
|
80
87
|
|
81
|
-
The
|
88
|
+
The *session* method opens a session, gives you a token to use in your service
|
82
89
|
calls, then closes the session when the block ends, even if an exception is
|
83
90
|
raised during processing. It's the recommended method to ensure you don't
|
84
91
|
hang connections when things go wrong. If you use start/end, make sure you
|
data/TODO
CHANGED
@@ -13,7 +13,7 @@
|
|
13
13
|
** DONE Yieldmanager::Report DTO
|
14
14
|
*** DONE headers array (for proper column ordering)
|
15
15
|
*** DONE data as array of arrays
|
16
|
-
*** data as array of hashes
|
16
|
+
*** DONE data as array of hashes (string or symbol keys)
|
17
17
|
** DONE hpricot for parsing (http://github.com/hpricot/hpricot/)
|
18
18
|
** how to handle subtotal/total rows?
|
19
19
|
** cast columns to ruby types based on column[data_type]?
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
data/lib/yieldmanager/report.rb
CHANGED
@@ -3,7 +3,13 @@ module Yieldmanager
|
|
3
3
|
#
|
4
4
|
# The #pull method is typically called by Yieldmanager::Client#pull_report.
|
5
5
|
#
|
6
|
-
# Data is returned as an array
|
6
|
+
# Data is returned as an array that can be accessed either by index
|
7
|
+
# or by column name:
|
8
|
+
#
|
9
|
+
# report.headers # => ['advertiser_name','seller_imps']
|
10
|
+
# report.data[0][0] # => "Bob's Ads"
|
11
|
+
# report.data[0].by_name('advertiser_name') # => "Bob's Ads"
|
12
|
+
# report.data[0].by_name(:advertiser_name) # => "Bob's Ads"
|
7
13
|
#
|
8
14
|
# Column order is stored in the *headers* array.
|
9
15
|
class Report
|
@@ -41,18 +47,27 @@ private
|
|
41
47
|
(doc/"header column").each do |col|
|
42
48
|
headers << col.inner_html
|
43
49
|
end
|
44
|
-
(doc/"row").each_with_index do |
|
45
|
-
# TODO make data available as keyword hashes, too
|
46
|
-
# row_hash = {}
|
47
|
-
# (row/"column").each do |col|
|
48
|
-
# row_hash[headers[idx]] = col.inner_html
|
49
|
-
# end
|
50
|
-
# data << row_hash
|
50
|
+
(doc/"row").each_with_index do |row_elems,idx|
|
51
51
|
# TODO cast elements to appropriate types based on column attrs
|
52
|
-
|
53
|
-
|
52
|
+
row = ReportRow.new(headers)
|
53
|
+
(row_elems/"column").each do |col|
|
54
|
+
row << col.inner_html
|
55
|
+
end
|
56
|
+
data << row
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class ReportRow < Array
|
61
|
+
def initialize headers
|
62
|
+
@name_lookup = {}
|
63
|
+
headers.each_with_index do |header, idx|
|
64
|
+
@name_lookup[header] = idx
|
54
65
|
end
|
55
66
|
end
|
67
|
+
|
68
|
+
def by_name name
|
69
|
+
at(@name_lookup[name.to_s])
|
70
|
+
end
|
56
71
|
end
|
57
72
|
end
|
58
73
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<RWResponse>
|
3
|
+
<RESPONSE>
|
4
|
+
<DATA>
|
5
|
+
<HEADER>
|
6
|
+
<COLUMN>first</COLUMN>
|
7
|
+
<COLUMN>second</COLUMN>
|
8
|
+
</HEADER>
|
9
|
+
<ROW>
|
10
|
+
<COLUMN data_type="text" id="5" >one</COLUMN>
|
11
|
+
<COLUMN data_type="numeric" >1</COLUMN>
|
12
|
+
</ROW>
|
13
|
+
<ROW>
|
14
|
+
<COLUMN data_type="text" id="12" >two</COLUMN>
|
15
|
+
<COLUMN data_type="numeric" >2</COLUMN>
|
16
|
+
</ROW>
|
17
|
+
</DATA>
|
18
|
+
<METADATA tracking_id="1" rows="2" columns="2" domain="network" timeend="2009-11-22 00:00:00" timestart="2009-11-21 00:00:00" timezone="America/New_York"/>
|
19
|
+
</RESPONSE>
|
20
|
+
</RWResponse>
|
@@ -13,6 +13,7 @@ describe "A Yieldmanager report request" do
|
|
13
13
|
|
14
14
|
before(:each) do
|
15
15
|
@ym = Yieldmanager::Client.new(login_args)
|
16
|
+
@sample_report = File.join(File.dirname(__FILE__), '..', 'reports', 'sample_report.xml')
|
16
17
|
end
|
17
18
|
|
18
19
|
it "returns report object" do
|
@@ -50,10 +51,16 @@ describe "A Yieldmanager report request" do
|
|
50
51
|
end
|
51
52
|
|
52
53
|
it "offers data as array of arrays" do
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
54
|
+
report = Yieldmanager::Report.new
|
55
|
+
report.send(:retrieve_data, @sample_report)
|
56
|
+
report.data[0][0].should == "one"
|
57
|
+
end
|
58
|
+
|
59
|
+
it "offers data as array of hashes" do
|
60
|
+
report = Yieldmanager::Report.new
|
61
|
+
report.send(:retrieve_data, @sample_report)
|
62
|
+
report.data[0].by_name('first').should == "one"
|
63
|
+
report.data[1].by_name(:second).should == "2"
|
57
64
|
end
|
58
65
|
|
59
66
|
it "complains if report token is nil"
|
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.3.
|
8
|
+
s.version = "0.3.1"
|
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-22}
|
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 = [
|
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
|
|
28
28
|
"lib/yieldmanager/builder.rb",
|
29
29
|
"lib/yieldmanager/client.rb",
|
30
30
|
"lib/yieldmanager/report.rb",
|
31
|
+
"spec/reports/sample_report.xml",
|
31
32
|
"spec/spec.opts",
|
32
33
|
"spec/spec_helper.rb",
|
33
34
|
"spec/yieldmanager/builder_spec.rb",
|
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.3.
|
4
|
+
version: 0.3.1
|
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-22 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -53,6 +53,7 @@ files:
|
|
53
53
|
- lib/yieldmanager/builder.rb
|
54
54
|
- lib/yieldmanager/client.rb
|
55
55
|
- lib/yieldmanager/report.rb
|
56
|
+
- spec/reports/sample_report.xml
|
56
57
|
- spec/spec.opts
|
57
58
|
- spec/spec_helper.rb
|
58
59
|
- spec/yieldmanager/builder_spec.rb
|