magellan-publisher 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7ffadcdab35bc05035387f74ffdc1069a209c56d
4
+ data.tar.gz: 6cc67dca0a373f051e7cdccc1272009adacf8f78
5
+ SHA512:
6
+ metadata.gz: 514fd121d2df5a1cc5607285da9224f16fb6c4cf561607beb52bf1da437548326e8b52e79b259b03590313fb9753fd027f69e2a4330d449357adc5917213baf0
7
+ data.tar.gz: 1c6c9d8bd218176cb470d442cc0c1428616807ea2258a99191d31c4b96329a77254fc5202e510571cb21112c8917c0b0248e46a12a6e99f6d69b5b8aebae9cd0
data/.gitignore ADDED
@@ -0,0 +1,38 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+ /log
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalisation:
25
+ Gemfile.lock
26
+ /.bundle/
27
+ /lib/bundler/man/
28
+ vendor/bundle
29
+
30
+ # for a library or gem, you might want to ignore these files since the code is
31
+ # intended to run in multiple environments; otherwise, check them in:
32
+ # Gemfile.lock
33
+ # .ruby-version
34
+ # .ruby-gemset
35
+
36
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
37
+ .rvmrc
38
+
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "bunny_mock", :git => 'git://github.com/groovenauts/bunny-mock.git',
4
+ :branch => "features/minimum_necessary_mock"
5
+
6
+ # Specify your gem's dependencies in magellan-publisher.gemspec
7
+ gemspec
8
+
9
+ group :test do
10
+ gem "simplecov"
11
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Yuuki Noguchi
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Magellan::Publisher
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'magellan-publisher'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install magellan-publisher
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/magellan-rails/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env rake
2
+
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
9
+ require "bundler/gem_tasks"
10
+ require "rspec/core/rake_task"
11
+
12
+ RSpec::Core::RakeTask.new(:spec)
13
+
14
+ task :default => :spec
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+
3
+ module Magellan
4
+ class Publisher
5
+ def initialize(host: "127.0.0.1", port: 5672, vhost: nil, user: nil, pass: nil, timeout: 0.3)
6
+ # RabbitMQへの接続設定を作成
7
+ connection_settings = {
8
+ host: host,
9
+ port: port,
10
+ vhost: vhost,
11
+ user: user,
12
+ pass: pass,
13
+ timeout: timeout,
14
+ }
15
+
16
+ @conn = Bunny.new(connection_settings)
17
+ @conn.start
18
+ @channel = @conn.create_channel
19
+
20
+ exchange_name = ENV["MAGELLAN_PUBLISH_EXCHANGE"] || "magellan_publish"
21
+
22
+ # no_declareを設定しない場合、Exchangeに対してdeclareを実行してしまい、
23
+ # Acess Contorolにひっかかりエラーとなります
24
+ # exchangeはmagellan-conductorによって作成済みの想定です
25
+ @exchange = @channel.exchange(exchange_name, no_declare: true)
26
+ end
27
+
28
+ def convert_topic(mqtt_topic)
29
+ mqtt_topic.gsub("/", ".")
30
+ end
31
+ private :convert_topic
32
+
33
+ def publish(topic, body)
34
+ @exchange.publish(body, routing_key: convert_topic(topic))
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,5 @@
1
+ module Magellan
2
+ class Publisher
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'magellan/publisher/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "magellan-publisher"
8
+ spec.version = Magellan::Publisher::VERSION
9
+ spec.authors = ["Tomoyuki Chikanaga"]
10
+ spec.email = ["t-chikanaga@groovenauts.jp"]
11
+ spec.summary = %q{}
12
+ spec.description = %q{}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "bunny"
22
+ spec.add_runtime_dependency "json"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.6"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "bunny_mock"
28
+ end
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+
3
+ require "spec_helper"
4
+ require 'bunny'
5
+ require 'bunny_mock'
6
+ require 'json'
7
+
8
+ describe Magellan::Publisher do
9
+
10
+ describe "#publish" do
11
+
12
+ before do
13
+ @topic = "topic/aaa"
14
+ @rabbitmq_topic = "topic.aaa"
15
+ @payload = "Hello World"
16
+ @bunny = BunnyMock.new
17
+ channel = @bunny.create_channel
18
+ @exchange = @bunny.exchange('test_exchange', type: :direct, durable: false, auto_delete: false)
19
+ expect(@exchange).to receive(:publish).with(@payload, routing_key: @rabbitmq_topic)
20
+
21
+ allow(Bunny ).to receive(:new).and_return(@bunny)
22
+ allow(@bunny ).to receive(:create_channel).and_return(channel)
23
+ allow(channel).to receive(:exchange).with('test_exchange', no_declare: true).and_return(@exchange)
24
+
25
+ ENV["MAGELLAN_PUBLISH_EXCHANGE"] = "test_exchange"
26
+ @publisher = Magellan::Publisher.new(host: "127.0.0.1",
27
+ port: 5672,
28
+ vhost: "customer1.sample_project",
29
+ user: "customer1.sample_project",
30
+ pass: "pasw1")
31
+ end
32
+
33
+ it do
34
+ @publisher.publish(@topic, @payload)
35
+ end
36
+
37
+
38
+ end
39
+ end
@@ -0,0 +1,8 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+
3
+ if ENV["COVERAGE"] and not(ENV["COVERAGE"].empty?)
4
+ require "simplecov"
5
+ SimpleCov.start "rails"
6
+ end
7
+
8
+ require 'magellan/publisher'
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: magellan-publisher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tomoyuki Chikanaga
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bunny
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bunny_mock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: ''
98
+ email:
99
+ - t-chikanaga@groovenauts.jp
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - lib/magellan/publisher.rb
110
+ - lib/magellan/publisher/version.rb
111
+ - magellan-publisher.gemspec
112
+ - spec/magellan/publisher_spec.rb
113
+ - spec/spec_helper.rb
114
+ homepage: ''
115
+ licenses:
116
+ - MIT
117
+ metadata: {}
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.2.2
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: ''
138
+ test_files:
139
+ - spec/magellan/publisher_spec.rb
140
+ - spec/spec_helper.rb