Last active
July 14, 2020 22:26
-
-
Save abelorian/4b32139450ab13bbbb2888df06a0503c to your computer and use it in GitHub Desktop.
[RUBY] Mediastream API example + HTTP.rb Gem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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