Skip to content

Commit fce1f5e

Browse files
committed
Merge branch 'feature/update-reports'
2 parents ffeb7ab + 277fa6a commit fce1f5e

File tree

5 files changed

+139
-8
lines changed

5 files changed

+139
-8
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ Gemfile.lock
77
/tmp
88
/.rbx
99
.zenflow-log
10+
.ruby-gemset
11+
.ruby-version

Gemfile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
source :rubygems
1+
source 'https://rubygems.org'
22

33
gem "multi_json"
4+
gem "rake"
45

56
group :test do
6-
gem "shoulda"
7+
gem "shoulda", "2.11.3"
8+
gem "activesupport", "3.2.16"
79
gem "mocha"
810
gem "webmock", "~>1.6.0"
911
end
@@ -12,5 +14,6 @@ group :development do
1214
gem "jruby-openssl", :platforms => :jruby
1315
gem "ruby-debug", :platforms => :mri_18
1416
gem "ruby-debug19", :platforms => :mri_19
15-
gem "typhoeus", :platforms => [:mri_18, :mri_19]
17+
gem "byebug", :platforms => :mri_20
18+
gem "typhoeus", :platforms => [:mri_18, :mri_19, :mri_20]
1619
end

README.markdown

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Tested on the following versions of Ruby:
1111
* Ruby 1.8.7-p352
1212
* Ruby 1.9.2-p290
1313
* Ruby 1.9.3-p0
14+
* Ruby 2.0.0-p353
1415
* Rubinius 2.0.0dev
1516
* jRuby 1.6.5
1617

@@ -35,6 +36,9 @@ With the release of version two of the Zencoder API, there are some new methods
3536
* Zencoder::Input.progress(input\_id)
3637
* Zencoder::Output.details(output\_id)
3738
* Zencoder::Report.minutes(:from => "2011-01-01", :to => "2011-03-01")
39+
* Zencoder::Report.all(:from => "2011-01-01", :to => "2011-03-01")
40+
* Zencoder::Report.live(:from => "2011-01-01", :to => "2011-03-01")
41+
* Zencoder::Report.vod(:from => "2011-01-01", :to => "2011-03-01")
3842

3943
These new methods will not work with older versions of the API. Please see the [Zencoder documentation](https://app.zencoder.com/docs) and our [blog post on the subject](http://blog.zencoder.com/2012/01/05/announcing-zencoder-api-v2/) for more information on APIv2.
4044

@@ -279,6 +283,30 @@ This will list the minutes used for your account within a certain, configurable
279283
Zencoder::Report.minutes(:from => "2011-10-30", :to => "2011-11-24")
280284
```
281285

286+
### all
287+
288+
This will list all usage, including VOD and Live for your account within a certain, configurable range.
289+
290+
```ruby
291+
Zencoder::Report.all(:from => "2011-10-30", :to => "2011-11-24")
292+
```
293+
294+
### vod
295+
296+
This will list just VOD usage for your account within a certain, configurable range.
297+
298+
```ruby
299+
Zencoder::Report.vod(:from => "2011-10-30", :to => "2011-11-24")
300+
```
301+
302+
### live
303+
304+
This will list just Live usage for your account within a certain, configurable range.
305+
306+
```ruby
307+
Zencoder::Report.live(:from => "2011-10-30", :to => "2011-11-24")
308+
```
309+
282310
## Advanced HTTP
283311

284312
### Alternate HTTP Libraries

lib/zencoder/report.rb

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,33 @@ module Zencoder
22
class Report < Resource
33

44
def self.minutes(options={})
5-
get("/reports/minutes", options)
5+
get("/reports/minutes", merge_params(*extract_params(options)))
6+
end
7+
8+
def self.all(options={})
9+
get("/reports/all", merge_params(*extract_params(options)))
10+
end
11+
12+
def self.live(options={})
13+
get("/reports/live", merge_params(*extract_params(options)))
14+
end
15+
16+
def self.vod(options={})
17+
get("/reports/vod", merge_params(*extract_params(options)))
18+
end
19+
20+
21+
protected
22+
23+
def self.extract_params(options={})
24+
options = options.dup
25+
params = {
26+
:from => options.delete(:from),
27+
:to => options.delete(:to),
28+
:grouping => options.delete(:grouping)
29+
}
30+
31+
return options, params.delete_if { |k, v| v.nil? }
632
end
733

834
end

test/zencoder/reports_test.rb

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,88 @@ class Zencoder::ReportTest < Test::Unit::TestCase
1313
:to => "2011-06-01",
1414
:grouping => "foo"},
1515
:headers => { "Zencoder-Api-Key" => @api_key }}).returns(Zencoder::Response.new)
16-
assert_equal Zencoder::Response, Zencoder::Report.minutes(:api_key => @api_key, :params => { :from => "2011-01-01",
17-
:to => "2011-06-01",
18-
:grouping => "foo" }).class
16+
assert_equal Zencoder::Response, Zencoder::Report.minutes(:api_key => @api_key, :from => "2011-01-01",
17+
:to => "2011-06-01",
18+
:grouping => "foo").class
1919
end
2020

2121
should "merge params well" do
2222
Zencoder::HTTP.stubs(:get).with(@url, {:params => { :from => "2011-01-01",
2323
:to => "2011-06-01"},
2424
:headers => { "Zencoder-Api-Key" => @api_key }}).returns(Zencoder::Response.new)
25-
assert_equal Zencoder::Response, Zencoder::Report.minutes(:api_key => @api_key, :params => {:from => "2011-01-01", :to => "2011-06-01"}).class
25+
assert_equal Zencoder::Response, Zencoder::Report.minutes(:api_key => @api_key, :from => "2011-01-01", :to => "2011-06-01").class
26+
end
27+
end
28+
29+
context ".all" do
30+
setup do
31+
@api_key = "abcd123"
32+
@url = "#{Zencoder.base_url}/reports/all"
33+
end
34+
35+
should "GET the correct url and return a response" do
36+
Zencoder::HTTP.stubs(:get).with(@url, {:params => { :from => "2011-01-01",
37+
:to => "2011-06-01",
38+
:grouping => "foo"},
39+
:headers => { "Zencoder-Api-Key" => @api_key }}).returns(Zencoder::Response.new)
40+
assert_equal Zencoder::Response, Zencoder::Report.all(:api_key => @api_key, :from => "2011-01-01",
41+
:to => "2011-06-01",
42+
:grouping => "foo").class
43+
end
44+
45+
should "merge params well" do
46+
Zencoder::HTTP.stubs(:get).with(@url, {:params => { :from => "2011-01-01",
47+
:to => "2011-06-01"},
48+
:headers => { "Zencoder-Api-Key" => @api_key }}).returns(Zencoder::Response.new)
49+
assert_equal Zencoder::Response, Zencoder::Report.all(:api_key => @api_key, :from => "2011-01-01", :to => "2011-06-01").class
50+
end
51+
end
52+
53+
context ".vod" do
54+
setup do
55+
@api_key = "abcd123"
56+
@url = "#{Zencoder.base_url}/reports/vod"
57+
end
58+
59+
should "GET the correct url and return a response" do
60+
Zencoder::HTTP.stubs(:get).with(@url, {:params => { :from => "2011-01-01",
61+
:to => "2011-06-01",
62+
:grouping => "foo"},
63+
:headers => { "Zencoder-Api-Key" => @api_key }}).returns(Zencoder::Response.new)
64+
assert_equal Zencoder::Response, Zencoder::Report.vod(:api_key => @api_key, :from => "2011-01-01",
65+
:to => "2011-06-01",
66+
:grouping => "foo").class
67+
end
68+
69+
should "merge params well" do
70+
Zencoder::HTTP.stubs(:get).with(@url, {:params => { :from => "2011-01-01",
71+
:to => "2011-06-01"},
72+
:headers => { "Zencoder-Api-Key" => @api_key }}).returns(Zencoder::Response.new)
73+
assert_equal Zencoder::Response, Zencoder::Report.vod(:api_key => @api_key, :from => "2011-01-01", :to => "2011-06-01").class
74+
end
75+
end
76+
77+
context ".live" do
78+
setup do
79+
@api_key = "abcd123"
80+
@url = "#{Zencoder.base_url}/reports/live"
81+
end
82+
83+
should "GET the correct url and return a response" do
84+
Zencoder::HTTP.stubs(:get).with(@url, {:params => { :from => "2011-01-01",
85+
:to => "2011-06-01",
86+
:grouping => "foo"},
87+
:headers => { "Zencoder-Api-Key" => @api_key }}).returns(Zencoder::Response.new)
88+
assert_equal Zencoder::Response, Zencoder::Report.live(:api_key => @api_key, :from => "2011-01-01",
89+
:to => "2011-06-01",
90+
:grouping => "foo").class
91+
end
92+
93+
should "merge params well" do
94+
Zencoder::HTTP.stubs(:get).with(@url, {:params => { :from => "2011-01-01",
95+
:to => "2011-06-01"},
96+
:headers => { "Zencoder-Api-Key" => @api_key }}).returns(Zencoder::Response.new)
97+
assert_equal Zencoder::Response, Zencoder::Report.live(:api_key => @api_key, :from => "2011-01-01", :to => "2011-06-01").class
2698
end
2799
end
28100

0 commit comments

Comments
 (0)