opener-callback-handler 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ODk5YmE5MmY2ZTg0MDU5ZTg3MzhlYTY2M2Q2ZTJmNmVmODY5ZTY4Zg==
5
+ data.tar.gz: !binary |-
6
+ NTI1ODUxM2I2NTdiZDNjYzI0NzBiZGY1NDRkMjdmNDdlMmQ1Yjc2MQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZDNiYjBjYWRlZmY2NTIzMjFiNDM0YWUwYTA1YjYwODBjYzU2MmRiNGVmZjQy
10
+ ODVkMWU1ZjlkMDkxZjQ2ZGU4MDg0MDQ3OTU5MTc4MGQ2ZTk4M2EwMDRkNGNm
11
+ YjA5ZmM1ODlkNTczOWRkMTkwYWY3ODZmMDQ5Y2Y0ZGQzNzI0Nzk=
12
+ data.tar.gz: !binary |-
13
+ ZTc5ZTliMWVkNDcwOTk4Y2U2ZDZkNTJjZDRlOTA5NDg5ZjY3ZTYwMTg2ZjE1
14
+ YTIzOTUzNTE3NTRlYmQ5NTViNWI2MWMyYjJjMDNlY2UyMjA3OGIxZDNhZDc2
15
+ NjA3OTZiNmI5ZmZjOWNjZmZiYzVlYTkwNjcxMzJlMTNmZjBkNmU=
@@ -0,0 +1,13 @@
1
+ Copyright 2014 OpeNER Project Consortium
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -0,0 +1,31 @@
1
+ # Opener::CallbackHandler
2
+
3
+ Gem that handles the different callback URLs based on the protocol of each URL.
4
+
5
+ (HTTP, HTTPS, SQS, S3, FTP etc..) For now HTTP/HTTPS and Amazon SQS are supported.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'opener-callback-handler'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install opener-callback-handler
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create new Pull Request
@@ -0,0 +1,35 @@
1
+ require 'active_support/inflector'
2
+ require "opener/callback_handler/version"
3
+ require 'aws-sdk-core'
4
+ require 'httpclient'
5
+
6
+ ##
7
+ # First strategy that passes the validation is served. So make sure that
8
+ # if there are overlapping strategies, to put the one that needs to
9
+ # be handled, first. For example amazon_sqs URLs are also http URLs, but need
10
+ # to be handled by the amazon_sqs strategy. so http should go after the
11
+ # amazon_sqs strategy.
12
+ STRATEGIES = ["amazon_sqs", "http"]
13
+ STRATEGIES.each do |strategy|
14
+ require "opener/callback_handler/strategies/#{strategy}"
15
+ end
16
+
17
+ module Opener
18
+ class CallbackHandler
19
+ attr_accessor :url
20
+
21
+ def post(url, params = {})
22
+ strategy = select_strategy(url)
23
+ strategy.process(url, params)
24
+ end
25
+
26
+
27
+ def select_strategy(url)
28
+ STRATEGIES.map do |strategy|
29
+ "Opener::CallbackHandler::Strategies::#{strategy.camelize}".constantize.new
30
+ end.select do |strategy_class|
31
+ strategy_class.pass_validation?(url)
32
+ end.compact.first
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,25 @@
1
+ require 'json'
2
+
3
+ module Opener
4
+ class CallbackHandler
5
+ module Strategies
6
+ class AmazonSqs
7
+ def pass_validation?(url)
8
+ !!Regexp.new("^https:\/\/sqs.(.*)amazonaws.com\/.*").match(url)
9
+ end
10
+
11
+ def process(url, params = {})
12
+ send_message(url, params)
13
+ end
14
+
15
+ def send_message(url, params)
16
+ sqs = ::Aws::SQS::Client.new
17
+ params_json = params.is_a?(String) ? params : params.to_json
18
+ message_body = params.keys.include?(:message_body) ? params : {:message_body => params_json}
19
+
20
+ sqs.send_message(message_body.merge(:queue_url=>url))
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,24 @@
1
+ module Opener
2
+ class CallbackHandler
3
+ module Strategies
4
+ class Http
5
+
6
+ def pass_validation?(url)
7
+ !!Regexp.new("^https?:\/\/.*").match(url)
8
+ end
9
+
10
+ def process(url, params = {})
11
+ body_params = params.keys.include?(:body) ? params : {:body => params}
12
+ http_client.post_async(url, body_params)
13
+ end
14
+
15
+ def http_client
16
+ client = ::HTTPClient.new
17
+ client.connect_timeout = 120
18
+
19
+ return client
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,5 @@
1
+ module Opener
2
+ class CallbackHandler
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ require File.expand_path('../lib/opener/callback_handler/version', __FILE__)
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "opener-callback-handler"
5
+ spec.version = Opener::CallbackHandler::VERSION
6
+ spec.authors = ["development@olery.com"]
7
+ spec.summary = %q{Tool for handling different callback URLs based on their protocol.}
8
+ spec.description = spec.summary
9
+
10
+ spec.license = 'Apache 2.0'
11
+
12
+ spec.files = Dir.glob([
13
+ 'lib/**/*',
14
+ '*.gemspec',
15
+ 'README.md',
16
+ 'LICENSE.txt'
17
+ ]).select { |file| File.file?(file) }
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.3"
20
+ spec.add_development_dependency "rake"
21
+ spec.add_development_dependency "pry"
22
+
23
+ spec.add_dependency "json"
24
+ spec.add_dependency "activesupport"
25
+ spec.add_dependency "aws-sdk-core"
26
+ spec.add_dependency "httpclient"
27
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: opener-callback-handler
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - development@olery.com
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-16 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
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: activesupport
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
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: aws-sdk-core
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: httpclient
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Tool for handling different callback URLs based on their protocol.
112
+ email:
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - LICENSE.txt
118
+ - README.md
119
+ - lib/opener/callback_handler.rb
120
+ - lib/opener/callback_handler/strategies/amazon_sqs.rb
121
+ - lib/opener/callback_handler/strategies/http.rb
122
+ - lib/opener/callback_handler/version.rb
123
+ - opener-callback-handler.gemspec
124
+ homepage:
125
+ licenses:
126
+ - Apache 2.0
127
+ metadata: {}
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ! '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.2.2
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: Tool for handling different callback URLs based on their protocol.
148
+ test_files: []
149
+ has_rdoc: