ooyala 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,6 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
6
+ api.yml
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Matthew Ford and Bit Zesty Ltd. (http://bitzesty.com/)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,28 @@
1
+ = Ooyala
2
+
3
+ Ruby gem to access the Ooyala API
4
+
5
+ == TODO
6
+
7
+ * replace httparty as it's causing sig mismatches with the params
8
+ * finish implementing api
9
+
10
+
11
+ == Testing
12
+
13
+ Create a YAML file in features/support/api.yml
14
+
15
+ == Note on Patches/Pull Requests
16
+
17
+ * Fork the project.
18
+ * Make your feature addition or bug fix.
19
+ * Add tests for it. This is important so I don't break it in a
20
+ future version unintentionally.
21
+ * Commit, do not mess with rakefile, version, or history.
22
+ If you want to have your own version, that is fine but
23
+ bump version in a commit by itself I can ignore when I pull
24
+ * Send me a pull request. Bonus points for topic branches.
25
+
26
+ == Copyright
27
+
28
+ Copyright (c) 2009 Bit Zesty Ltd. See LICENSE for details.
@@ -0,0 +1,48 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "ooyala"
8
+ gem.summary = %Q{Ruby gem to access the Ooyala API}
9
+ gem.description = %Q{Ruby gem to access the Ooyala API}
10
+ gem.email = "matthew.c.ford@gmail.com"
11
+ gem.homepage = "http://github.com/bitzesty/ooyala"
12
+ gem.authors = ["Matthew Ford"]
13
+ gem.add_dependency("httparty", ">=0.0.4")
14
+ # gem.add_development_dependency("fakeweb", ">=1.2.5")
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
20
+ end
21
+
22
+ begin
23
+ require 'cucumber/rake/task'
24
+ Cucumber::Rake::Task.new(:features) do |t|
25
+ t.cucumber_opts = "--format pretty"
26
+ t.rcov = true
27
+ t.rcov_opts = %w{--exclude features\/}
28
+ end
29
+ rescue LoadError
30
+ task :features do
31
+ abort "Cucumber or rcov is not available. In order to run features, you must: sudo gem install cucumber relevance-rcov"
32
+ end
33
+ end
34
+ task :default => :features
35
+
36
+ require 'rake/rdoctask'
37
+ Rake::RDocTask.new do |rdoc|
38
+ if File.exist?('VERSION')
39
+ version = File.read('VERSION')
40
+ else
41
+ version = ""
42
+ end
43
+
44
+ rdoc.rdoc_dir = 'rdoc'
45
+ rdoc.title = "ooyala #{version}"
46
+ rdoc.rdoc_files.include('README*')
47
+ rdoc.rdoc_files.include('lib/**/*.rb')
48
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.2
@@ -0,0 +1,34 @@
1
+ Feature: Ooyala API
2
+
3
+ Background:
4
+ Given I wait a few seconds
5
+ When I request my videos
6
+
7
+ Scenario: Query your videos
8
+ Then I should receive my account data
9
+
10
+ Scenario: Fetching thumbnails for a video
11
+ When I request the thumbnails for the first one
12
+ Then I should receive a list of thumbnails
13
+
14
+ Scenario: Updating a video title
15
+ When I update it's title
16
+ Then it should succeed
17
+
18
+ Scenario: Add metadata to a video
19
+ When I update the genre
20
+ Then it should succeed
21
+
22
+ Scenario: Search metadata for a video
23
+ When I query its metadata
24
+ Then I should have some metadata
25
+
26
+ Scenario: Delete metadata for a video
27
+ When I query its metadata
28
+ And delete one guid of metadata
29
+ Then that metadata should be deleted
30
+
31
+ Scenario: Delete metadata for a query
32
+ When I do a query to delete all metadata
33
+ Then it should succeed
34
+
@@ -0,0 +1,66 @@
1
+ Given /^I wait a few seconds$/ do
2
+ sleep 5.5
3
+ end
4
+
5
+ When /^I request my videos$/ do
6
+ @responce = Video.query
7
+ @responce.should_not == "signature mismatch"
8
+ if @responce["list"]["size"].to_i > 1
9
+ @video = @responce["list"]["item"][0]
10
+ else
11
+ @video = @responce["list"]["item"]
12
+ end
13
+ end
14
+
15
+ Then /^I should receive my account data$/ do
16
+ @responce['list']['pageID'].should == "0"
17
+ end
18
+
19
+ When /^I request the thumbnails for the first one$/ do
20
+ sleep 6.0
21
+ @responce = Video.thumbnails(@video["embedCode"])
22
+ @responce.should_not == "signature mismatch"
23
+ end
24
+
25
+ Then /^I should receive a list of thumbnails$/ do
26
+ @responce["thumbnails"]["thumbnail"].size.should >= 1
27
+ end
28
+
29
+ When /^I update it's title$/ do
30
+ sleep 6.0
31
+ @responce = Video.edit(@video["embedCode"], {"title" => "#{@video["title"]}_updated"})
32
+ @responce.should_not == "signature mismatch"
33
+ end
34
+
35
+ When /^I update the genre$/ do
36
+ sleep 6.0
37
+ @responce = Video.metadata(@video["embedCode"], "add", {"genre" => "Films"})
38
+ @responce.should_not == "signature mismatch"
39
+ end
40
+
41
+ When /^I query its metadata$/ do
42
+ pending
43
+ end
44
+
45
+ Then /^I should have some metadata$/ do
46
+ pending
47
+ end
48
+
49
+ When /^delete one guid of metadata$/ do
50
+ pending
51
+ end
52
+
53
+ Then /^that metadata should be deleted$/ do
54
+ pending
55
+ end
56
+
57
+ When /^I do a query to delete all metadata$/ do
58
+ pending
59
+ end
60
+
61
+
62
+
63
+ Then /^it should succeed$/ do
64
+ @responce.should == "ok"
65
+ end
66
+
@@ -0,0 +1,15 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
+ require 'ooyala'
3
+
4
+ require 'spec/expectations'
5
+
6
+ # require 'fakeweb' #http://fakeweb.rubyforge.org/
7
+ require 'pp'
8
+ require "yaml"
9
+
10
+ API = YAML::load_file(File.dirname(__FILE__) + '/api.yml')
11
+
12
+ class Video
13
+ include Ooyala
14
+ api_codes API["partner_code"], API["secret_code"]
15
+ end
@@ -0,0 +1,43 @@
1
+ # module HTTParty
2
+ # class Request #:nodoc:
3
+ # def uri
4
+ # new_uri = path.relative? ? URI.parse("#{options[:base_uri]}#{path}") : path
5
+ #
6
+ # # avoid double query string on redirects [#12]
7
+ # unless @redirect
8
+ # new_uri.query = query_string(new_uri)
9
+ # puts new_uri
10
+ # end
11
+ # new_uri
12
+ # end
13
+ # end
14
+ # end
15
+
16
+ # Need to hack httparty' perform request
17
+ # http://github.com/jnunemaker/httparty/blob/b0cf1e946f483b882f9fe4142b768754dbce6657/lib/httparty.rb#L157
18
+ # to conform with the api http://www.ooyala.com/support/docs/partner_api
19
+ module HTTParty
20
+ module ClassMethods
21
+ private
22
+ def perform_request(http_method, path, options)
23
+ process_cookies(options)
24
+ string_to_sign = ooyala_options[:api_codes][:secret]
25
+
26
+ options[:query] ||= {}
27
+ options[:query]["expires"] ||= (Time.now.to_i + 5).to_s
28
+
29
+ q = ["pcode=#{ooyala_options[:api_codes][:partner]}"]
30
+ options[:query].keys.sort.each do |k|
31
+ string_to_sign += "#{k}=#{options[:query][k]}"
32
+ q << "#{CGI.escape(k)}=#{CGI.escape(options[:query][k])}"
33
+ end
34
+
35
+ digest = Digest::SHA256.digest(string_to_sign)
36
+ signature = CGI.escape(Base64::encode64(digest).chomp.gsub(/=+$/, ''))
37
+ q << "signature=#{signature}"
38
+ options[:query] = q.join("&")
39
+
40
+ Request.new(http_method, path, default_options.dup.merge(options)).perform
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,87 @@
1
+ require 'rubygems'
2
+ require 'httparty'
3
+ require 'httparty/module_inheritable_attributes'
4
+ require "base64"
5
+ require "digest/sha2"
6
+ require 'uri'
7
+ require 'hacks'
8
+
9
+ module Ooyala
10
+ class NoAPICodes < StandardError; end #:nodoc:
11
+ class NoEmmbedCode < StandardError;end #:nodoc:
12
+ class InvalidStatus < StandardError;end #:nodoc:
13
+ class InvalidAction < StandardError;end #:nodoc:
14
+
15
+ def self.included(base)
16
+ base.send :include, HTTParty
17
+ base.extend ClassMethods
18
+ base.send(:mattr_inheritable, :ooyala_options)
19
+ base.instance_variable_set("@ooyala_options", {})
20
+ base.send(:base_uri, "http://api.ooyala.com/partner/")
21
+ end
22
+
23
+ module ClassMethods
24
+ def api_codes(partner, secret)
25
+ raise NoAPICodes if partner.blank? || secret.blank?
26
+ ooyala_options[:api_codes] = {:partner => partner, :secret => secret}
27
+ end
28
+
29
+ def query(options={})
30
+ self.get("/query", :query => options)
31
+ end
32
+
33
+ def query_channel_list
34
+ self.query('contentType' => 'Channel')
35
+ end
36
+
37
+ def query_channel(channel_embed_code, options = {})
38
+ opts = {'channelEmbedCode' => channel_embed_code, 'mode' => 'list'}.merge(options)
39
+ self.get("/channels", :query => opts)
40
+ end
41
+
42
+ ##
43
+ # Options:
44
+ # rage:: String:: "0-4"
45
+ # resolution:: String:: "320x240"
46
+ def thumbnails(embed_code, options={})
47
+ raise NoEmmbedCode if embed_code.blank?
48
+ opts = {"embedCode" => embed_code, "range" =>"0-25", "resolution" =>"600x400"}.merge(options)
49
+ self.get("/thumbnails", :query => opts)
50
+ end
51
+
52
+ ##
53
+ # TODO make an instance method
54
+ # Options:
55
+ # title:: String
56
+ # description:: String
57
+ # status:: String - "live", "paused" or "deleted" - Setting status to deleted deletes the video or channel.
58
+ # hostedAt:: String - The URL for the main page the video or channel is embedded on.
59
+ def edit(embed_code, options={})
60
+ raise NoEmmbedCode if embed_code.blank?
61
+ status_options = ['live', 'paused', 'deleted']
62
+ if options["status"]
63
+ raise InvalidStatus unless status_options.include?(options["status"])
64
+ end
65
+ opts = {"embedCode" => embed_code}.merge(options)
66
+ self.get("/edit", :query => opts)
67
+ end
68
+
69
+ ##
70
+ # TODO make an instance method
71
+ # Actions:: ["add", "query", "delete_id", "delete_query"]
72
+ # Add opts:: director, actor, genre (multiple in an array)
73
+ # Search opts:: rows, op (OR, AND), and same as Add action but with asterisks for fuzzy searching
74
+ # Delete ID opts:: guid
75
+ # Delete Query opts:: same as search (delete metadata)
76
+ def metadata(embed_code, action, options={})
77
+ raise NoEmmbedCode if embed_code.blank?
78
+ raise InvalidAction unless ["add", "query", "delete_id", "delete_query"].include?(action)
79
+ if options["genre"].is_a?(Array)
80
+ options["genre"] = options["genre"].join("\0")
81
+ end
82
+ opts = {"embedCode" => embed_code, "metaMode" => action}.merge(options)
83
+ self.get("/metadata", :query => opts)
84
+ end
85
+ end
86
+
87
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ooyala
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 2
10
+ version: 0.1.2
11
+ platform: ruby
12
+ authors:
13
+ - Matthew Ford
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-05-27 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: httparty
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 23
30
+ segments:
31
+ - 0
32
+ - 0
33
+ - 4
34
+ version: 0.0.4
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ description: Ruby gem to access the Ooyala API
38
+ email: matthew.c.ford@gmail.com
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files:
44
+ - LICENSE
45
+ - README.rdoc
46
+ files:
47
+ - .document
48
+ - .gitignore
49
+ - LICENSE
50
+ - README.rdoc
51
+ - Rakefile
52
+ - VERSION
53
+ - features/ooyala.feature
54
+ - features/step_definitions/ooyala_steps.rb
55
+ - features/support/env.rb
56
+ - lib/hacks.rb
57
+ - lib/ooyala.rb
58
+ has_rdoc: true
59
+ homepage: http://github.com/bitzesty/ooyala
60
+ licenses: []
61
+
62
+ post_install_message:
63
+ rdoc_options:
64
+ - --charset=UTF-8
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ hash: 3
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ requirements: []
86
+
87
+ rubyforge_project:
88
+ rubygems_version: 1.3.7
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: Ruby gem to access the Ooyala API
92
+ test_files: []
93
+