episodic-platform 0.9

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.
Files changed (36) hide show
  1. data/History.txt +4 -0
  2. data/Manifest.txt +35 -0
  3. data/PostInstall.txt +7 -0
  4. data/README.rdoc +86 -0
  5. data/Rakefile +45 -0
  6. data/lib/episodic/platform.rb +82 -0
  7. data/lib/episodic/platform/analytics_methods.rb +190 -0
  8. data/lib/episodic/platform/base.rb +64 -0
  9. data/lib/episodic/platform/collection_response.rb +45 -0
  10. data/lib/episodic/platform/connection.rb +305 -0
  11. data/lib/episodic/platform/exceptions.rb +105 -0
  12. data/lib/episodic/platform/query_methods.rb +721 -0
  13. data/lib/episodic/platform/response.rb +94 -0
  14. data/lib/episodic/platform/write_methods.rb +446 -0
  15. data/script/console +10 -0
  16. data/script/destroy +14 -0
  17. data/script/generate +14 -0
  18. data/test/fixtures/1-0.mp4 +0 -0
  19. data/test/fixtures/create-episode-response-s3.xml +15 -0
  20. data/test/fixtures/create-episode-response.xml +3 -0
  21. data/test/fixtures/episodes-response.xml +408 -0
  22. data/test/fixtures/episodes-summary-report-response.xml +4 -0
  23. data/test/fixtures/invalid-param-response-multiple.xml +8 -0
  24. data/test/fixtures/invalid-param-response-single.xml +9 -0
  25. data/test/fixtures/playlists-response.xml +611 -0
  26. data/test/fixtures/shows-response.xml +26 -0
  27. data/test/test_analytics_requests.rb +42 -0
  28. data/test/test_analytics_responses.rb +14 -0
  29. data/test/test_connection.rb +31 -0
  30. data/test/test_error_responses.rb +29 -0
  31. data/test/test_helper.rb +8 -0
  32. data/test/test_query_requests.rb +62 -0
  33. data/test/test_query_responses.rb +165 -0
  34. data/test/test_write_requests.rb +56 -0
  35. data/test/test_write_responses.rb +24 -0
  36. metadata +135 -0
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ === 0.0.9 2010-02-10
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/Manifest.txt ADDED
@@ -0,0 +1,35 @@
1
+ History.txt
2
+ Manifest.txt
3
+ PostInstall.txt
4
+ README.rdoc
5
+ Rakefile
6
+ lib/episodic/platform.rb
7
+ lib/episodic/platform/analytics_methods.rb
8
+ lib/episodic/platform/base.rb
9
+ lib/episodic/platform/collection_response.rb
10
+ lib/episodic/platform/connection.rb
11
+ lib/episodic/platform/exceptions.rb
12
+ lib/episodic/platform/query_methods.rb
13
+ lib/episodic/platform/response.rb
14
+ lib/episodic/platform/write_methods.rb
15
+ script/console
16
+ script/destroy
17
+ script/generate
18
+ test/fixtures/1-0.mp4
19
+ test/fixtures/create-episode-response-s3.xml
20
+ test/fixtures/create-episode-response.xml
21
+ test/fixtures/episodes-response.xml
22
+ test/fixtures/episodes-summary-report-response.xml
23
+ test/fixtures/invalid-param-response-multiple.xml
24
+ test/fixtures/invalid-param-response-single.xml
25
+ test/fixtures/playlists-response.xml
26
+ test/fixtures/shows-response.xml
27
+ test/test_analytics_requests.rb
28
+ test/test_analytics_responses.rb
29
+ test/test_connection.rb
30
+ test/test_error_responses.rb
31
+ test/test_helper.rb
32
+ test/test_query_requests.rb
33
+ test/test_query_responses.rb
34
+ test/test_write_requests.rb
35
+ test/test_write_responses.rb
data/PostInstall.txt ADDED
@@ -0,0 +1,7 @@
1
+
2
+ For more information on episodic-platform, see http://episodic.github.com/episodic-platform-ruby
3
+
4
+ NOTE: Change this information in PostInstall.txt
5
+ You can also delete it if you don't want it.
6
+
7
+
data/README.rdoc ADDED
@@ -0,0 +1,86 @@
1
+ = Episodic Platform SDK for Ruby
2
+
3
+ * http://github.com/episodic/episodic-platform-ruby
4
+
5
+ == DESCRIPTION:
6
+
7
+ Ruby client library for Episodic's Platform REST API
8
+
9
+ For more information about Episodic's Platform API see {http://app.episodic.com/help/server_api}[http://app.episodic.com/help/server_api]
10
+
11
+ Rdocs are located at {http://episodic.github.com/episodic-platform-ruby/doc/index.html}[http://episodic.github.com/episodic-platform-ruby/doc/index.html]
12
+
13
+ == GETTING STARTED:
14
+
15
+ To get started you need to require 'episodic/platform':
16
+
17
+ require 'episodic/platform'
18
+
19
+ Before you can use any of the object methods, you need to create a connection using <tt>Base.establish_connection!</tt>. The
20
+ <tt>Base.establish_connection!</tt> method requires that you pass your Episodic API Key and Episodic Secret Key.
21
+
22
+ Episodic::Platform::Base.establish_connection!('my_api_key', 'my_secret_key')
23
+
24
+ After establishing a connection you can call any of the methods in the <tt>Episodic::Platform::QueryMehtods</tt>, <tt>Episodic::Platform::WriteMehtods</tt>
25
+ or <tt>Episodic::Platform::AnaylticsMehtods</tt>. Generally these methods will return some subclass of <tt>Episodic::Platform::Response</tt> which
26
+ contains the parsed response. However, you can also access the XML response body directly by calling <tt>response.xml</tt>.
27
+
28
+ == SAMPLE USAGE:
29
+
30
+ To query for a list of episodes:
31
+
32
+ response = Episodic::Platform::QueryMethods.episodes({:show_id => "12345678", search_term => "fun", :status => "on_the_air", :sort_by => "air_date"})
33
+
34
+ puts "There are a total of #{response.total} episodes matching the query"
35
+
36
+ # For each episode display the episode's name and embed code for the default player.
37
+ response.episodes.each do |episode|
38
+ puts episode.name
39
+ default_player = episode.players.detect {|p| p.default}
40
+ puts default_player.embed_code
41
+ end
42
+
43
+ To create a new episode:
44
+
45
+ # Create the episode and tell Episodic about the video file and thumbnail file to use
46
+ response = ::Episodic::Platform::WriteMethods.create_episode("oz04s1q0i29t", "My Episode", {:air_date => Time.now + 1.week, :upload_types => "s3", :video_filename => "my_video.mp4", :thumbnail_filename => "my_thumb.png"})
47
+
48
+ # Now upload the video and thumbnail. It is best to upload the thumbnail first since it is usually smaller.
49
+ ::Episodic::Platform::WriteMethods.upload_file_for_episode(response.upload_for_filepath("/home/viceos/my_thumb.png"))
50
+ ::Episodic::Platform::WriteMethods.upload_file_for_episode(response.upload_for_filepath("/home/viceos/my_video.mp4"))
51
+
52
+ == HANDLING ERRORS:
53
+
54
+ Any errors returned from the Episodic Platform API are converted to exceptions and raised from the called method. For example,
55
+ the following response would cause <tt>Episodic::Platform::InvalidAPIKey</tt> to be raised.
56
+
57
+ <?xml version="1.0" encoding="UTF-8"?>
58
+ <error>
59
+ <code>1</code>
60
+ <message>Invalid API Key</message>
61
+ </error>
62
+
63
+ == LICENSE:
64
+
65
+ (The MIT License)
66
+
67
+ Copyright (c) 2010 Episodic, Inc.
68
+
69
+ Permission is hereby granted, free of charge, to any person obtaining
70
+ a copy of this software and associated documentation files (the
71
+ 'Software'), to deal in the Software without restriction, including
72
+ without limitation the rights to use, copy, modify, merge, publish,
73
+ distribute, sublicense, and/or sell copies of the Software, and to
74
+ permit persons to whom the Software is furnished to do so, subject to
75
+ the following conditions:
76
+
77
+ The above copyright notice and this permission notice shall be
78
+ included in all copies or substantial portions of the Software.
79
+
80
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
81
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
82
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
83
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
84
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
85
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
86
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/episodic/platform'
6
+
7
+ Hoe.plugin :newgem
8
+ # Hoe.plugin :website
9
+ # Hoe.plugin :cucumberfeatures
10
+
11
+ # Generate all the Rake tasks
12
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
13
+ $hoe = Hoe.spec 'episodic-platform' do
14
+ self.developer 'Randy Simon', 'support@episodic.com'
15
+ self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
16
+ self.rubyforge_name = self.name # TODO this is default value
17
+ self.version = '0.9'
18
+
19
+ end
20
+
21
+ require 'newgem/tasks'
22
+ Dir['tasks/**/*.rake'].each { |t| load t }
23
+
24
+ gem 'rdoc'
25
+ gem 'hanna'
26
+ require 'rake/rdoctask'
27
+ require 'hanna/rdoctask'
28
+
29
+ desc 'Generate RDoc documentation'
30
+ Rake::RDocTask.new(:rdoc) do |rdoc|
31
+ # rdoc.rdoc_files.include('README.rdoc', 'LICENSE', 'CHANGELOG').
32
+ # include('lib/**/*.rb').
33
+ ## exclude('lib/will_paginate/named_scope*').
34
+
35
+ rdoc.main = "README.rdoc" # page to start on
36
+ rdoc.title = "Episodic Platform GEM documentation"
37
+
38
+ rdoc.rdoc_dir = 'doc' # rdoc output folder
39
+ # rdoc.options << '--webcvs=http://github.com/mislav/will_paginate/tree/master/'
40
+ end
41
+
42
+
43
+ # TODO - want other tests/tasks run by default? Add them to the list
44
+ # remove_task :default
45
+ # task :default => [:spec, :features]
@@ -0,0 +1,82 @@
1
+ require 'time'
2
+ require 'digest/sha1'
3
+ require 'digest/md5'
4
+ require 'net/http'
5
+ require 'uri'
6
+ require 'zlib'
7
+
8
+ def require_library_or_gem(library, gem_name = nil)
9
+ if RUBY_VERSION >= '1.9'
10
+ gem(gem_name || library, '>=0')
11
+ end
12
+ require library
13
+ rescue LoadError => library_not_installed
14
+ begin
15
+ require 'rubygems'
16
+ require library
17
+ rescue LoadError
18
+ raise library_not_installed
19
+ end
20
+ end
21
+
22
+ $:.unshift(File.dirname(__FILE__)) unless
23
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
24
+ require_library_or_gem 'curb' unless defined? Curb
25
+ require_library_or_gem 'xmlsimple', 'xml-simple' unless defined? XmlSimple
26
+ require_library_or_gem 'hanna', 'mislav-hanna' unless defined? Hanna
27
+
28
+ class Class # :nodoc:
29
+ def cattr_reader(*syms)
30
+ syms.flatten.each do |sym|
31
+ class_eval(<<-EOS, __FILE__, __LINE__)
32
+ unless defined? @@#{sym}
33
+ @@#{sym} = nil
34
+ end
35
+
36
+ def self.#{sym}
37
+ @@#{sym}
38
+ end
39
+
40
+ def #{sym}
41
+ @@#{sym}
42
+ end
43
+ EOS
44
+ end
45
+ end
46
+
47
+ def cattr_writer(*syms)
48
+ syms.flatten.each do |sym|
49
+ class_eval(<<-EOS, __FILE__, __LINE__)
50
+ unless defined? @@#{sym}
51
+ @@#{sym} = nil
52
+ end
53
+
54
+ def self.#{sym}=(obj)
55
+ @@#{sym} = obj
56
+ end
57
+
58
+ def #{sym}=(obj)
59
+ @@#{sym} = obj
60
+ end
61
+ EOS
62
+ end
63
+ end
64
+
65
+ def cattr_accessor(*syms)
66
+ cattr_reader(*syms)
67
+ cattr_writer(*syms)
68
+ end
69
+ end if Class.instance_methods(false).grep(/^cattr_(?:reader|writer|accessor)$/).empty?
70
+
71
+ require 'platform/exceptions'
72
+ require 'platform/response'
73
+ require 'platform/collection_response'
74
+ require 'platform/connection'
75
+ require 'platform/base'
76
+ require 'platform/analytics_methods'
77
+ require 'platform/query_methods'
78
+ require 'platform/write_methods'
79
+
80
+ Episodic::Platform::Base.class_eval do
81
+ include Episodic::Platform::Connection::Management
82
+ end
@@ -0,0 +1,190 @@
1
+ module Episodic #:nodoc:
2
+
3
+ module Platform
4
+
5
+ #
6
+ # Class for making requests against the Episodic Platform Analytics API.
7
+ #
8
+ class AnalyticsMethods < Base
9
+
10
+ class << self
11
+
12
+ #
13
+ # Fetches a previously generated report.
14
+ #
15
+ # ==== Parameters
16
+ #
17
+ # report_token<String>:: This is the value returned from one of the report generation methods.
18
+ #
19
+ # ==== Returns
20
+ #
21
+ # String:: The contents of the report.
22
+ #
23
+ def get_report token
24
+ params = {
25
+ :report_token => token,
26
+ }
27
+
28
+ response = connection.do_get(construct_url("analytics", "get_report"), params)
29
+
30
+ return response.body
31
+ end
32
+
33
+ #
34
+ # Generates a report for all episodes in a show. The report will contain information such as
35
+ # the total views, complete views, downloads, etc for each episode in the show.
36
+ #
37
+ # It is important to note that this method just generates the report and returns a token
38
+ # that can be used to get the report by calling <tt>Episodic::Platform::AnalyticsMethods.get_report</tt>.
39
+ #
40
+ # ==== Parameters
41
+ #
42
+ # show_id<String>:: The id of the show that contains your episodes. To get a list of your
43
+ # shows see <tt>Episodic::Platform::QueryMethods.show</tt>.
44
+ # date_range<String>:: Specifies period of your report. The value of this parameter must be one
45
+ # of 'today', 'last_seven', 'last_thirty'.
46
+ # date_grouping<String>:: Must be one of 'daily' or 'aggregate' to list the data by day or just a total
47
+ # for the entire period respectively.
48
+ # format<String>:: The format parameter is required and must be one of 'csv' or 'xml'.
49
+ #
50
+ # ==== Returns
51
+ #
52
+ # Episodic::Platform::TokenResponse:: This response object includes a token that can be used to
53
+ # actually get the report by calling <tt>Episodic::Platform::AnalyticsMethods.get_report</tt>.
54
+ #
55
+ def episodes_summary_report show_id, date_range, date_grouping, format
56
+
57
+ params = {
58
+ :show_id => show_id,
59
+ :date_range => date_range,
60
+ :date_grouping => date_grouping,
61
+ :format => format
62
+ }
63
+
64
+ response = connection.do_get(construct_url("analytics", "request_episodes_summary_report"), params)
65
+
66
+ # Convert to a hash
67
+ return parse_token_response(response)
68
+ end
69
+
70
+ #
71
+ # Generates a report for a specific episode in a show. The report will contain information
72
+ # such as the total views, complete views, downloads, etc for each episode in the show.
73
+ #
74
+ # It is important to note that this method just generates the report and returns a token
75
+ # that can be used to get the report by calling <tt>Episodic::Platform::AnalyticsMethods.get_report</tt>.
76
+ #
77
+ # ==== Parameters
78
+ #
79
+ # show_id<String>:: The id of the show that contains your episodes. To get a list of your
80
+ # shows see <tt>Episodic::Platform::QueryMethods.show</tt>.
81
+ # episode_id<String>:: The id of the episodes to generate the report for. To get a list of your
82
+ # episodes see <tt>Episodic::Platform::QueryMethods.episodes</tt>.
83
+ # date_range<String>:: Specifies period of your report. The value of this parameter must be one
84
+ # of 'today', 'last_seven', 'last_thirty'.
85
+ # format<String>:: The format parameter is required and must be one of 'csv' or 'xml'.
86
+ #
87
+ # ==== Returns
88
+ #
89
+ # Episodic::Platform::TokenResponse:: This response object includes a token that can be used to
90
+ # actually get the report by calling <tt>Episodic::Platform::AnalyticsMethods.get_report</tt>.
91
+ #
92
+ def episode_daily_report show_id, episode_id, date_range, format
93
+
94
+ params = {
95
+ :show_id => show_id,
96
+ :date_range => date_range,
97
+ :id => episode_id,
98
+ :format => format
99
+ }
100
+
101
+ response = connection.do_get(construct_url("analytics", "request_episode_daily_report"), params)
102
+
103
+ # Convert to a hash
104
+ return parse_token_response(response)
105
+ end
106
+
107
+ #
108
+ # Generates a report for all campaigns in a specific show. The report will contain information
109
+ # such as the total views, complete views, downloads, click throughs, etc for each campaign in the show.
110
+ #
111
+ # It is important to note that this method just generates the report and returns a token
112
+ # that can be used to get the report by calling <tt>Episodic::Platform::AnalyticsMethods.get_report</tt>.
113
+ #
114
+ # ==== Parameters
115
+ #
116
+ # show_id<String>:: The id of the show that contains your campaigns. To get a list of your
117
+ # shows see <tt>Episodic::Platform::QueryMethods.show</tt>.
118
+ # date_range<String>:: Specifies period of your report. The value of this parameter must be one
119
+ # of 'today', 'last_seven', 'last_thirty'.
120
+ # format<String>:: The format parameter is required and must be one of 'csv' or 'xml'.
121
+ #
122
+ # ==== Returns
123
+ #
124
+ # Episodic::Platform::TokenResponse:: This response object includes a token that can be used to
125
+ # actually get the report by calling <tt>Episodic::Platform::AnalyticsMethods.get_report</tt>.
126
+ #
127
+ def campaigns_daily_report show_id, date_range, format
128
+
129
+ params = {
130
+ :show_id => show_id,
131
+ :date_range => date_range,
132
+ :format => format
133
+ }
134
+
135
+ response = connection.do_get(construct_url("analytics", "request_campaigns_daily_report"), params)
136
+
137
+ # Convert to a hash
138
+ return parse_token_response(response)
139
+ end
140
+
141
+ protected
142
+
143
+ #
144
+ # Method factored out to make unit testing easier. This method simply creates the <tt>::Episodic::Platform::TokenResponse</tt>
145
+ # object.
146
+ #
147
+ # ==== Parameters
148
+ #
149
+ # response<Episodic::Platform::HTTPResponse>:: The response from any token request
150
+ #
151
+ # ==== Returns
152
+ #
153
+ # ::Episodic::Platform::TokenResponse:: The parsed response.
154
+ #
155
+ def parse_token_response response
156
+ return TokenResponse.new(response)
157
+ end
158
+ end
159
+ end
160
+
161
+ #
162
+ # All token request methods have a similar response structure. This class extends <tt>Episodic::Platform::Response</tt>
163
+ # and adds a method to get the token of the generated report.
164
+ #
165
+ class TokenResponse < Response
166
+
167
+ #
168
+ # Constructor
169
+ #
170
+ # ==== Parameters
171
+ #
172
+ # response<Episodic::Platform::HTTPResponse>:: The response object returned from an Episodic Platform API request.
173
+ #
174
+ def initialize response
175
+ super(response, "ForceArray" => false)
176
+ end
177
+
178
+ #
179
+ # Get the token used to request the generated report. This token is passed to
180
+ # <tt>Episodic::Platform::AnalyticsMethods.get_report</tt>.
181
+ #
182
+ def token
183
+ return @parsed_body["report_token"]
184
+ end
185
+
186
+ end
187
+
188
+ end
189
+
190
+ end