magellan-rails 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7796c0cc393d2e17a56de656c8022d29ec771b86
4
- data.tar.gz: 1554fbf277c4c14f4e40cbc1f4ba596085ecb01d
3
+ metadata.gz: 8d0de6e82993e776a9176ee74883355927e74455
4
+ data.tar.gz: dbc15a0c348de7e03f7bd235308fcac8be766b84
5
5
  SHA512:
6
- metadata.gz: c2fdc42264aedba9574209ec711f36318ace206e48e8c9e0a78d918493f54079ebf0828c1390fffc19a6b5446d63d24ab86d5a7c19cb251ba195c4e86803bec1
7
- data.tar.gz: bcf0fe036e69f5894306d802c50cdcc22c60791bfa961f3fddb4ef78ee638c23d0b7ae22a503162fed28c02a73aafc5dfc673277acb953b9c62f7fd15a21db4f
6
+ metadata.gz: f31a049e23ecaa65e0824685ef3d1b8183083bfcde6e9880351524d0a7ada1002db0ee10b1273124cd15f073c2d104f12e0a22f59cbd0e9a33d21e5868023557
7
+ data.tar.gz: 520c958dfec234f2371614f504cdfd56f3d09d9c959f093ea15189c6774b032019cad3054ec122a63dabd79632c20951c3d449cdc5096034124854c669ffac61
data/Gemfile.lock CHANGED
@@ -8,7 +8,7 @@ GIT
8
8
  PATH
9
9
  remote: .
10
10
  specs:
11
- magellan-rails (0.0.1)
11
+ magellan-rails (0.0.2)
12
12
  bunny
13
13
  json
14
14
  railties (~> 4.1.0)
@@ -16,16 +16,16 @@ PATH
16
16
  GEM
17
17
  remote: https://rubygems.org/
18
18
  specs:
19
- actionpack (4.1.4)
20
- actionview (= 4.1.4)
21
- activesupport (= 4.1.4)
19
+ actionpack (4.1.6)
20
+ actionview (= 4.1.6)
21
+ activesupport (= 4.1.6)
22
22
  rack (~> 1.5.2)
23
23
  rack-test (~> 0.6.2)
24
- actionview (4.1.4)
25
- activesupport (= 4.1.4)
24
+ actionview (4.1.6)
25
+ activesupport (= 4.1.6)
26
26
  builder (~> 3.1)
27
27
  erubis (~> 2.7.0)
28
- activesupport (4.1.4)
28
+ activesupport (4.1.6)
29
29
  i18n (~> 0.6, >= 0.6.9)
30
30
  json (~> 1.7, >= 1.7.7)
31
31
  minitest (~> 5.1)
@@ -33,19 +33,19 @@ GEM
33
33
  tzinfo (~> 1.1)
34
34
  amq-protocol (1.9.2)
35
35
  builder (3.2.2)
36
- bunny (1.4.0)
36
+ bunny (1.5.0)
37
37
  amq-protocol (>= 1.9.2)
38
38
  diff-lcs (1.2.5)
39
39
  erubis (2.7.0)
40
40
  i18n (0.6.11)
41
41
  json (1.8.1)
42
- minitest (5.4.0)
42
+ minitest (5.4.2)
43
43
  rack (1.5.2)
44
44
  rack-test (0.6.2)
45
45
  rack (>= 1.0)
46
- railties (4.1.4)
47
- actionpack (= 4.1.4)
48
- activesupport (= 4.1.4)
46
+ railties (4.1.6)
47
+ actionpack (= 4.1.6)
48
+ activesupport (= 4.1.6)
49
49
  rake (>= 0.8.7)
50
50
  thor (>= 0.18.1, < 2.0)
51
51
  rake (10.3.2)
@@ -1,2 +1,3 @@
1
1
 
2
2
  require "magellan/extentions/rails/engine"
3
+ require "magellan/extentions/rails/application"
@@ -0,0 +1,54 @@
1
+ # coding: utf-8
2
+
3
+ require "rails/application"
4
+ require "magellan/worker"
5
+ require "magellan/subscriber"
6
+
7
+ module Magellan
8
+ module Extentions
9
+ module Rails
10
+ module Application
11
+ def magellan_build_publish_request(topic, payload)
12
+ {
13
+ "headers" => {
14
+ "Method" => "PUBLISH",
15
+ "Path-Info" => topic,
16
+ },
17
+ "body" => payload,
18
+ "body_encoding" => "plain",
19
+ }
20
+ end
21
+ private :magellan_build_publish_request
22
+
23
+ def magellan_parse_publish_request(env)
24
+ if env["REQUEST_METHOD"] == "POST" and env["HTTP_X_EMULATE_MQTT"]
25
+ # POST with HTTP header X-EMULATE-MQTT
26
+ magellan_build_publish_request(env["PATH_INFO"].sub(/\A\//, ""), env["rack.input"].read)
27
+ elsif env["REQUEST_METHOD"] == "PUBLISH"
28
+ # link_to(text, "topic?payload", method: :publish, remote: true)
29
+ magellan_build_publish_request(env["PATH_INFO"].sub(/\A\//, ""), URI.unescape(env["QUERY_STRING"]))
30
+ end
31
+ end
32
+ private :magellan_parse_publish_request
33
+
34
+ def call(env)
35
+ if request_object = magellan_parse_publish_request(env)
36
+ @subscriber_executor ||= Magellan::Subscriber::Executor.new
37
+ @subscriber_executor.execute(request_object)
38
+ res = ActionDispatch::Response.new
39
+ [200, res.headers, []]
40
+ else
41
+ super
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ if Rails.env.development?
50
+ class ::Rails::Application
51
+ prepend Magellan::Extentions::Rails::Application
52
+ end
53
+ end
54
+
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
 
3
3
  require "rails/engine"
4
- require "magellan/worker/config"
4
+ require "magellan/worker"
5
5
 
6
6
  module Magellan
7
7
  module Extentions
@@ -1,6 +1,8 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require "magellan"
3
3
  require 'magellan/rails/railtie'
4
+ require "magellan/extentions/rails"
5
+ require "magellan/subscriber"
4
6
 
5
7
  module Magellan::Rails
6
8
  autoload :Executor, 'magellan/rails/executor'
@@ -1,5 +1,5 @@
1
1
  module Magellan
2
2
  module Rails
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magellan-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuuki Noguchi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-17 00:00:00.000000000 Z
11
+ date: 2014-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -111,6 +111,7 @@ files:
111
111
  - lib/magellan.rb
112
112
  - lib/magellan/extentions.rb
113
113
  - lib/magellan/extentions/rails.rb
114
+ - lib/magellan/extentions/rails/application.rb
114
115
  - lib/magellan/extentions/rails/engine.rb
115
116
  - lib/magellan/rails.rb
116
117
  - lib/magellan/rails/executor.rb