wowza 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fba0dab1d8179f126f3c21bcdd1819bc785dceb1
4
+ data.tar.gz: 72f9a530308f2cbd9ca804af16c0f9efb48eedfd
5
+ SHA512:
6
+ metadata.gz: 2fa91e6d9822f9068f7334772a567319558c8b2cbaf46af6b5a884adac85b0115842d273d45c0430c9a8afa9f693918ff8e541d005ce1626b883d11bf7ccfef4
7
+ data.tar.gz: ef8cfb21230d5aada514e082c9eb9bb55d46f592b9798c6425ad9a4a44eac39b9b7441c0671f5c4d308834ced49fd40310ec04b9b778144ff5f204c05238787c
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at chase@code0100fun.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+ ruby '2.2.2'
3
+
4
+ # Specify your gem's dependencies in wowza.gemspec
5
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Chase McCarthy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,74 @@
1
+ # Wowza
2
+
3
+ Ruby wrapper around the Wowza REST API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'wowza'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install wowza
20
+
21
+ ## Usage
22
+
23
+ **Note: the server has to have the API enabled (in config/Server.xml) and the port (default 8087) allowed.**
24
+
25
+ Create server:
26
+
27
+ ```ruby
28
+ server = Wowza::REST::Server.new(host: 'example.com', port: 8087)
29
+ ```
30
+
31
+ Connect as client:
32
+
33
+ ```ruby
34
+ client = server.connect(username: 'foo', password: 'bar')
35
+ ```
36
+
37
+ List of all publishers:
38
+
39
+ ```ruby
40
+ publishers = client.publishers.all
41
+ ```
42
+
43
+ Update a publisher:
44
+
45
+ ```ruby
46
+ publisher = publishers.first
47
+ publisher.name = 'otherName'
48
+ publisher.save
49
+ ```
50
+
51
+ Create a publisher
52
+
53
+ ```ruby
54
+ publisher = Wowza::REST::Publisher.new(name: 'channel', password: '321')
55
+ publisher.conn = client.connection
56
+ publisher.save
57
+ ```
58
+
59
+ ## Development
60
+
61
+ Run `ruby bin/console` to connect to a development server.
62
+
63
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
64
+
65
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
66
+
67
+ ## Contributing
68
+
69
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hashrocket/wowza. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
70
+
71
+
72
+ ## License
73
+
74
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "wowza"
5
+ require "pry"
6
+
7
+ server = Wowza::REST::Server.new(host: 'example.com', port: 8087)
8
+ client = server.connect(username: 'username', password: 'password')
9
+ conn = client.connection
10
+ publishers = client.publishers.all
11
+ application = Wowza::REST::Application.new id: 'live', conn: conn
12
+ streams = application.instances.all.first.incoming_streams
13
+
14
+ stream_by_name = Wowza::REST::Stream.find_by name: 'Snowboarding', app_id: 'live', conn: conn
15
+
16
+ group = Wowza::REST::StreamGroup.find_by stream_name: 'Snowboarding', app_id: 'live', conn: conn
17
+ stream_by_group = group.streams.first
18
+
19
+ binding.pry;
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,25 @@
1
+ require 'wowza/version'
2
+ require 'base64'
3
+ require 'json'
4
+ require 'indifference' unless defined?(ActiveSupport)
5
+ require 'assignment'
6
+ require 'net/http/digest_auth'
7
+
8
+ require 'wowza/will_change'
9
+
10
+ require 'wowza/rest/publishers'
11
+ require 'wowza/rest/publisher'
12
+ require 'wowza/rest/authentication'
13
+ require 'wowza/rest/connection'
14
+ require 'wowza/rest/server'
15
+ require 'wowza/rest/status_parser'
16
+ require 'wowza/rest/client'
17
+ require 'wowza/rest/applications'
18
+ require 'wowza/rest/application'
19
+ require 'wowza/rest/instances'
20
+ require 'wowza/rest/instance'
21
+ require 'wowza/rest/stream'
22
+ require 'wowza/rest/stream_group'
23
+
24
+ module Wowza
25
+ end
@@ -0,0 +1,62 @@
1
+ module Wowza
2
+ module REST
3
+ class Application
4
+
5
+ include Assignment::Attributes
6
+
7
+ attr_accessor :id, :href, :app_type, :dvr_enabled, :drm_enabled,
8
+ :transcoder_enabled, :stream_targets_enabled,
9
+ :server_name, :vhost_name, :conn
10
+
11
+ def initialize(attributes={})
12
+ assign_attributes(attributes) if attributes
13
+ super()
14
+ end
15
+
16
+ def attributes
17
+ {
18
+ id: id,
19
+ href: href,
20
+ app_type: app_type,
21
+ dvr_enabled: dvr_enabled,
22
+ drm_enabled: drm_enabled,
23
+ transcoder_enabled: transcoder_enabled,
24
+ stream_targets_enabled: stream_targets_enabled,
25
+ }
26
+ end
27
+
28
+ def instances
29
+ Instances.new(conn, self)
30
+ end
31
+
32
+ def href
33
+ if !@href && resource_path
34
+ resource_path
35
+ else
36
+ @href
37
+ end
38
+ end
39
+
40
+ def resource_path
41
+ id && "#{vhost_path}/applications/#{id}"
42
+ end
43
+
44
+ def server_name
45
+ @server_name || "_defaultServer_"
46
+ end
47
+
48
+ def server_path
49
+ "/v2/servers/#{server_name}"
50
+ end
51
+
52
+ def vhost_name
53
+ @vhost_name || "_defaultVHost_"
54
+ end
55
+
56
+ def vhost_path
57
+ "#{server_path}/vhosts/#{vhost_name}"
58
+ end
59
+
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,31 @@
1
+ module Wowza
2
+ module REST
3
+ class Applications
4
+
5
+ def initialize(conn)
6
+ @conn = conn
7
+ end
8
+
9
+ def all
10
+ resp = conn.get('/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications')
11
+ JSON.parse(resp.body)['applications'].map do |attrs|
12
+ Application.new({
13
+ id: attrs["id"],
14
+ href: attrs["href"],
15
+ app_type: attrs["appType"],
16
+ dvr_enabled: attrs["dvrEnabled"],
17
+ drm_enabled: attrs["drmEnabled"],
18
+ transcoder_enabled: attrs["transcoderEnabled"],
19
+ stream_targets_enabled: attrs["streamTargetsEnabled"],
20
+ }).tap do |app|
21
+ app.conn = conn
22
+ end
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ attr_reader :conn
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,6 @@
1
+ module Wowza
2
+ module REST
3
+ class Authentication < Struct.new(:username, :password)
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,43 @@
1
+ module Wowza
2
+ module REST
3
+ class Client
4
+
5
+ attr_reader :server_name, :connection
6
+
7
+ def initialize(connection)
8
+ @connection = connection
9
+ end
10
+
11
+ def publishers
12
+ Publishers.new(connection)
13
+ end
14
+
15
+ def applications
16
+ Applications.new(connection)
17
+ end
18
+
19
+ def status
20
+ StatusParser.new.parse(get_json(status_path))
21
+ end
22
+
23
+ def status_path
24
+ "#{server_path}/status"
25
+ end
26
+
27
+ def server_name
28
+ @server_name || "_defaultServer_"
29
+ end
30
+
31
+ def server_path
32
+ "/v2/servers/#{server_name}"
33
+ end
34
+
35
+ private
36
+
37
+ def get_json(path)
38
+ JSON.parse(connection.get(path).body)
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,76 @@
1
+ module Wowza
2
+ module REST
3
+ class Connection
4
+
5
+ attr_reader :uri, :auth
6
+
7
+ def initialize(uri, auth)
8
+ @auth = auth
9
+ @uri = uri
10
+ end
11
+
12
+ def get(path, query={}, &block)
13
+ request_method(:get, path, query, &block)
14
+ end
15
+
16
+ def post(path, query={}, &block)
17
+ request_method(:post, path, query, &block)
18
+ end
19
+
20
+ def put(path, query={}, &block)
21
+ request_method(:put, path, query, &block)
22
+ end
23
+
24
+ def delete(path, query={}, &block)
25
+ request_method(:delete, path, query, &block)
26
+ end
27
+
28
+ private
29
+
30
+ def request_method(method, path, query, &block)
31
+ full_uri = URI.join(uri, path)
32
+ request(method, full_uri, query, &block)
33
+ end
34
+
35
+ def start(uri, &block)
36
+ Net::HTTP.start( uri.host, uri.port,
37
+ use_ssl: uri.scheme == 'https', &block)
38
+ end
39
+
40
+ REQUEST_TYPES = {
41
+ get: Net::HTTP::Get,
42
+ post: Net::HTTP::Post,
43
+ put: Net::HTTP::Put,
44
+ delete: Net::HTTP::Delete,
45
+ }
46
+
47
+ def request(method, uri, query)
48
+ start(uri) do |http|
49
+ req = REQUEST_TYPES[method].new uri, query
50
+ req["Content-Type"] = "application/json"
51
+ req["Accept"] = "application/json"
52
+ yield(req) if block_given?
53
+ res = http.request req
54
+ if res.code == "401"
55
+ auth = digest_auth(req, res)
56
+ req["Authorization"] = auth
57
+ http.request req
58
+ else
59
+ res
60
+ end
61
+ end
62
+ end
63
+
64
+ def digest_auth(req, res)
65
+ uri = req.uri
66
+ uri.user = auth.username
67
+ uri.password = auth.password
68
+
69
+ realm = res['www-authenticate']
70
+ method = req.method.upcase
71
+ Net::HTTP::DigestAuth.new.auth_header(uri, realm, method)
72
+ end
73
+
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,22 @@
1
+ module Wowza
2
+ module REST
3
+ class Instance
4
+
5
+ include Assignment::Attributes
6
+
7
+ attr_accessor :incoming_streams, :name, :conn
8
+
9
+ def initialize(attributes={})
10
+ assign_attributes(attributes) if attributes
11
+ super()
12
+ end
13
+
14
+ def attributes
15
+ {
16
+ name: name
17
+ }
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,30 @@
1
+ module Wowza
2
+ module REST
3
+ class Instances
4
+
5
+ def initialize(conn, application)
6
+ @conn = conn
7
+ @application = application
8
+ end
9
+
10
+ def all
11
+ resp = conn.get("#{application.href}/instances")
12
+ JSON.parse(resp.body)['instanceList'].map do |attrs|
13
+ instance = Instance.new({
14
+ name: attrs["name"]
15
+ })
16
+ streams = attrs.fetch("incomingStreams", [])
17
+ instance.incoming_streams = streams.map do |stream|
18
+ attrs = Stream.deserialize(stream)
19
+ Stream.new(attrs.merge({ conn: conn }))
20
+ end
21
+ instance
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ attr_reader :conn, :application
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,117 @@
1
+ module Wowza
2
+ module REST
3
+ class Publisher
4
+
5
+ include Assignment::Attributes
6
+ include Wowza::WillChange
7
+
8
+ attr_accessor :name, :password, :server_name, :persisted, :conn
9
+ track_changes :name, :password, :server_name
10
+
11
+ def initialize(attributes={})
12
+ assign_attributes(attributes) if attributes
13
+ super()
14
+ self.persisted = false
15
+ changes_applied
16
+ end
17
+
18
+ def attributes
19
+ {
20
+ name: name,
21
+ password: password,
22
+ }
23
+ end
24
+
25
+ def to_json
26
+ attributes.to_json
27
+ end
28
+
29
+ def id
30
+ if changes[:name].nil?
31
+ name
32
+ else
33
+ changes[:name].first
34
+ end
35
+ end
36
+
37
+ def save
38
+ resp = conn.send(persist_method, persist_path) do |req|
39
+ req.body = to_json
40
+ end
41
+ if resp.code == "201" || resp.code == "200"
42
+ self.persisted = true
43
+ end
44
+ changes_applied
45
+ end
46
+
47
+ def persisted=(persisted)
48
+ @persisted = persisted
49
+ if persisted
50
+ changes_applied
51
+ end
52
+ end
53
+
54
+ def persisted?
55
+ persisted
56
+ end
57
+
58
+ def name=(newName)
59
+ will_change! :name unless newName == @name
60
+ @name = newName
61
+ end
62
+
63
+ def password=(newPassword)
64
+ will_change! :password unless newPassword == @password
65
+ @password = newPassword
66
+ end
67
+
68
+ def reload!
69
+ resp = conn.get resource_path
70
+ attributes = JSON.parse(resp.body)
71
+ assign_attributes(attributes) if attributes
72
+ clear_changes_information
73
+ end
74
+
75
+ def rollback!
76
+ restore_attributes
77
+ end
78
+
79
+ def destroy
80
+ if persisted?
81
+ resp = conn.delete resource_path
82
+ if resp.code == "204"
83
+ self.persisted = false
84
+ clear_changes_information
85
+ end
86
+ end
87
+ end
88
+
89
+ def server_name
90
+ @server_name || "_defaultServer_"
91
+ end
92
+
93
+ private
94
+
95
+ def persist_method
96
+ persisted? ? :put : :post
97
+ end
98
+
99
+ def resource_path
100
+ "#{server_path}/publishers/#{id}"
101
+ end
102
+
103
+ def resources_path
104
+ "#{server_path}/publishers"
105
+ end
106
+
107
+ def persist_path
108
+ persisted? ? resource_path : resources_path
109
+ end
110
+
111
+ def server_path
112
+ "/v2/servers/#{server_name}"
113
+ end
114
+
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,51 @@
1
+ module Wowza
2
+ module REST
3
+ class Publishers
4
+
5
+ attr_accessor :server_name
6
+
7
+ def initialize(conn)
8
+ @conn = conn
9
+ end
10
+
11
+ def all
12
+ resp = conn.get(resource_path)
13
+ JSON.parse(resp.body)['publishers'].map do |attrs|
14
+ Publisher.new(name: attrs["name"]).tap do |p|
15
+ p.conn = conn
16
+ p.persisted = true
17
+ end
18
+ end
19
+ end
20
+
21
+ def find(name)
22
+ resp = conn.get("#{resource_path}/#{name}")
23
+ if resp.code == "200"
24
+ attrs = JSON.parse(resp.body)
25
+ Publisher.new(name: attrs["name"]).tap do |p|
26
+ p.conn = conn
27
+ p.persisted = true
28
+ end
29
+ else
30
+ nil
31
+ end
32
+ end
33
+
34
+ def resource_path
35
+ "#{server_path}/publishers"
36
+ end
37
+
38
+ def server_name
39
+ @server_name || "_defaultServer_"
40
+ end
41
+
42
+ def server_path
43
+ "/v2/servers/#{server_name}"
44
+ end
45
+
46
+ private
47
+
48
+ attr_reader :conn
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,19 @@
1
+ module Wowza
2
+ module REST
3
+ class Server
4
+
5
+ attr_reader :uri
6
+
7
+ def initialize(host:, port:)
8
+ @uri = URI("http://#{host}:#{port}")
9
+ end
10
+
11
+ def connect(username:, password:)
12
+ auth = Authentication.new(username, password)
13
+ conn = Connection.new(uri, auth)
14
+ Client.new(conn)
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,65 @@
1
+ module Wowza
2
+ module REST
3
+ class StatusParser
4
+
5
+ def parse(hash)
6
+ hash = hash.with_indifferent_access
7
+ {
8
+ version: hash["version"],
9
+ total_memory: hash["totalMemory"],
10
+ processor_cores: hash["processorCores"],
11
+ gpu_acceleration: hash["gpuAcceleration"],
12
+ time_running: hash["timeRunning"],
13
+ current_connections: hash["currentConnections"],
14
+ max_connections: hash["maxConnections"],
15
+ max_incoming_streams: hash["maxIncomingStreams"],
16
+ rest_api_available: hash["restAPIAvailable"],
17
+ http_origin: hash["httpOrigin"],
18
+ native_base: hash["nativeBase"],
19
+ wse_name: hash["wseName"],
20
+ transcoder: {
21
+ licenses: hash["transcoderLicenses"],
22
+ licenses_in_use: hash["transcoderLicensesInUse"],
23
+ applications: hash["transcoderApplications"],
24
+ },
25
+ dvr: {
26
+ licensed: hash["dvrLicensed"],
27
+ in_use: hash["dvrInUse"],
28
+ applications: hash["dvrApplications"],
29
+ },
30
+ drm: {
31
+ licensed: hash["drmLicensed"],
32
+ in_use: hash["drmInUse"],
33
+ applications: hash["drmApplications"],
34
+ },
35
+ server: {
36
+ name: hash["serverName"],
37
+ version: hash["serverVersion"],
38
+ build: hash["serverBuild"],
39
+ mode: hash["serverMode"],
40
+ },
41
+ license: {
42
+ type: hash["licenseType"],
43
+ expire_date: hash["licenseExpireDate"],
44
+ },
45
+ os: {
46
+ name: hash["osName"],
47
+ version: hash["osVersion"],
48
+ architecture: hash["osArchitecture"],
49
+ bitness: hash["osBitness"],
50
+ },
51
+ java: {
52
+ version: hash["javaVersion"],
53
+ vm_version: hash["javaVMVersion"],
54
+ bitness: hash["javaBitness"],
55
+ name: hash["javaName"],
56
+ vendor: hash["javaVendor"],
57
+ home: hash["javaHome"],
58
+ max_heap_size: hash["javaMaxHeapSize"],
59
+ }
60
+ }
61
+ end
62
+
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,109 @@
1
+ module Wowza
2
+ module REST
3
+ class Stream
4
+
5
+ include Assignment::Attributes
6
+
7
+ attr_accessor :name, :is_connected, :is_recording, :source_ip,
8
+ :server_name, :app_id, :vhost_name, :instance_name, :conn
9
+
10
+ def self.deserialize(attrs)
11
+ attrs = attrs.with_indifferent_access
12
+ {
13
+ name: attrs["name"],
14
+ is_connected: attrs["isConnected"],
15
+ is_recording: attrs["isRecordingSet"],
16
+ source_ip: attrs["sourceIp"],
17
+ }
18
+ end
19
+
20
+ def self.find_by(attrs)
21
+ new(attrs).reload!
22
+ end
23
+
24
+ def initialize(attributes={})
25
+ assign_attributes(attributes) if attributes
26
+ super()
27
+ end
28
+
29
+ def attributes
30
+ {
31
+ name: name,
32
+ is_connected: is_connected,
33
+ is_recording: is_recording,
34
+ source_ip: source_ip
35
+ }
36
+ end
37
+
38
+ def is_connected
39
+ @is_connected || false
40
+ end
41
+
42
+ def connected?
43
+ is_connected
44
+ end
45
+
46
+ def is_recording
47
+ @is_recording || false
48
+ end
49
+
50
+ def recording?
51
+ is_recording
52
+ end
53
+
54
+ def reload!
55
+ resp = conn.get resource_path
56
+ attrs = JSON.parse(resp.body)
57
+ assign_attributes(self.class.deserialize(attrs)) if attrs
58
+ self
59
+ end
60
+
61
+ def name=(name)
62
+ unless name.nil?
63
+ @name = name
64
+ end
65
+ end
66
+
67
+ def resource_path
68
+ "#{instance_path}/incomingstreams/#{id}"
69
+ end
70
+
71
+ def server_name
72
+ @server_name || "_defaultServer_"
73
+ end
74
+
75
+ def server_path
76
+ "/v2/servers/#{server_name}"
77
+ end
78
+
79
+ def vhost_name
80
+ @vhost_name || "_defaultVHost_"
81
+ end
82
+
83
+ def vhost_path
84
+ "#{server_path}/vhosts/#{vhost_name}"
85
+ end
86
+
87
+ def app_id
88
+ @app_id || 'live'
89
+ end
90
+
91
+ def application_path
92
+ "#{vhost_path}/applications/#{app_id}"
93
+ end
94
+
95
+ def instance_name
96
+ @instance_name || "_definst_"
97
+ end
98
+
99
+ def instance_path
100
+ "#{application_path}/instances/#{instance_name}"
101
+ end
102
+
103
+ def id
104
+ name
105
+ end
106
+
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,128 @@
1
+ module Wowza
2
+ module REST
3
+ class StreamGroup
4
+
5
+ include Assignment::Attributes
6
+
7
+ attr_accessor :stream_name, :name, :is_transcode_result, :members,
8
+ :server_name, :app_id, :vhost_name, :instance_name, :conn
9
+
10
+ def self.deserialize(attrs)
11
+ attrs = attrs.with_indifferent_access
12
+ {
13
+ name: attrs["groupName"],
14
+ is_transcode_result: attrs["isTranscodeResult"],
15
+ instance_name: attrs["instanceName"],
16
+ server_name: attrs["serverName"],
17
+ members: attrs["members"],
18
+ }
19
+ end
20
+
21
+ def self.find_by(attrs)
22
+ new(attrs).reload!
23
+ end
24
+
25
+ def initialize(attributes={})
26
+ assign_attributes(attributes) if attributes
27
+ super()
28
+ end
29
+
30
+ def attributes
31
+ {
32
+ name: name,
33
+ is_connected: is_connected,
34
+ is_recording: is_recording,
35
+ source_ip: source_ip
36
+ }
37
+ end
38
+
39
+ def is_connected
40
+ @is_connected || false
41
+ end
42
+
43
+ def connected?
44
+ is_connected
45
+ end
46
+
47
+ def is_recording
48
+ @is_recording || false
49
+ end
50
+
51
+ def recording?
52
+ is_recording
53
+ end
54
+
55
+ def reload!
56
+ resp = conn.get resource_path
57
+ attrs = JSON.parse(resp.body)
58
+ assign_attributes(self.class.deserialize(attrs)) if attrs
59
+ self
60
+ end
61
+
62
+ def name=(name)
63
+ unless name.nil?
64
+ @name = name
65
+ end
66
+ end
67
+
68
+ def stream_name=(name)
69
+ self.name = "#{name}_all"
70
+ @stream_name = name
71
+ end
72
+
73
+ def resource_path
74
+ "#{instance_path}/streamgroups/#{id}"
75
+ end
76
+
77
+ def server_name
78
+ @server_name || "_defaultServer_"
79
+ end
80
+
81
+ def server_path
82
+ "/v2/servers/#{server_name}"
83
+ end
84
+
85
+ def vhost_name
86
+ @vhost_name || "_defaultVHost_"
87
+ end
88
+
89
+ def vhost_path
90
+ "#{server_path}/vhosts/#{vhost_name}"
91
+ end
92
+
93
+ def app_id
94
+ @app_id || 'live'
95
+ end
96
+
97
+ def application_path
98
+ "#{vhost_path}/applications/#{app_id}"
99
+ end
100
+
101
+ def instance_name
102
+ @instance_name || "_definst_"
103
+ end
104
+
105
+ def instance_path
106
+ "#{application_path}/instances/#{instance_name}"
107
+ end
108
+
109
+ def id
110
+ name
111
+ end
112
+
113
+ def streams
114
+ (members || []).map do |stream_name|
115
+ Stream.new({
116
+ name: stream_name,
117
+ app_id: app_id,
118
+ server_name: server_name,
119
+ vhost_name: vhost_name,
120
+ instance_name: instance_name,
121
+ conn: conn
122
+ })
123
+ end
124
+ end
125
+
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,3 @@
1
+ module Wowza
2
+ VERSION = "0.0.3"
3
+ end
@@ -0,0 +1,89 @@
1
+ module Wowza
2
+ module WillChange
3
+
4
+ def self.included(host)
5
+ def host.track_changes(*attrs)
6
+ attrs.each { |attr| track_change(attr) }
7
+ end
8
+
9
+ def host.track_change(attr)
10
+ define_method(:will_change!) do |attr|
11
+ attribute_will_change!(attr)
12
+ end
13
+ end
14
+ end
15
+
16
+ def changed?
17
+ !changed_attributes.empty?
18
+ end
19
+
20
+ def changed
21
+ changed_attributes.keys
22
+ end
23
+
24
+ def changes
25
+ Hash[changed.map { |attr| [attr, attribute_change(attr)] }]
26
+ end
27
+
28
+ def changed_attributes
29
+ @changed_attributes ||= {}
30
+ end
31
+
32
+ def restore_attributes(attributes = changed)
33
+ attributes.each { |attr| restore_attribute! attr }
34
+ end
35
+
36
+ private
37
+
38
+ def changes_include?(attr_name)
39
+ changed_attributes.include?(attr_name)
40
+ end
41
+
42
+ def changes_applied
43
+ clear_changes_information
44
+ end
45
+
46
+ def clear_changes_information
47
+ @changed_attributes = {}
48
+ end
49
+
50
+ def attribute_change(attr)
51
+ [changed_attributes[attr], send(attr)] if attribute_changed?(attr)
52
+ end
53
+
54
+ def attribute_previous_change(attr)
55
+ previous_changes[attr] if attribute_previously_changed?(attr)
56
+ end
57
+
58
+ def attribute_will_change!(attr)
59
+ return if attribute_changed?(attr)
60
+
61
+ begin
62
+ value = __send__(attr)
63
+ value = value.duplicable? ? value.clone : value
64
+ rescue TypeError, NoMethodError
65
+ end
66
+
67
+ set_attribute_was(attr, value)
68
+ end
69
+
70
+ def restore_attribute!(attr)
71
+ if attribute_changed?(attr)
72
+ send("#{attr}=", changed_attributes[attr])
73
+ clear_attribute_changes([attr])
74
+ end
75
+ end
76
+
77
+ def attribute_changed?(attr)
78
+ changes_include?(attr)
79
+ end
80
+
81
+ def set_attribute_was(attr, old_value)
82
+ changed_attributes[attr] = old_value
83
+ end
84
+
85
+ def clear_attribute_changes(attributes)
86
+ changed_attributes.except!(*attributes)
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'wowza/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "wowza"
8
+ spec.version = Wowza::VERSION
9
+ spec.authors = ["Chase McCarthy"]
10
+ spec.email = ["chase@code0100fun.com"]
11
+
12
+ spec.summary = %q{Wowza REST API wrapper}
13
+ spec.description = %q{Wowza REST API wrapper. ALPHA!}
14
+ spec.homepage = "https://github.com/hashrocket/wowza"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.11"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_development_dependency "mock5", "~> 1.0.8", ">= 1.0.8"
26
+ spec.add_development_dependency "pry", "~> 0"
27
+
28
+ spec.add_dependency "indifference", "~> 0.0.1"
29
+ spec.add_dependency "assignment", "~> 0.0.1"
30
+ spec.add_dependency "net-http-digest_auth", "~> 1.4"
31
+ end
metadata ADDED
@@ -0,0 +1,189 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wowza
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Chase McCarthy
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-06-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mock5
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.8
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 1.0.8
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: 1.0.8
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 1.0.8
75
+ - !ruby/object:Gem::Dependency
76
+ name: pry
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: indifference
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: 0.0.1
96
+ type: :runtime
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: 0.0.1
103
+ - !ruby/object:Gem::Dependency
104
+ name: assignment
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: 0.0.1
110
+ type: :runtime
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: 0.0.1
117
+ - !ruby/object:Gem::Dependency
118
+ name: net-http-digest_auth
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '1.4'
124
+ type: :runtime
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '1.4'
131
+ description: Wowza REST API wrapper. ALPHA!
132
+ email:
133
+ - chase@code0100fun.com
134
+ executables: []
135
+ extensions: []
136
+ extra_rdoc_files: []
137
+ files:
138
+ - ".gitignore"
139
+ - ".rspec"
140
+ - ".travis.yml"
141
+ - CODE_OF_CONDUCT.md
142
+ - Gemfile
143
+ - LICENSE.txt
144
+ - README.md
145
+ - Rakefile
146
+ - bin/console
147
+ - bin/setup
148
+ - lib/wowza.rb
149
+ - lib/wowza/rest/application.rb
150
+ - lib/wowza/rest/applications.rb
151
+ - lib/wowza/rest/authentication.rb
152
+ - lib/wowza/rest/client.rb
153
+ - lib/wowza/rest/connection.rb
154
+ - lib/wowza/rest/instance.rb
155
+ - lib/wowza/rest/instances.rb
156
+ - lib/wowza/rest/publisher.rb
157
+ - lib/wowza/rest/publishers.rb
158
+ - lib/wowza/rest/server.rb
159
+ - lib/wowza/rest/status_parser.rb
160
+ - lib/wowza/rest/stream.rb
161
+ - lib/wowza/rest/stream_group.rb
162
+ - lib/wowza/version.rb
163
+ - lib/wowza/will_change.rb
164
+ - wowza.gemspec
165
+ homepage: https://github.com/hashrocket/wowza
166
+ licenses:
167
+ - MIT
168
+ metadata: {}
169
+ post_install_message:
170
+ rdoc_options: []
171
+ require_paths:
172
+ - lib
173
+ required_ruby_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ requirements: []
184
+ rubyforge_project:
185
+ rubygems_version: 2.4.6
186
+ signing_key:
187
+ specification_version: 4
188
+ summary: Wowza REST API wrapper
189
+ test_files: []