Module: Pili::API
- Defined in:
- lib/pili/api.rb
Class Method Summary collapse
- .create_stream(credentials, hub_name, options = {}) ⇒ Object
- .delete_stream(credentials, stream_id) ⇒ Object
- .get_stream(credentials, stream_id) ⇒ Object
- .get_stream_segments(credentials, stream_id, options = {}) ⇒ Object
- .get_stream_status(credentials, stream_id) ⇒ Object
- .list_streams(credentials, hub_name, options = {}) ⇒ Object
- .save_stream_as(credentials, stream_id, name, format, start_time, end_time, notify_url = nil) ⇒ Object
- .snapshot(credentials, stream_id, name, format, options = {}) ⇒ Object
- .update_stream(credentials, stream_id, options = {}) ⇒ Object
Class Method Details
.create_stream(credentials, hub_name, options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/pili/api.rb', line 8 def create_stream(credentials, hub_name, = {}) url = "/streams" body = { :hub => hub_name, :title => [:title], :publishKey => [:publish_key], :publishSecurity => [:publish_security] == "static" ? "static" : "dynamic", :clientIp => [:client_ip] } body.delete_if { |k, v| v.nil? } Stream.new credentials, RPC.post(credentials, url, body) end |
.delete_stream(credentials, stream_id) ⇒ Object
68 69 70 71 |
# File 'lib/pili/api.rb', line 68 def delete_stream(credentials, stream_id) url = "/streams/" + stream_id RPC.delete(credentials, url) end |
.get_stream(credentials, stream_id) ⇒ Object
25 26 27 28 |
# File 'lib/pili/api.rb', line 25 def get_stream(credentials, stream_id) url = "/streams/" + stream_id Stream.new credentials, RPC.get(credentials, url) end |
.get_stream_segments(credentials, stream_id, options = {}) ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/pili/api.rb', line 74 def get_stream_segments(credentials, stream_id, = {}) url = "/streams/#{stream_id}/segments" url += "?start=#{[:start]}" if [:start].is_a?(Fixnum) url += "&end=#{[:end]}" if [:end].is_a?(Fixnum) url += "&limit=#{[:limit]}" if [:limit].is_a?(Fixnum) response = RPC.get(credentials, url) response["segments"] || [] end |
.get_stream_status(credentials, stream_id) ⇒ Object
48 49 50 51 |
# File 'lib/pili/api.rb', line 48 def get_stream_status(credentials, stream_id) url = "/streams/#{stream_id}/status" RPC.get(credentials, url) end |
.list_streams(credentials, hub_name, options = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/pili/api.rb', line 31 def list_streams(credentials, hub_name, = {}) url = "/streams?hub=#{hub_name}" url += "&marker=#{[:marker]}" unless Utils.blank?([:marker]) url += "&limit=#{[:limit]}" if [:limit].is_a?(Fixnum) url += "&title=#{[:title]}" unless Utils.blank?([:title]) streams = [] RPC.get(credentials, url)["items"].each do |item| streams << Stream.new(credentials, item) end streams end |
.save_stream_as(credentials, stream_id, name, format, start_time, end_time, notify_url = nil) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/pili/api.rb', line 86 def save_stream_as(credentials, stream_id, name, format, start_time, end_time, notify_url = nil) url = "/streams/" + stream_id + "/saveas" body = {} body[:name] = name body[:format] = format body[:start] = start_time body[:end] = end_time body[:notifyUrl] = notify_url body.delete_if { |k, v| v.nil? } RPC.post(credentials, url, body) end |
.snapshot(credentials, stream_id, name, format, options = {}) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/pili/api.rb', line 102 def snapshot(credentials, stream_id, name, format, = {}) url = "/streams/" + stream_id + '/snapshot' body = {} body[:name] = name body[:format] = format body[:time] = [:time] body[:notifyUrl] = [:notify_url] body.delete_if { |k, v| v.nil? } RPC.post(credentials, url, body) end |
.update_stream(credentials, stream_id, options = {}) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/pili/api.rb', line 54 def update_stream(credentials, stream_id, = {}) url = "/streams/" + stream_id body = {} body[:publishKey] = [:publish_key] body[:publishSecurity] = [:publish_security] == "static" ? "static" : "dynamic" body[:disabled] = [:disabled] body.delete_if { |k, v| v.nil? } Stream.new credentials, RPC.post(credentials, url, body) end |