Skip to content

Instantly share code, notes, and snippets.

@abelorian
Last active July 14, 2020 22:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abelorian/4b32139450ab13bbbb2888df06a0503c to your computer and use it in GitHub Desktop.
Save abelorian/4b32139450ab13bbbb2888df06a0503c to your computer and use it in GitHub Desktop.
[RUBY] Mediastream API example + HTTP.rb Gem
class Mediastream
API_KEY = 'da...'
API_URL = 'https://platform.mediastre.am/api/live-stream'
PROFILE = {
"enabled": true,
"profile": "720p",
"video_bitrate": 2000000,
"audio_bitrate": 96000,
"audio_codec": "mp4a.40.2",
"video_codec": "avc1.42001e",
"resolution": {"width": 1280, "height": 720},
"recording": false
}
CDN_ZONES = ["us"]
PROTOCOL = "rtmp"
def search id
client.get(API_URL, params: {id: id})
end
def create name
client.post(API_URL, json: {"name": name, "encodingProfiles": [PROFILE], "cdn_zones": CDN_ZONES, "preferred_protocol": PROTOCOL})
end
def online id, value # "true" || "false"
client.post("#{API_URL}/#{id}", json: {online: value})
end
def update id
client.post("#{API_URL}/#{id}", json: {"encodingProfiles": [PROFILE], "cdn_zones": CDN_ZONES})
end
def client
HTTP.headers("Content-Type" => "application/json").headers("X-API-Token" => API_KEY)
end
end
# Usage:
# md = Mediastream.new
# res = md.search("abc123").parse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment