Module: Pili::API

Defined in:
lib/pili/api.rb

Class Method Summary collapse

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, options = {})
  url = "/streams"

  body = {
    :hub              => hub_name,
    :title            => options[:title],
    :publishKey       => options[:publish_key],
    :publishSecurity  => options[:publish_security] == "static" ? "static" : "dynamic",
    :clientIp         => options[: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, options = {})
  url = "/streams/#{stream_id}/segments"

  url += "?start=#{options[:start]}" if options[:start].is_a?(Fixnum)
  url += "&end=#{options[:end]}"     if options[:end].is_a?(Fixnum)
  url += "&limit=#{options[:limit]}" if options[: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, options = {})
  url = "/streams?hub=#{hub_name}"

  url += "&marker=#{options[:marker]}" unless Utils.blank?(options[:marker])
  url += "&limit=#{options[:limit]}"   if options[:limit].is_a?(Fixnum)
  url += "&title=#{options[:title]}"   unless Utils.blank?(options[: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, options = {})
  url = "/streams/" + stream_id + '/snapshot'

  body = {}
  body[:name]      = name
  body[:format]    = format
  body[:time]      = options[:time]
  body[:notifyUrl] = options[: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, options = {})
  url = "/streams/" + stream_id

  body = {}
  body[:publishKey]      = options[:publish_key]
  body[:publishSecurity] = options[:publish_security] == "static" ? "static" : "dynamic"
  body[:disabled]        = options[:disabled]

  body.delete_if { |k, v| v.nil? }

  Stream.new credentials, RPC.post(credentials, url, body)
end