licode 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9953777cef8274b2556ffcb79eb88b90184d10eb
4
+ data.tar.gz: 742d69f5e590ff87d28dc670349613d60c2ddeda
5
+ SHA512:
6
+ metadata.gz: 57ecae0683efbb1a705bc5b3988352d637eaa85d541d91906836a8975a268ad81feebb5a9c0c11e0bae3428d233b45362d1c34d8025606111b65e727d30767ea
7
+ data.tar.gz: 06fa9cff01f169121f0730fa504896e17aa197c23e26d4924f0afbd4736f9d268569edc221e1a51768b4ecf2db1396ce669de1505f13eb43b66e812a3d769c9b
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in licode-ruby-sdk.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Joshua Rountree
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,78 @@
1
+ # Licode Ruby SDK
2
+
3
+ The Licode gem is designed to help you interface with the Licode platform via server side code.
4
+ It is influenced by the original `nuveClient_ruby` found in the ging/licode repo but isn't a gem and isn't easy to include in your projects.
5
+
6
+ This also will be more up to date and testable.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'licode'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install licode
23
+
24
+ ## Usage
25
+
26
+ ### Initializing
27
+
28
+ Load the gem and initialize the `Licode::Nuve` object with your Licode `ServiceId`, `ServiceKey`, and `ServiceURL`.
29
+ Your service URL should be the server you have installed licode on either by `http://xxx.xxx.xxx.xxx:3000/` or if you reversed proxied via nginx. (but you know that... right?)
30
+
31
+ ```ruby
32
+ require "licode"
33
+
34
+ licode = Licode::Nuve.new "55b3f8d58591b4566af491ed", "18316", "http://my-licode-server:3000"
35
+ ```
36
+
37
+ ### Creating Rooms
38
+ Creating a room is done by the `Licode#create_room(name, options)` method. The `name` parameter is up to you. Pass in a hash or a unique identifier of your choosing to properly identify this room. The `room_id` method of the returned `Licode::Room` instance is usually recommended to be persisted to a store (ie. database) for usage later when creating user tokens.
39
+
40
+ ```ruby
41
+ # Creating a relayed (non-p2p) room.
42
+ room = licode.create_room('my-new-room', :p2p => false)
43
+
44
+ # Creating a p2p room which uses a TURN server to ensure proper connections between peers.
45
+ room = licode.create_room('my-new-room', :p2p => true)
46
+
47
+ # Store this room_id in the database for later generating user tokens.
48
+ room_id = room.room_id # 55b6549e0ff0f5c9551963c7
49
+ ```
50
+
51
+ ### Generating User Tokens
52
+ After creating a `Room`, your user's need a special unique `token` to connect to the room.
53
+ You may generate a token by either `licode.create_token(room_id,username,role)` or through an instance of `Licode::Room` after creating it either by `licode.create_room(name,options)` or `licode.client.get_room(room_id)`
54
+
55
+ ```ruby
56
+ # Create a Token from just a room_id (fetched from a database)
57
+ token = licode.create_token session_id, 'my-user-id-name', 'presenter'
58
+
59
+ # Create a Token from a room instance.
60
+ room = licode.create_room('my-new-room') # or with `licode.client.get_room` but access to client might be deprecated later.
61
+
62
+ token = room.create_token('my-user-id-name','presenter') # roles are configured on your server in `licode_config.json` and by default are `presenter`, `viewer`, or `viewerWithData`
63
+ ```
64
+
65
+ ## Development
66
+
67
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
68
+
69
+ 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).
70
+
71
+ ## Contributing
72
+
73
+ Bug reports and pull requests are welcome on GitHub at https://github.com/joshuairl/licode-ruby-sdk. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
74
+
75
+
76
+ ## License
77
+
78
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "licode/ruby/sdk"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ require "licode/version"
2
+ require "licode/nuve"
3
+ module Licode
4
+
5
+ end
@@ -0,0 +1,178 @@
1
+ require "httparty"
2
+ require "licode/exceptions"
3
+ require "active_support/inflector"
4
+ require 'base64'
5
+ require "openssl"
6
+ module Licode
7
+ # @private For internal use by the SDK.
8
+ class Client
9
+ include HTTParty
10
+
11
+ open_timeout 2
12
+
13
+ def initialize(service_id,service_key,service_url)
14
+ self.class.base_uri service_url
15
+ self.class.headers({
16
+ "User-Agent" => "licode-ruby-sdk/#{VERSION}",
17
+ "Content-Type" => "application/json"
18
+ })
19
+ @service_id = service_id
20
+ @service_key = service_key
21
+ @service_url = service_url
22
+ end
23
+
24
+ def get_rooms ()
25
+ response = self.class.get('/rooms', {
26
+ :headers => {
27
+ "Authorization" => mauth_header
28
+ }
29
+ })
30
+
31
+ case response.code
32
+ when 200
33
+ response
34
+ when 403
35
+ raise LicodeAuthenticationError, "Authentication failed while retrieving rooms. Service: #{@service_id}"
36
+ else
37
+ raise LicodeArchiveError, "The rooms could not be retrieved."
38
+ end
39
+ rescue StandardError => e
40
+ raise LicodeError, "Failed to connect to Licode. Response code: #{e.message}"
41
+ end
42
+
43
+ def create_room (name, options={})
44
+ response = self.class.post("/rooms", :body => {:name => name, :options => options}.to_json, :headers => {
45
+ "Authorization" => mauth_header
46
+ })
47
+ case response.code
48
+ when (200..300)
49
+ response
50
+ when 403
51
+ raise LicodeAuthenticationError, "Authentication failed while creating a room. Service: #{@service_id}"
52
+ else
53
+ raise LicodeError, "Failed to create room. Response code: #{response}"
54
+ end
55
+ rescue StandardError => e
56
+ raise LicodeError, "Failed to connect to Licode. Response code: #{e.message}"
57
+ end
58
+
59
+ def get_room (room)
60
+ response = self.class.get('/rooms/' + room, {
61
+ :headers => {
62
+ "Authorization" => mauth_header
63
+ }
64
+ })
65
+ rescue StandardError => e
66
+ raise LicodeError, "Failed to connect to Licode. Response code: #{e.message}"
67
+ end
68
+
69
+ def delete_room (room)
70
+ response = self.class.delete('/rooms/' + room, {
71
+ :headers => {
72
+ "Authorization" => mauth_header
73
+ }
74
+ })
75
+ rescue StandardError => e
76
+ raise LicodeError, "Failed to connect to Licode. Response code: #{e.message}"
77
+ end
78
+
79
+ def create_token(room, username, role)
80
+ response = self.class.post('/rooms/' + room + '/tokens', {
81
+ :headers => { "Authorization" => mauth_header(:username => username.to_s, :role => role) }
82
+ })
83
+ response
84
+ rescue StandardError => e
85
+ raise LicodeError, "Failed to connect to Licode. Response code: #{e.message}"
86
+ end
87
+
88
+ def create_service (name, key)
89
+ response = self.class.post('/services/',
90
+ :body => {'name' => name, 'key' => key},
91
+ :headers => {
92
+ "Authorization" => mauth_header
93
+ })
94
+ rescue StandardError => e
95
+ raise LicodeError, "Failed to connect to Licode. Response code: #{e.message}"
96
+ end
97
+
98
+ def get_services ()
99
+ response = self.class.get('/services/',
100
+ :headers => {
101
+ "Authorization" => mauth_header,
102
+ "Content-Type" => "application/json"
103
+ })
104
+ rescue StandardError => e
105
+ raise LicodeError, "Failed to connect to Licode. Response code: #{e.message}"
106
+ end
107
+
108
+ def get_service (service)
109
+ response = self.class.get('/services/' + service,
110
+ :headers => {
111
+ "Authorization" => mauth_header,
112
+ "Content-Type" => "application/json",
113
+ "Content-Type" => "application/json"
114
+ })
115
+ rescue StandardError => e
116
+ raise LicodeError, "Failed to connect to Licode. Response code: #{e.message}"
117
+ end
118
+
119
+ def delete_service (service)
120
+ response = self.class.delete('/services/' + service,
121
+ :headers => {
122
+ "Authorization" => mauth_header,
123
+ "Content-Type" => "application/json"
124
+ })
125
+ rescue StandardError => e
126
+ raise LicodeError, "Failed to connect to Licode. Response code: #{e.message}"
127
+ end
128
+
129
+ def get_room_users (room)
130
+ response = self.class.get('/rooms/' + room + '/users/',
131
+ :headers => {
132
+ "Authorization" => mauth_header,
133
+ "Content-Type" => "application/json"
134
+ })
135
+ rescue StandardError => e
136
+ raise LicodeError, "Failed to connect to Licode. Response code: #{e.message}"
137
+ end
138
+
139
+ private
140
+ def mauth_header(opts = {})
141
+ header = "MAuth realm=#{@service_url},mauth_signature_method=HMAC_SHA1"
142
+ timestamp = (Time.now.to_f * 1000).to_i
143
+ cnounce = rand(99999)
144
+
145
+ toSign = timestamp.to_s + "," + cnounce.to_s
146
+
147
+ if opts[:username] && !opts[:username].empty? && opts[:role] && !opts[:role].empty?
148
+ header += ',mauth_username='
149
+ header += opts[:username]
150
+ header += ',mauth_role='
151
+ header += opts[:role]
152
+
153
+ toSign += ',' + opts[:username] + ',' + opts[:role]
154
+ end
155
+
156
+ signed = calculateSignature(toSign, @service_key)
157
+
158
+ header += ',mauth_serviceid='
159
+ header += @service_id
160
+ header += ',mauth_cnonce='
161
+ header += cnounce.to_s
162
+ header += ',mauth_timestamp='
163
+ header += timestamp.to_s
164
+ header += ',mauth_signature='
165
+ header += signed
166
+
167
+ header
168
+ end
169
+
170
+ private
171
+ def calculateSignature (toSign, key)
172
+ digest = OpenSSL::Digest.new('sha1')
173
+ hex = OpenSSL::HMAC.hexdigest(digest,key,toSign)
174
+ signed = Base64.encode64("#{hex}")
175
+ return signed
176
+ end
177
+ end
178
+ end
@@ -0,0 +1,8 @@
1
+ module Licode
2
+
3
+ # Defines errors raised by methods of the Licode Ruby SDK.
4
+ class LicodeError < StandardError; end
5
+ # Defines errors raised when authentication fails
6
+ class LicodeAuthenticationError < LicodeError; end
7
+
8
+ end
@@ -0,0 +1,40 @@
1
+ require "licode/room"
2
+ require "licode/client"
3
+
4
+ module Licode
5
+ class Nuve
6
+ attr_reader :service_id, :service_key, :service_url
7
+ ##
8
+ # Create a new Nuve object.
9
+ #
10
+ # @param [String] service_id Your ServiceId. See the Nuve Mongo DB.
11
+ # @param [String] service_key Your ServiceKey.
12
+ # @param [String] service_url base URL to your licode instance.
13
+
14
+ def initialize (service_id, service_key, service_url)
15
+ @service_id = service_id
16
+ @service_key = service_key
17
+ @service_url = service_url
18
+ end
19
+
20
+ # def create_service(name, key)
21
+ # response = client.create_service(name,key});
22
+ # Service.new name,key
23
+ # end
24
+
25
+ def create_room(name,opts={})
26
+ response = client.create_room(name,opts)
27
+ Room.new response['_id'], opts
28
+ end
29
+
30
+ def create_token(room, username, role)
31
+ client.create_token(room, username, role)
32
+ end
33
+
34
+ protected
35
+
36
+ def client
37
+ @client ||= Client.new service_id, service_key, service_url
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,29 @@
1
+ require "licode/client"
2
+ module Licode
3
+ # Represents an Licode room.
4
+ #
5
+ # Use the Nuve.create_room() method to create an Licode room. Use the
6
+ # room_id property of the Room object to get the room room_id.
7
+ class Room
8
+ attr_reader :room_id, :users, :opts
9
+
10
+ # @private
11
+ def initialize(room_id, opts={})
12
+ @room_id = room_id
13
+ @opts = opts
14
+ end
15
+
16
+ def create_token(username, role)
17
+ client.create_token(room_id, username, role)
18
+ end
19
+
20
+ def users
21
+ client.get_room_users(room_id);
22
+ end
23
+
24
+ # @private
25
+ def to_s
26
+ @room_id
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ module Licode
2
+ class Service
3
+
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module Licode
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'licode/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "licode"
8
+ spec.version = Licode::VERSION
9
+ spec.authors = ["Joshua Rountree"]
10
+ spec.email = ["joshua@swodev.com"]
11
+
12
+ spec.summary = %q{Ruby gem for working with Licode Services from Ruby}
13
+ spec.description = %q{This is a ruby gem based on the rb file from the licode repo but with tests and an up to date code base.}
14
+ spec.homepage = "https://github.com/joshuairl/licode-ruby-sdk"
15
+ spec.license = "MIT"
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.10"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+
24
+ spec.add_dependency "addressable", "~> 2.3"
25
+ spec.add_runtime_dependency 'httparty', '~> 0.13', '>= 0.13.1'
26
+ spec.add_runtime_dependency 'activesupport'
27
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: licode
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Joshua Rountree
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-29 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
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: addressable
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.3'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: httparty
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.13'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 0.13.1
65
+ type: :runtime
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '0.13'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 0.13.1
75
+ - !ruby/object:Gem::Dependency
76
+ name: activesupport
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ description: This is a ruby gem based on the rb file from the licode repo but with
90
+ tests and an up to date code base.
91
+ email:
92
+ - joshua@swodev.com
93
+ executables: []
94
+ extensions: []
95
+ extra_rdoc_files: []
96
+ files:
97
+ - ".gitignore"
98
+ - CODE_OF_CONDUCT.md
99
+ - Gemfile
100
+ - LICENSE.txt
101
+ - README.md
102
+ - Rakefile
103
+ - bin/console
104
+ - bin/setup
105
+ - lib/licode.rb
106
+ - lib/licode/client.rb
107
+ - lib/licode/exceptions.rb
108
+ - lib/licode/nuve.rb
109
+ - lib/licode/room.rb
110
+ - lib/licode/service.rb
111
+ - lib/licode/version.rb
112
+ - licode.gemspec
113
+ homepage: https://github.com/joshuairl/licode-ruby-sdk
114
+ licenses:
115
+ - MIT
116
+ metadata: {}
117
+ post_install_message:
118
+ rdoc_options: []
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ requirements: []
132
+ rubyforge_project:
133
+ rubygems_version: 2.2.2
134
+ signing_key:
135
+ specification_version: 4
136
+ summary: Ruby gem for working with Licode Services from Ruby
137
+ test_files: []
138
+ has_rdoc: