phlegethon 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in phlegethon.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 phil
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.
@@ -0,0 +1,79 @@
1
+ _ _ _ _
2
+ _ __ | |__ | | ___ __ _ ___| |_| |__ ___ _ __
3
+ | '_ \| '_ \| |/ _ \/ _` |/ _ \ __| '_ \ / _ \| '_ \
4
+ | |_) | | | | | __/ (_| | __/ |_| | | | (_) | | | |
5
+ | .__/|_| |_|_|\___|\__, |\___|\__|_| |_|\___/|_| |_|
6
+ |_| |___/
7
+
8
+ Welcome to phlegethon
9
+ =====================
10
+
11
+ Phlegethon is an endpoint for
12
+ [PayPal Webhooks](https://developer.paypal.com/docs/integration/direct/rest-webhooks-overview/)
13
+ which forwards all requests to
14
+ [RabbitMQ](https://www.rabbitmq.com/).
15
+
16
+ ## Installation
17
+
18
+ Add this line to your application's Gemfile:
19
+
20
+ gem 'phlegethon'
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ Or install it yourself as:
27
+
28
+ $ gem install phlegethon
29
+
30
+ ## Usage
31
+
32
+ Simply run
33
+
34
+ phlegethon
35
+
36
+ It will look for a config file in the following places
37
+
38
+ ./phlegethon.yml
39
+ ~/.phlegethon.yml
40
+
41
+ ## Configuration
42
+
43
+ A phlegethon config file may look like this; these are the defaults
44
+
45
+ rabbitmq:
46
+ extension: paypal
47
+ host: localhost
48
+ server:
49
+ port: 9292
50
+ ssl: true
51
+
52
+ ## Prerequisites
53
+
54
+ To use phlegethon with https you have to have libssl-dev installed
55
+ before installing eventmachine.
56
+
57
+ apt-get install libssl-dev
58
+ gem install eventmachine
59
+
60
+ ## Contributing
61
+
62
+ 1. Fork it
63
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
64
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
65
+ 4. Push to the branch (`git push origin my-new-feature`)
66
+ 5. Create new Pull Request
67
+
68
+ ## Trivia
69
+
70
+ In Greek mythology, the river Phlegethon (Φλεγέθων, English
71
+ translation: "flaming") or Pyriphlegethon (Πυριφλεγέθων, English
72
+ translation: "fire-flaming") was one of the five rivers in the
73
+ infernal regions of the underworld, along with the rivers Styx, Lethe,
74
+ Cocytus, and Acheron. Plato describes it as "a stream of fire, which
75
+ coils round the earth and flows into the depths of Tartarus". It
76
+ was parallel to the river Styx. It is said that the goddess Styx was
77
+ in love with Phlegethon, but she was consumed by his flames and sent
78
+ to Hades. Eventually when Hades allowed her river to flow through,
79
+ they reunited. [Wikipedia](https://en.wikipedia.org/wiki/Phlegethon)
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.join(%w(.. .. lib phlegethon)), __FILE__)
4
+
5
+ Phlegethon::Exec.run(ARGV)
@@ -0,0 +1,19 @@
1
+ # apt-get install libssl-dev
2
+ # gem install thin
3
+ # gem install eventmachine
4
+ # iptables -I INPUT -p tcp --dport 9292 -j ACCEPT
5
+ #
6
+ # thin start --ssl -p 9292
7
+ # curl -k https://localhost:9292/
8
+
9
+ require 'pp'
10
+
11
+ run Proc.new { |env|
12
+ # Extract the requested path from the request
13
+ req = Rack::Request.new(env)
14
+
15
+ pp env
16
+ pp req
17
+
18
+ [200, {}, []]
19
+ }
@@ -0,0 +1,8 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ require "phlegethon/version"
4
+ require "phlegethon/exec"
5
+
6
+ module Phlegethon
7
+ # Your code goes here...
8
+ end
@@ -0,0 +1,59 @@
1
+ require 'yaml'
2
+
3
+ require 'json'
4
+ require 'thin'
5
+ require 'bunny'
6
+
7
+ module Phlegethon
8
+ module Exec
9
+
10
+ # TODO make exchange or queue name configurable
11
+ EXCHANGE = 'paypal'
12
+
13
+ extend self
14
+
15
+ attr_accessor :exchange
16
+
17
+ def run(args)
18
+ init_bunny
19
+ # TODO make port and bind address configurable
20
+ server = Thin::Server.new('0.0.0.0', 3002, handler)
21
+ server.start
22
+ end
23
+
24
+ def handler
25
+ ->(env) {
26
+ # TODO perform business logic on posted data
27
+ output = deep_encode(env, 'UTF-8')
28
+ exchange.publish(JSON.unparse(output))
29
+ # TODO make debug response configurable
30
+ [200, {'Content-Type' => 'text/plain'}, output.to_yaml]
31
+ }
32
+ end
33
+
34
+ # TODO steal recoonect from simon or monitoring in vr_dev
35
+ def init_bunny
36
+ # TODO make bunny configurable
37
+ bunny = Bunny.new read_timeout: 10, heartbeat: 10
38
+ bunny.start
39
+ bunny_channel = bunny.create_channel
40
+ self.exchange = bunny_channel.fanout(EXCHANGE)
41
+ end
42
+
43
+ # TODO move to gem trickery
44
+ def deep_encode(data, enc)
45
+ case data
46
+ when String
47
+ data.encode(enc)
48
+ when Array
49
+ data.map { |e| deep_encode(e, enc) }
50
+ when Hash
51
+ data.inject({}) do |r, a|
52
+ r.merge deep_encode(a[0], enc) => deep_encode(a[1], enc)
53
+ end
54
+ else data
55
+ end
56
+ end
57
+
58
+ end
59
+ end
@@ -0,0 +1,3 @@
1
+ module Phlegethon
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'phlegethon/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "phlegethon"
8
+ spec.version = Phlegethon::VERSION
9
+ spec.authors = ["Phil Hofmann"]
10
+ spec.email = ["phil@branch14.org"]
11
+ spec.description = %q{Bridging PayPal Webhooks to RabbitMQ}
12
+ spec.summary = %q{Bridging PayPal Webhooks to RabbitMQ}
13
+ spec.homepage = "http://github.com/branch14/phlegethon"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency 'bunny'
25
+ spec.add_dependency 'thin'
26
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: phlegethon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Phil Hofmann
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-09-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bunny
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: thin
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Bridging PayPal Webhooks to RabbitMQ
79
+ email:
80
+ - phil@branch14.org
81
+ executables:
82
+ - phlegethon
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - .gitignore
87
+ - Gemfile
88
+ - LICENSE.txt
89
+ - README.md
90
+ - Rakefile
91
+ - bin/phlegethon
92
+ - config.ru
93
+ - lib/phlegethon.rb
94
+ - lib/phlegethon/exec.rb
95
+ - lib/phlegethon/version.rb
96
+ - phlegethon.gemspec
97
+ homepage: http://github.com/branch14/phlegethon
98
+ licenses:
99
+ - MIT
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ segments:
111
+ - 0
112
+ hash: -3554166032137022905
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ segments:
120
+ - 0
121
+ hash: -3554166032137022905
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 1.8.23
125
+ signing_key:
126
+ specification_version: 3
127
+ summary: Bridging PayPal Webhooks to RabbitMQ
128
+ test_files: []