ruby_rabbitmq_janus 0.1.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c04994698a3ccfc133c0826a4bcd92dcc58ff41d
4
+ data.tar.gz: f9e4b1151c22937d7e31b572c4166a103e27709e
5
+ SHA512:
6
+ metadata.gz: b07f2dbd3e7e6dc9cd32eed1f321da24ff80348b98d222e609c5a6f2ba24d7afa50a43b262a154be81cbee55b05b744c7627cc8e0fbe33f09aa78924c48e5d14
7
+ data.tar.gz: b45f399e4e97bbad4b33f5a9e529f2508464c4128215b5b74b89ef915ac74eaba31b6e72396733f9e34057a59adfc6dac332d5fbaa6d320708ab8662bd8ac238
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ *.gem
12
+
13
+ log
14
+ config/ruby-rabbitmq-janus.yml
data/.overcommit.yml ADDED
@@ -0,0 +1,12 @@
1
+ PreCommit:
2
+ RuboCop:
3
+ enabled: true
4
+ Reek:
5
+ enabled: true
6
+ YamlSyntax:
7
+ enabled: true
8
+ JsonSyntax:
9
+ enabled: true
10
+ PrePush:
11
+ RSpec:
12
+ enabled: true
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format Fuubar
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,15 @@
1
+ AllCops:
2
+ Exclude:
3
+ - Gemfile
4
+ - rrj.gemspec
5
+ - bin/**/*
6
+ TargetRubyVersion: 2.3
7
+
8
+ Style/Encoding:
9
+ Enabled: true
10
+
11
+ Style/FrozenStringLiteralComment:
12
+ EnforcedStyle: always
13
+
14
+ Metrics/LineLength:
15
+ Max: 90
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
data/.yardopts ADDED
@@ -0,0 +1,5 @@
1
+ --markup markdown
2
+ --private
3
+ --protected
4
+ -
5
+ config/default.md
@@ -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 TODO: Write your email address. 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,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rrj.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 VAILLANT Jeremy
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # ruby-rabbitmq-janus
2
+
3
+ Ruby Gem for Janus WebRTC Gateway integration using RabbitMQ message queue
4
+
5
+ This gem is used to communicate to a server Janus through RabbitMQ software (
6
+ Message-oriented middleware). It waiting a messages to Rails API who send to RabbitMQ
7
+ server in a queue for janus server. janus processes a message and send to RabbitMQ server
8
+ in a queue for gem. Once the received message is decoded and returned through the Rails API.
9
+
10
+ ## Menu
11
+ * [How to use](#how-to-use)
12
+ * [Installation](#installation)
13
+ * [Configuration](#configuration)
14
+ * [Usage](#usage)
15
+ * [Development](#development)
16
+ * [RSpec](#rspec-test)
17
+ * [Documentation](#documentation)
18
+
19
+ ## How to use
20
+
21
+ ### Installation
22
+
23
+ Use bitbucket for installing gem in your Gemfile
24
+ ```ruby
25
+ gem 'ruby-rabbitmq-janus', '~> 0.1.0'
26
+ ```
27
+
28
+ ### Configuration
29
+
30
+ If you want used a customize configuration see [ruby-rabbitmq-janus.yml](config/default.md)
31
+
32
+ ### Usage
33
+
34
+ Exemple usage :
35
+ ```ruby
36
+ # Initialize gem
37
+ transaction = RubyRabbitmqJanus::RRJ.new
38
+
39
+ # Send a message type 'create'
40
+ create = transaction.message_template_ask('create')
41
+ => {"janus"=>"create",
42
+ "transaction"=>"U5MZ8IYNLF",
43
+ "correlation"=>"6e77d355-6c3e-450c-89ad-a5daeb8e006a"}
44
+ create_response = transaction.message_template_response(create)
45
+ => {"janus"=>"success", "transaction"=>"U5MZ8IYNLF", "data"=>{"id"=>7123088323743398}}
46
+
47
+ # Destroy session created
48
+ destroy = transaction.message_template_ask('destroy')
49
+ => {"janus"=>"destroy",
50
+ "session_id"=>7123088323743398,
51
+ "transaction"=>"PKS63VJD8C",
52
+ "correlation"=>"6e34d8d6-814a-4633-bcab-be3e24cc6260"}
53
+ destroy_response = transaction_template_response(destroy)
54
+ => {"janus"=>"success", "session_id"=>7123088323743398, "transaction"=>"PKS63VJD8C"}
55
+ ```
56
+
57
+ The methods message_template_ask and message_template_response have an aliases :wink:
58
+ ```ruby
59
+ message_template_ask => ask
60
+ message_template_response => response
61
+ ```
62
+
63
+ ## Development
64
+ ### RSpec test
65
+
66
+ ```linux
67
+ bundle exec rspec
68
+ ```
69
+
70
+ TIPS: for rspec install janus and rabbitmq server configured by default for user
71
+ rabbitmq and use plugin echotest for janus server.
72
+
73
+ ### Documentation
74
+
75
+ This doc is generated with yard.
76
+
77
+ ```
78
+ # Genereate doc
79
+ yard
80
+ # Launch server
81
+ yard server
82
+ ```
83
+
84
+ see [Yard Getting Started](http://www.rubydoc.info/gems/yard/file/docs/GettingStarted.md)
data/config.reek ADDED
@@ -0,0 +1,3 @@
1
+ ---
2
+ TooManyInstanceVariables:
3
+ max_instance_variables: 7
data/config/default.md ADDED
@@ -0,0 +1,28 @@
1
+ # RabbitMQ server info
2
+
3
+ The configuration file contains two parts.
4
+
5
+ The RabbitMQ server information for connection, and the queue used by janus.
6
+
7
+ By default the configuration file look like this :
8
+
9
+ ```yaml
10
+ server:
11
+ host: 'localhost'
12
+ port: 5672
13
+ vhost: '/'
14
+ user: 'guest'
15
+ password: 'guest'
16
+
17
+ queues:
18
+ queue_from: from-janus
19
+ queue_to: to-janus
20
+ ```
21
+
22
+ ## Customize
23
+ For customizing a configuration add a yml file in your rails project in
24
+ `config/ruby-rabbitmq-janus.yml`.
25
+
26
+ ## Ressources
27
+ * [Configuration of RabbitMQ](https://www.rabbitmq.com/configure.html#config-items)
28
+ * [Configuration of Janus queue](https://janus.conf.meetecho.com/docs/rest.html#rabbit)
@@ -0,0 +1,31 @@
1
+ # Configuration file for gem
2
+ server:
3
+ # Precise RabbitMQ host - Default 'localhost'
4
+ host: localhost
5
+ # Precise RabbitMQ port - Default 'port'
6
+ port: 5672
7
+ # Precise RabbitMQ vhost - Default '/'
8
+ vhost: /
9
+ # Precise RabbitMQ user - Default 'guest'
10
+ user: guest
11
+ # Precise RabbitMQ password - Default 'guest'
12
+ password: guest
13
+
14
+ # RabbitMQ Queue information
15
+ queues:
16
+ # Queue sending response to janus server
17
+ queue_from: from-janus
18
+ # Queue sending a message for janus server
19
+ queue_to: to-janus
20
+
21
+ # Janus plugin used
22
+ janus:
23
+ # Create an array to plugin
24
+ plugins:
25
+ - janus.plugin.echotest
26
+
27
+ # Options gem
28
+ gem:
29
+ # Option for logging
30
+ log:
31
+ level: 'debug'
@@ -0,0 +1,6 @@
1
+ {
2
+ "janus": "attach",
3
+ "session_id": "<number>",
4
+ "transaction": "<string>",
5
+ "plugin": "<plugin[0]>"
6
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "janus": "create",
3
+ "transaction": "<string>"
4
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "janus": "destroy",
3
+ "session_id": "<number>",
4
+ "transaction": "<string>"
5
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "janus": "detach",
3
+ "session_id": "<number>",
4
+ "handle_id": "<number>",
5
+ "transaction": "<string>"
6
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "janus": "info",
3
+ "transaction": "<string>"
4
+ }
data/lib/rrj/config.rb ADDED
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+
5
+ module RubyRabbitmqJanus
6
+ # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
7
+ # Loading a yaml file for apply a configuration to gem.
8
+ # @!attribute [r] options
9
+ # @return [RubyRabbitmqJanus::Config] Options to gem.
10
+ class Config
11
+ attr_reader :options
12
+
13
+ # Define a default path to file configuration
14
+ DEFAULT_PATH = File.realpath(File.join(File.dirname(__FILE__), '..', '..'))
15
+
16
+ # Define a default name to file configuration
17
+ DEFAULT_CONF = 'config/default.yml'
18
+
19
+ # Define a default override file configuration
20
+ CUSTOMIZE_CONF = 'config/ruby-rabbitmq-janus.yml'
21
+
22
+ # Initialize configuration file default or customize if exist
23
+ # @param logs [RubyRabbitmqJanus::Log] Load RubyRabbitmqJanus::Log to gem
24
+ def initialize(logs)
25
+ @logs = logs
26
+ @options = load_configuration(File.join(DEFAULT_PATH, DEFAULT_CONF))
27
+ override_configuration(File.join(Dir.pwd, CUSTOMIZE_CONF))
28
+ precise_log_level
29
+ end
30
+
31
+ private
32
+
33
+ # Load configuration file yaml
34
+ # @return [Yaml] Configuration file
35
+ # @param file [String] Path to configuration file (with name)
36
+ def load_configuration(file)
37
+ @logs.info("Loading configuration file : #{file}")
38
+ YAML.load(File.read(file))
39
+ end
40
+
41
+ # Load customize configuration file if exist
42
+ # @return [Yaml] Configuration file
43
+ # @param file [String] Path to configuration file (with name)
44
+ def override_configuration(file)
45
+ @options = load_configuration(file) if File.exist?(file)
46
+ end
47
+
48
+ def precise_log_level
49
+ @logs.level = @options['gem']['log']['level']
50
+ end
51
+ end
52
+ end
data/lib/rrj/init.rb ADDED
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyRabbitmqJanus
4
+ # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
5
+ # Initialize gem
6
+ # @!attribute [r] rabbit
7
+ # @return [RubyRabbitmqJanus::RabbitMQ] Object RabbitMQ for connection to RabbitMQ
8
+ # server
9
+ # @!attribute [r] logs
10
+ # @return [RubyRabbitmqJanus::Log] Object Log for manipulate logs
11
+ # @!attribute [r] settings
12
+ # @return [RubyRabbitmqJanus::Config] Object Config to gem
13
+ class RRJ
14
+ # Returns a new instance of RubyRabbitmqJanus
15
+ def initialize
16
+ @logs = Log.instance
17
+
18
+ @settings = RubyRabbitmqJanus::Config.new(@logs)
19
+ @requests = RubyRabbitmqJanus::Requests.new(@logs)
20
+ @rabbit = RubyRabbitmqJanus::RabbitMQ.new(@settings, @requests.requests, @logs)
21
+ end
22
+
23
+ # Send a message, to RabbitMQ, with a template JSON
24
+ # @return [Hash] Contains information to request sending
25
+ # @param template_used [String] Json used to request sending in RabbitMQ
26
+ # @param [Hash] opts the options sending with a request
27
+ # @option opts [String] :janus The message type
28
+ # @option opts [String] :transaction The transaction identifier
29
+ # @option opts [Hash] :data The option data to request
30
+ def message_template_ask(template_used = 'info', opts = {})
31
+ @rabbit.ask_request(template_used, opts)
32
+ end
33
+
34
+ # Send a message to RabbitMQ for reading a response
35
+ # @return [Hash] Contains a response to request sending
36
+ # @param info_request [Hash] Contains information to request sending
37
+ # @option info_request [String] :janus The message type
38
+ # @option info_request [String] :transaction The transaction identifier
39
+ # @option info_request [Hash] :data The option data to request
40
+ def message_template_response(info_request)
41
+ @rabbit.ask_response(info_request)
42
+ end
43
+
44
+ alias ask message_template_ask
45
+ alias response message_template_response
46
+ end
47
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyRabbitmqJanus
4
+ # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
5
+ # Define errors to gems
6
+ class Error
7
+ end
8
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
5
+ module RubyRabbitmqJanus
6
+ # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
7
+ # Communication to RabbitMQ with format for Janus message
8
+ class Janus
9
+ # Returns a new instance of Janus
10
+ # @param connection [String] Connection to RabbitMQ server
11
+ # @param logs [RRJ::Log] Instance to log
12
+ def initialize(connection, options, logs)
13
+ @channel = connection.create_channel
14
+ @queues = options['queues']
15
+ @plugins = options['janus']['plugins']
16
+ @logs = logs
17
+ end
18
+
19
+ # Send a message to RabbitMQ
20
+ def send(request, opts)
21
+ message = MessageJanus.new(@plugins, @logs, opts)
22
+ message.send(request, @channel, @queues['queue_to'])
23
+ end
24
+
25
+ # Read a message to RabbitMQ
26
+ def read(info_message, connection)
27
+ response = ResponseJanus.new(@channel, connection, @logs, info_message)
28
+ response.read(@queues['queue_from'])
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'securerandom'
5
+
6
+ module RubyRabbitmqJanus
7
+ # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
8
+ # Message Janus sending to rabbitmq server
9
+ class MessageJanus
10
+ # Initialiaze a message posting to RabbitMQ
11
+ def initialize(plugins, logs, opts)
12
+ @correlation = SecureRandom.uuid
13
+ @opts = opts
14
+ @plugins = plugins
15
+ @logs = logs
16
+ @my_request = nil
17
+ @message = nil
18
+ end
19
+
20
+ # Send a message to RabbitMQ server
21
+ def send(json, channel, queue_to)
22
+ @message = channel.default_exchange
23
+ @message.publish(test_request_and_replace(json),
24
+ routing_key: queue_to,
25
+ correlation_id: @correlation,
26
+ content_type: 'application/json')
27
+ return_info_message
28
+ end
29
+
30
+ private
31
+
32
+ # Prepare a hash request and replace information necessary for janus
33
+ def test_request_and_replace(json_file)
34
+ @my_request = JSON.parse(File.read(json_file))
35
+ replaces
36
+ @my_request.to_json
37
+ end
38
+
39
+ def replaces
40
+ replace_transaction
41
+ if @opts
42
+ replace_element('session_id')
43
+ replace_plugin
44
+ replace_element(@opts['handle_id'] ? 'handle_id' : 'sender', 'handle_id')
45
+ end
46
+ end
47
+
48
+ # Replace a transaction field with an String format
49
+ def replace_transaction
50
+ @my_request['transaction'] = [*('A'..'Z'), *('0'..'9')].sample(10).join
51
+ end
52
+
53
+ # Replace a session_id field with an Integer
54
+ def replace_element(value, value_replace = value)
55
+ add_return(value_replace, value_data_or_precise(value)) \
56
+ if @my_request[value_replace]
57
+ end
58
+
59
+ # Replace plugin used for transaction
60
+ def replace_plugin
61
+ my_plugin = @my_request['plugin']
62
+ if my_plugin
63
+ my_plugin = @plugins[my_plugin.delete('<plugin[').delete(']').to_i]
64
+ add_return('plugin', my_plugin)
65
+ end
66
+ end
67
+
68
+ # Prepare an Hash with information necessary to read a response in RabbitMQ queue
69
+ def return_info_message
70
+ @my_request['correlation'] = @correlation
71
+ @logs.debug @my_request
72
+ @my_request
73
+ end
74
+
75
+ def add_return(key, value)
76
+ @my_request[key] = value
77
+ @my_request.merge!(key => value)
78
+ end
79
+
80
+ def value_data_or_precise(key)
81
+ @opts[key] || @opts['data']['id']
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
5
+ module RubyRabbitmqJanus
6
+ # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
7
+ # Response Janus received to RabbitMQ server
8
+ class ResponseJanus
9
+ def initialize(channel, connection, logs, opts = {})
10
+ @channel = channel
11
+ @connection = connection
12
+ @opts = opts
13
+ @logs = logs
14
+ @response = nil
15
+ end
16
+
17
+ # Read a response to janus (in RabbitMQ queue)
18
+ # @return [Hash] resultat to request
19
+ def read(queue_from)
20
+ option_sub = { block: true, manual_ack: false, exclusive: false }
21
+ the_queue = @channel.queue(queue_from)
22
+ the_queue.subscribe(option_sub) do |info, prop, pay|
23
+ listen(info, prop, pay)
24
+ end
25
+ return_response_json
26
+ end
27
+
28
+ private
29
+
30
+ # Listen a response to queue
31
+ def listen(_delivery_info, properties, payload)
32
+ if @opts['correlation'] == properties[:correlation_id]
33
+ @response = payload
34
+ @connection.close
35
+ end
36
+ end
37
+
38
+ def return_response_json
39
+ @response = JSON.parse(@response)
40
+ case @opts['janus']
41
+ when 'create'
42
+ merge('session_id')
43
+ when 'attach'
44
+ merge('handle_id')
45
+ end
46
+ @logs.debug @response
47
+ @response
48
+ end
49
+
50
+ def resp
51
+ @response['data']['id']
52
+ end
53
+
54
+ def merge(key)
55
+ @response[key] = resp
56
+ end
57
+ end
58
+ end
data/lib/rrj/log.rb ADDED
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'logging'
4
+
5
+ module RubyRabbitmqJanus
6
+ # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
7
+ # Class for wrtting logs. Define level used (:warn, :info, :debug).
8
+ class Log
9
+ include Singleton
10
+
11
+ # Define folder to writing logs
12
+ DEFAULT_LOG_DIR = 'log'
13
+
14
+ # Define file name to writing logs
15
+ DEFAULT_LOG_NAME = 'rails-rabbit-janus.log'
16
+
17
+ # Define a default level to gem (:warn, :info, :debug)
18
+ DEFAULT_LEVEL = :debug
19
+
20
+ # Returns a new instance to Log
21
+ def initialize
22
+ @logs = Logging.logger[Time.now.to_s + ' --']
23
+ @logs.level = DEFAULT_LEVEL
24
+ @logs.add_appenders Logging.appenders.file(DEFAULT_LOG_DIR + '/' + DEFAULT_LOG_NAME)
25
+
26
+ welcome = "\n"\
27
+ "====================================\n" \
28
+ "### Start gem Rails Rabbit Janus ###\n" \
29
+ '===================================='
30
+ @logs.info(welcome)
31
+ end
32
+
33
+ def level
34
+ @logs.level
35
+ end
36
+
37
+ def level=(level)
38
+ @logs.level = level
39
+ end
40
+
41
+ # Write a message in log with a warn level
42
+ def warn(message)
43
+ @logs.warn(message)
44
+ end
45
+
46
+ # Write a message in log with a info level
47
+ def info(message)
48
+ @logs.info(message)
49
+ end
50
+
51
+ # Write a message in log with a debug level
52
+ def debug(message)
53
+ @logs.debug(message)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bunny'
4
+
5
+ module RubyRabbitmqJanus
6
+ # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
7
+ # Class for connection with RabbitMQ Server
8
+ class RabbitMQ
9
+ # Return a new instance to RabbitMQ
10
+ # @param configuration [RRJ::Config] Configuration file to gem
11
+ # @param requests [Hash] Request sending to RabbitMQ
12
+ # @param logs [RRJ::Log] Log to gem
13
+ def initialize(configuration, requests, logs)
14
+ @settings = configuration
15
+ @logs = logs
16
+ @requests = requests
17
+ @connection = Bunny.new(read_options_server)
18
+ @response = nil
19
+ @janus = nil
20
+ end
21
+
22
+ # Connect to server RabbitMQ and post a message in queue ('to-janus' by default)
23
+ def ask_request(request_type, opts)
24
+ execute_request do
25
+ @response = @janus.send(@requests[request_type.to_s], opts)
26
+ close_server_rabbitmq
27
+ end
28
+ end
29
+
30
+ # Connect to server RabbitMQ and read a message in queue ('from-janus' by default)
31
+ def ask_response(info_request)
32
+ execute_request do
33
+ @response = @janus.read(info_request, @connection)
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ # Establish connection with RabbitMQ server
40
+ # @return [RRJ::Janus] Janus object for manipulating data sending and receiving to
41
+ # rabbitmq server
42
+ def open_server_rabbitmq
43
+ @connection.start
44
+ end
45
+
46
+ # Close connection to rabbitmq server
47
+ def close_server_rabbitmq
48
+ @connection.close
49
+ end
50
+
51
+ # Use configuration information to connect RabbitMQ
52
+ def read_options_server
53
+ hash = {}
54
+ @settings.options.fetch('server').each do |key, server|
55
+ hash.merge!(key.to_sym => server.to_s)
56
+ end
57
+ hash
58
+ end
59
+
60
+ # Execute request
61
+ def execute_request
62
+ open_server_rabbitmq
63
+ @janus = Janus.new(@connection, @settings.options, @logs)
64
+ yield
65
+ @response
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyRabbitmqJanus
4
+ # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
5
+ # Load files json in config/request.
6
+ # This file is used for sending a request to RabbitMQ
7
+ # @!attribute [r] requests
8
+ # @return [RubyRabbitmqJanus::Request] Array to request
9
+ class Requests
10
+ attr_reader :requests
11
+
12
+ # Define folder to request
13
+ PATH_REQUEST = 'config/requests/'
14
+
15
+ # Load all requests in folder
16
+ def initialize(logs)
17
+ @requests = {}
18
+ logs.info "Loading all requests in : #{PATH_REQUEST}"
19
+ Dir[File.join(PATH_REQUEST, '*')].count do |file|
20
+ if File.file?(file)
21
+ read_file(file)
22
+ elsif File.directory?(file)
23
+ each_folder(File.basename(file))
24
+ end
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ # Run folder contains templates json
31
+ def each_folder(subfolder)
32
+ Dir[File.join(PATH_REQUEST + subfolder, '*')].count do |file|
33
+ if File.file?(file)
34
+ read_folder(subfolder.gsub('/', '::') + '::', file)
35
+ elsif File.directory?(file)
36
+ each_folder(subfolder + '/' + File.basename(file))
37
+ end
38
+ end
39
+ end
40
+
41
+ # Add template json to requests array
42
+ # @param file [File]
43
+ def read_file(file)
44
+ @requests[File.basename(file, '.json').to_s] = File.path(file)
45
+ end
46
+
47
+ # Add template json to requests array with a path
48
+ # @param folder [Dir]
49
+ # @param file [File]
50
+ def read_folder(folder, file)
51
+ @requests[folder + File.basename(file, '.json').to_s] = File.path(file)
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
3
+ # Define constant to gem.
4
+ module RubyRabbitmqJanus
5
+ # Define version to gem
6
+ VERSION = '0.1.1'
7
+
8
+ # Define a summary description to gem
9
+ SUMMARY = 'Ruby RabbitMQ Janus'
10
+
11
+ # Define a long description to gem
12
+ DESCRIPTION = 'This gem is used to communicate to a server Janus through RabbitMQ '\
13
+ 'software (Message-oriented middleware). It waiting a messages to Rails API who ' \
14
+ 'send to RabbitMQ server in a queue for janus server. Janus processes a message ' \
15
+ 'and send to RabbitMQ server in a queue for gem. Once the received message is ' \
16
+ 'decoded and returned through the Rails API.'
17
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ require 'rrj/version'
3
+
4
+ require 'rrj/init'
5
+ require 'rrj/log'
6
+ require 'rrj/config'
7
+ require 'rrj/requests'
8
+
9
+ require 'rrj/rabbitmq/rabbitmq'
10
+
11
+ require 'rrj/janus/janus'
12
+ require 'rrj/janus/message'
13
+ require 'rrj/janus/response'
14
+ require 'rrj/janus/error'
data/rrj.gemspec ADDED
@@ -0,0 +1,35 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'rrj/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'ruby_rabbitmq_janus'
7
+ spec.version = RubyRabbitmqJanus::VERSION
8
+ spec.authors = ['VAILLANT Jeremy']
9
+ spec.email = ['jeremy.vaillant@dazzl.tv']
10
+
11
+ spec.summary = RubyRabbitmqJanus::SUMMARY
12
+ spec.description = RubyRabbitmqJanus::DESCRIPTION
13
+
14
+ spec.homepage = 'https://github.com/dazzl-tv/ruby-rabbitmq-janus'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_development_dependency 'bundler', '~> 1.12'
21
+ spec.add_development_dependency 'rake', '~> 10.0'
22
+ spec.add_development_dependency 'rspec', '~> 3.5', '>= 3.5.0'
23
+ spec.add_development_dependency 'overcommit', '~> 0.34.2'
24
+ spec.add_development_dependency 'rubocop', '~> 0.42.0'
25
+ spec.add_development_dependency 'yard', '~> 0.9.5'
26
+ spec.add_development_dependency 'reek', '~> 4.2', '>= 4.2.4'
27
+ spec.add_development_dependency 'fuubar', '~> 2.2'
28
+ spec.add_development_dependency 'aruba', '~> 0.14.2'
29
+ spec.add_development_dependency 'pry-byebug', '~> 3.4'
30
+ spec.add_development_dependency 'json-schema', '~> 2.6', '>= 2.6.2'
31
+ spec.add_development_dependency 'json-schema-rspec', '~> 0.0.4'
32
+
33
+ spec.add_runtime_dependency 'bunny', '~> 2.5'
34
+ spec.add_runtime_dependency 'logging', '~> 2.1'
35
+ end
metadata ADDED
@@ -0,0 +1,292 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_rabbitmq_janus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - VAILLANT Jeremy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-07 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.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
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.5'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 3.5.0
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '3.5'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 3.5.0
61
+ - !ruby/object:Gem::Dependency
62
+ name: overcommit
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 0.34.2
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 0.34.2
75
+ - !ruby/object:Gem::Dependency
76
+ name: rubocop
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 0.42.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.42.0
89
+ - !ruby/object:Gem::Dependency
90
+ name: yard
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: 0.9.5
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: 0.9.5
103
+ - !ruby/object:Gem::Dependency
104
+ name: reek
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '4.2'
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: 4.2.4
113
+ type: :development
114
+ prerelease: false
115
+ version_requirements: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: '4.2'
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: 4.2.4
123
+ - !ruby/object:Gem::Dependency
124
+ name: fuubar
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: '2.2'
130
+ type: :development
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - "~>"
135
+ - !ruby/object:Gem::Version
136
+ version: '2.2'
137
+ - !ruby/object:Gem::Dependency
138
+ name: aruba
139
+ requirement: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - "~>"
142
+ - !ruby/object:Gem::Version
143
+ version: 0.14.2
144
+ type: :development
145
+ prerelease: false
146
+ version_requirements: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - "~>"
149
+ - !ruby/object:Gem::Version
150
+ version: 0.14.2
151
+ - !ruby/object:Gem::Dependency
152
+ name: pry-byebug
153
+ requirement: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - "~>"
156
+ - !ruby/object:Gem::Version
157
+ version: '3.4'
158
+ type: :development
159
+ prerelease: false
160
+ version_requirements: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - "~>"
163
+ - !ruby/object:Gem::Version
164
+ version: '3.4'
165
+ - !ruby/object:Gem::Dependency
166
+ name: json-schema
167
+ requirement: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - "~>"
170
+ - !ruby/object:Gem::Version
171
+ version: '2.6'
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: 2.6.2
175
+ type: :development
176
+ prerelease: false
177
+ version_requirements: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - "~>"
180
+ - !ruby/object:Gem::Version
181
+ version: '2.6'
182
+ - - ">="
183
+ - !ruby/object:Gem::Version
184
+ version: 2.6.2
185
+ - !ruby/object:Gem::Dependency
186
+ name: json-schema-rspec
187
+ requirement: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - "~>"
190
+ - !ruby/object:Gem::Version
191
+ version: 0.0.4
192
+ type: :development
193
+ prerelease: false
194
+ version_requirements: !ruby/object:Gem::Requirement
195
+ requirements:
196
+ - - "~>"
197
+ - !ruby/object:Gem::Version
198
+ version: 0.0.4
199
+ - !ruby/object:Gem::Dependency
200
+ name: bunny
201
+ requirement: !ruby/object:Gem::Requirement
202
+ requirements:
203
+ - - "~>"
204
+ - !ruby/object:Gem::Version
205
+ version: '2.5'
206
+ type: :runtime
207
+ prerelease: false
208
+ version_requirements: !ruby/object:Gem::Requirement
209
+ requirements:
210
+ - - "~>"
211
+ - !ruby/object:Gem::Version
212
+ version: '2.5'
213
+ - !ruby/object:Gem::Dependency
214
+ name: logging
215
+ requirement: !ruby/object:Gem::Requirement
216
+ requirements:
217
+ - - "~>"
218
+ - !ruby/object:Gem::Version
219
+ version: '2.1'
220
+ type: :runtime
221
+ prerelease: false
222
+ version_requirements: !ruby/object:Gem::Requirement
223
+ requirements:
224
+ - - "~>"
225
+ - !ruby/object:Gem::Version
226
+ version: '2.1'
227
+ description: This gem is used to communicate to a server Janus through RabbitMQ software
228
+ (Message-oriented middleware). It waiting a messages to Rails API who send to RabbitMQ
229
+ server in a queue for janus server. Janus processes a message and send to RabbitMQ
230
+ server in a queue for gem. Once the received message is decoded and returned through
231
+ the Rails API.
232
+ email:
233
+ - jeremy.vaillant@dazzl.tv
234
+ executables: []
235
+ extensions: []
236
+ extra_rdoc_files: []
237
+ files:
238
+ - ".gitignore"
239
+ - ".overcommit.yml"
240
+ - ".rspec"
241
+ - ".rubocop.yml"
242
+ - ".travis.yml"
243
+ - ".yardopts"
244
+ - CODE_OF_CONDUCT.md
245
+ - Gemfile
246
+ - LICENSE
247
+ - README.md
248
+ - config.reek
249
+ - config/default.md
250
+ - config/default.yml
251
+ - config/requests/attach.json
252
+ - config/requests/create.json
253
+ - config/requests/destroy.json
254
+ - config/requests/detach.json
255
+ - config/requests/info.json
256
+ - lib/rrj/config.rb
257
+ - lib/rrj/init.rb
258
+ - lib/rrj/janus/error.rb
259
+ - lib/rrj/janus/janus.rb
260
+ - lib/rrj/janus/message.rb
261
+ - lib/rrj/janus/response.rb
262
+ - lib/rrj/log.rb
263
+ - lib/rrj/rabbitmq/rabbitmq.rb
264
+ - lib/rrj/requests.rb
265
+ - lib/rrj/version.rb
266
+ - lib/ruby_rabbitmq_janus.rb
267
+ - rrj.gemspec
268
+ homepage: https://github.com/dazzl-tv/ruby-rabbitmq-janus
269
+ licenses:
270
+ - MIT
271
+ metadata: {}
272
+ post_install_message:
273
+ rdoc_options: []
274
+ require_paths:
275
+ - lib
276
+ required_ruby_version: !ruby/object:Gem::Requirement
277
+ requirements:
278
+ - - ">="
279
+ - !ruby/object:Gem::Version
280
+ version: '0'
281
+ required_rubygems_version: !ruby/object:Gem::Requirement
282
+ requirements:
283
+ - - ">="
284
+ - !ruby/object:Gem::Version
285
+ version: '0'
286
+ requirements: []
287
+ rubyforge_project:
288
+ rubygems_version: 2.5.1
289
+ signing_key:
290
+ specification_version: 4
291
+ summary: Ruby RabbitMQ Janus
292
+ test_files: []