streamapi 0.0.1
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/.gitignore +3 -0
- data/Gemfile +4 -0
- data/README.rdoc +29 -0
- data/Rakefile +2 -0
- data/lib/streamapi/client.rb +98 -0
- data/lib/streamapi/embed.rb +55 -0
- data/lib/streamapi/version.rb +3 -0
- data/lib/streamapi.rb +7 -0
- data/streamapi.gemspec +21 -0
- metadata +73 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
= StreamAPI + Ruby
|
2
|
+
|
3
|
+
This is a Ruby gem for the StreamAPI. I have created in order to do a rapid prototype so expect a lot of deficiencies and complete lack of tests. Most of the code is influenced by the Wordnik Ruby client.
|
4
|
+
|
5
|
+
= Example Usage
|
6
|
+
|
7
|
+
Let's fire up an irb session:
|
8
|
+
$ irb
|
9
|
+
>> require 'streamapi'
|
10
|
+
=> true
|
11
|
+
|
12
|
+
Then create a session:
|
13
|
+
$ streamapi=StreamAPI::Client.new(:api_key=>yourapiky, :secret_key=>yoursecretkey, :site_id=>yoursiteid)
|
14
|
+
|
15
|
+
You can now call any of the methods provided by StreamAPI, for example:
|
16
|
+
$ themes = streamapi.list_themes()
|
17
|
+
|
18
|
+
Create a new session:
|
19
|
+
$ session = streamapi.create_session('panosjee',nil,true,false,1)
|
20
|
+
|
21
|
+
You can also create the embed object for the StreamAPI player:
|
22
|
+
StreamAPI::Embed.to_html(session['private_host_id'], session['public_host_id'], streamapi.site_id, theme)
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
== Copyright
|
27
|
+
|
28
|
+
Copyright (c) 2010 Panagiotis Papadopoulos / 6pna.com. See LICENSE for details.
|
29
|
+
Patches are very welcome!
|
data/Rakefile
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
# Ruby wrapper to access StreamAPI definitions API. Has dependency on HTTParty gem.
|
2
|
+
# No exception handling or other niceties. Intended as an API demo, not meant for production use
|
3
|
+
# Based on Wordnik Ruby api client
|
4
|
+
module StreamAPI
|
5
|
+
class ApiNotFoundError < StandardError
|
6
|
+
end
|
7
|
+
|
8
|
+
class ApiServerError < StandardError
|
9
|
+
end
|
10
|
+
|
11
|
+
class InvalidApiKeyError < StandardError
|
12
|
+
end
|
13
|
+
|
14
|
+
class InvalidAuthTokenError < StandardError
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
URL = 'http://api.streamapi.com/service'
|
19
|
+
TIMEOUT = 30
|
20
|
+
DEBUG = false
|
21
|
+
|
22
|
+
class Client
|
23
|
+
include HTTParty
|
24
|
+
base_uri URL
|
25
|
+
|
26
|
+
attr_accessor :api_key, :secret_key, :site_id, :site_user_id, :username, :timeout, :debug
|
27
|
+
|
28
|
+
def initialize(options={})
|
29
|
+
raise(InvalidApiKeyError, "Missing api_key!") if options[:api_key].nil?
|
30
|
+
raise(InvalidSecretKeyError, "Missing secret_key!") if options[:secret_key].nil?
|
31
|
+
raise(InvalidSiteIdError, "Missing site_id!") if options[:site_id].nil?
|
32
|
+
|
33
|
+
@api_key = options[:api_key]
|
34
|
+
@@api_key = @api_key
|
35
|
+
@secret_key = options[:secret_key]
|
36
|
+
@site_id = options[:site_id]
|
37
|
+
@username = options[:username] if options.has_key?('username')
|
38
|
+
|
39
|
+
return self
|
40
|
+
end
|
41
|
+
|
42
|
+
def get_public_host_id(private_host_id = nil, site_user_id = nil)
|
43
|
+
response = self.class.get("/host/id/public", :query =>
|
44
|
+
preprocess_options({:private_host_id=>private_host_id,:site_user_id=>site_user_id}))
|
45
|
+
end
|
46
|
+
|
47
|
+
def get_private_host_id(public_host_id = nil)
|
48
|
+
response = self.class.get("/host/id/private", :query => preprocess_options({:public_host_id=>public_host_id}))
|
49
|
+
end
|
50
|
+
|
51
|
+
def create_session(username = nil, fme_key = nil, is_video_private = nil, public_host_id = nil, site_user_id = nil)
|
52
|
+
response = self.class.post("/session/create", :query=>preprocess_options({:username=>username,
|
53
|
+
:is_video_private=>is_video_private, :public_host_id=>public_host_id, :site_user_id=>site_user_id}))
|
54
|
+
end
|
55
|
+
|
56
|
+
def create_user(username)
|
57
|
+
response = self.class.post("/session/create", :query => preprocess_options({:username => username}))
|
58
|
+
end
|
59
|
+
|
60
|
+
def get_live_session_status(public_host_id)
|
61
|
+
response = self.class.post("/session/live", :query => preprocess_options({:public_host_id => public_host_id}))
|
62
|
+
end
|
63
|
+
|
64
|
+
def list_recorded_videos()
|
65
|
+
recorded_videos = []
|
66
|
+
response = self.class.get("/video/list", :query => preprocess_options)
|
67
|
+
# iterate videos
|
68
|
+
end
|
69
|
+
|
70
|
+
def list_themes()
|
71
|
+
themes = []
|
72
|
+
response = self.class.get("/theme/list", :query => preprocess_options)
|
73
|
+
# iterate themes
|
74
|
+
end
|
75
|
+
|
76
|
+
def list_live_sessions()
|
77
|
+
live_sessions = []
|
78
|
+
response = self.class.get("/session/live/list", :query => preprocess_options)
|
79
|
+
# iterate results
|
80
|
+
end
|
81
|
+
|
82
|
+
def preprocess_options(options=nil)
|
83
|
+
options = {} if options = {} || options.nil?
|
84
|
+
options['key'] = self.api_key
|
85
|
+
rid = (Time.now.to_f * 1000).ceil
|
86
|
+
options['site_user_id'] = self.site_user_id if self.site_user_id
|
87
|
+
options['username'] = self.username if self.username
|
88
|
+
options['sig'] = Client.sign(options,self.secret_key, rid)
|
89
|
+
options['rid'] = rid
|
90
|
+
options
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.sign(options,secret,rid)
|
94
|
+
options.delete_if{ options.has_key?('sig') }
|
95
|
+
MD5.hexdigest(options.sort().collect{|v| v[1]}.join+secret+rid.to_s)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module StreamAPI
|
2
|
+
class Embed
|
3
|
+
|
4
|
+
def self.to_html(private_host_id, public_host_id, site_id, theme)
|
5
|
+
embed_code = <<-EOF
|
6
|
+
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
|
7
|
+
codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"
|
8
|
+
width="#{theme['width']}" height="#{theme['height']}" id="liveStream" align="">
|
9
|
+
<PARAM name="movie" value="http://static.streamapi.com/flash/loader.swf?app=custom.swf&1247246891974">
|
10
|
+
<PARAM name="FlashVars" value="siteID=#{site_id}&publicHostID=#{public_host_id}
|
11
|
+
&layoutPath=#{theme['layout_path']}
|
12
|
+
&skinPath=#{theme['skin_path']}
|
13
|
+
&privateHostID=#{theme['private_host_id']}&userType=host&">
|
14
|
+
<PARAM name="allowScriptAccess" value="always">
|
15
|
+
<PARAM name="allowFullScreen" value="true">
|
16
|
+
<PARAM name="quality" value="high">
|
17
|
+
<PARAM name="bgcolor" value="#000000">
|
18
|
+
<PARAM name="scale" value="noscale">
|
19
|
+
<PARAM name="wmode" value="transparent">
|
20
|
+
<embed src="http://static.streamapi.com/flash/loader.swf?app=custom.swf&1247246891974"
|
21
|
+
FlashVars="siteID=#{site_id}&publicHostID=#{public_host_id}
|
22
|
+
&layoutPath=#{theme['layout_path']}
|
23
|
+
&skinPath=#{theme['skin_path']}
|
24
|
+
&privateHostID=#{theme['private_host_id']}&userType=host&"
|
25
|
+
allowScriptAccess="always" allowFullScreen="true" width="#{theme['width']}" height="#{theme['height']}" scale="noscale"
|
26
|
+
wmode="transparent" quality="high" bgcolor="#000000" type="application/x-shockwave-flash" >
|
27
|
+
</embed>
|
28
|
+
</OBJECT>
|
29
|
+
<div id="player_container"></div>
|
30
|
+
|
31
|
+
<script type="text/javascript"
|
32
|
+
src="http://ajax.googleapis.com/ajax/libs/swfobject/2.1/swfobject.js"></script>
|
33
|
+
|
34
|
+
<script type="text/javascript">
|
35
|
+
swfobject.embedSWF("http://static.streamapi.com/flash/loader.swf", "player_container",
|
36
|
+
"#{theme['width']}", "#{theme['height']}", "9", "", {
|
37
|
+
'app' : 'custom.swf',
|
38
|
+
'siteID' : '#{site_id}',
|
39
|
+
'publicHostID' : '#{public_host_id}',
|
40
|
+
'layoutPath' : '#{theme['layout_path']}',
|
41
|
+
'skinPath' : '#{theme['skin_path']}',
|
42
|
+
'privateHostID' : '#{theme['private_host_id']}',
|
43
|
+
'userType' : 'host'
|
44
|
+
}, {
|
45
|
+
allowfullscreen: "true",
|
46
|
+
allowscriptaccess: "true"
|
47
|
+
});
|
48
|
+
</script type="text/javascript">
|
49
|
+
EOF
|
50
|
+
|
51
|
+
embed_code
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
data/lib/streamapi.rb
ADDED
data/streamapi.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "streamapi/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "streamapi"
|
7
|
+
s.version = Streamapi::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Panagiotis Papadoulos"]
|
10
|
+
s.email = ["panosjee@gmail.com"]
|
11
|
+
s.homepage = "http://rubygems.org/gems/streamapi"
|
12
|
+
s.summary = %q{A simple Ruby client for the StreamAPI api}
|
13
|
+
s.description = %q{StreamAPI is the easiest and most cost effective way to incorporate live streaming video into your website or application.}
|
14
|
+
|
15
|
+
s.rubyforge_project = "streamapi"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: streamapi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Panagiotis Papadoulos
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-11-04 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: StreamAPI is the easiest and most cost effective way to incorporate live streaming video into your website or application.
|
22
|
+
email:
|
23
|
+
- panosjee@gmail.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- .gitignore
|
32
|
+
- Gemfile
|
33
|
+
- README.rdoc
|
34
|
+
- Rakefile
|
35
|
+
- lib/streamapi.rb
|
36
|
+
- lib/streamapi/client.rb
|
37
|
+
- lib/streamapi/embed.rb
|
38
|
+
- lib/streamapi/version.rb
|
39
|
+
- streamapi.gemspec
|
40
|
+
has_rdoc: true
|
41
|
+
homepage: http://rubygems.org/gems/streamapi
|
42
|
+
licenses: []
|
43
|
+
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
version: "0"
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project: streamapi
|
68
|
+
rubygems_version: 1.3.7
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: A simple Ruby client for the StreamAPI api
|
72
|
+
test_files: []
|
73
|
+
|