Class: StreamAPI::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/streamapi/client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.

Raises:



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/streamapi/client.rb', line 28

def initialize(options={}) 
  raise(InvalidApiKeyError, "Missing api_key!") if options[:api_key].nil?
  raise(InvalidSecretKeyError, "Missing secret_key!") if options[:secret_key].nil?
  raise(InvalidSiteIdError, "Missing site_id!") if options[:site_id].nil?

  @api_key = options[:api_key]
  @@api_key = @api_key
  @secret_key = options[:secret_key]
  @site_id = options[:site_id]
  @username = options[:username] if options.has_key?('username')

  return self
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



26
27
28
# File 'lib/streamapi/client.rb', line 26

def api_key
  @api_key
end

#debugObject

Returns the value of attribute debug.



26
27
28
# File 'lib/streamapi/client.rb', line 26

def debug
  @debug
end

#secret_keyObject

Returns the value of attribute secret_key.



26
27
28
# File 'lib/streamapi/client.rb', line 26

def secret_key
  @secret_key
end

#site_idObject

Returns the value of attribute site_id.



26
27
28
# File 'lib/streamapi/client.rb', line 26

def site_id
  @site_id
end

#site_user_idObject

Returns the value of attribute site_user_id.



26
27
28
# File 'lib/streamapi/client.rb', line 26

def site_user_id
  @site_user_id
end

#timeoutObject

Returns the value of attribute timeout.



26
27
28
# File 'lib/streamapi/client.rb', line 26

def timeout
  @timeout
end

#usernameObject

Returns the value of attribute username.



26
27
28
# File 'lib/streamapi/client.rb', line 26

def username
  @username
end

Class Method Details

.sign(options, secret, rid) ⇒ Object



91
92
93
94
# File 'lib/streamapi/client.rb', line 91

def self.sign(options,secret,rid)
  options.delete_if{ options.has_key?('sig') }
  Digest::MD5.hexdigest(options.sort().collect{|v| v[1]}.join+secret+rid.to_s)
end

Instance Method Details

#create_session(username = nil, fme_key = nil, is_video_private = nil, public_host_id = nil, site_user_id = nil) ⇒ Object



51
52
53
54
# File 'lib/streamapi/client.rb', line 51

def create_session(username = nil, fme_key = nil, is_video_private = nil, public_host_id = nil, site_user_id = nil)
  response = self.class.post("/session/create", :query=>preprocess_options({:username=>username,
     :is_video_private=>is_video_private, :public_host_id=>public_host_id, :site_user_id=>site_user_id}))
end

#create_user(username) ⇒ Object



56
57
58
# File 'lib/streamapi/client.rb', line 56

def create_user(username)
  response = self.class.post("/session/create", :query => preprocess_options({:username => username}))
end

#get_live_session_status(public_host_id) ⇒ Object



60
61
62
# File 'lib/streamapi/client.rb', line 60

def get_live_session_status(public_host_id)
  response = self.class.post("/session/live", :query => preprocess_options({:public_host_id => public_host_id}))
end

#get_private_host_id(public_host_id = nil) ⇒ Object



47
48
49
# File 'lib/streamapi/client.rb', line 47

def get_private_host_id(public_host_id = nil)
  response = self.class.get("/host/id/private", :query => preprocess_options({:public_host_id=>public_host_id}))
end

#get_public_host_id(private_host_id = nil, site_user_id = nil) ⇒ Object



42
43
44
45
# File 'lib/streamapi/client.rb', line 42

def get_public_host_id(private_host_id = nil, site_user_id = nil)
  response = self.class.get("/host/id/public", :query => 
      preprocess_options({:private_host_id=>private_host_id,:site_user_id=>site_user_id}))
end

#list_live_sessionsObject



75
76
77
78
# File 'lib/streamapi/client.rb', line 75

def list_live_sessions()
  live_sessions = []
  response = self.class.get("/session/live/list", :query => preprocess_options)
end

#list_recorded_videosObject



64
65
66
67
68
# File 'lib/streamapi/client.rb', line 64

def list_recorded_videos()
  recorded_videos = []
  response = self.class.get("/video/list", :query => preprocess_options)
  # iterate videos
end

#list_themesObject



70
71
72
73
# File 'lib/streamapi/client.rb', line 70

def list_themes()
  themes = []
  response = self.class.get("/theme/list", :query => preprocess_options)
end

#preprocess_options(options = nil) ⇒ Object



80
81
82
83
84
85
86
87
88
89
# File 'lib/streamapi/client.rb', line 80

def preprocess_options(options=nil)
 options = {} if options = {} || options.nil?
 options['key'] = self.api_key
 rid = (Time.now.to_f * 1000).ceil
 options['site_user_id'] = self.site_user_id if self.site_user_id
 options['username'] = self.username if self.username
 options['sig'] = Client.sign(options,self.secret_key, rid)
 options['rid'] = rid
 options
end