opener-callback-handler 0.0.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5fd7f9d735aab8917d4f5c64090f6ffebc3a0d3d
4
- data.tar.gz: b0acc4cf19f01a23a6339d6675d11a6a5152a62c
3
+ metadata.gz: 728ac45c10bdd72761739eacf9ef463d7718f319
4
+ data.tar.gz: b7ff5d6086fcc50e3db3084b04f103569899dfc0
5
5
  SHA512:
6
- metadata.gz: f174cba7d89489209640c9ce91ae2b87cc3ecb1a0334260bea051097a9b246d10286d45cf52ad863ab2ecf33ee72c3084d2445aadbc18ef7abc7fb50d5ffe9a5
7
- data.tar.gz: 249579cd869a8024229fa5721c3fc48dd77da8462f459707b8652b08c7347cfe09ced297b3d87b1c80e79d9afd884e3664d56c10ee78edc406936d87ca21cedd
6
+ metadata.gz: 1c9168c9e7807562a72217cb29c654593d53717f550071bf410ae3aa7e7f90a31e5c29e26160c1b81a22795f9e2ed69a2a736f8fe20fb50d7a15caa681569586
7
+ data.tar.gz: 00285dfb7176cb3f009bd0b538fec3fc7f7750ac3962f162e3d2b14fea59583aa759235476f81b1e951f57c41613ad84d6f3c8b29b49427a41e7269625b66d25
data/README.md CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  Gem that handles the different callback URLs based on the protocol of each URL.
4
4
 
5
- (HTTP, HTTPS, SQS, S3, FTP etc..) For now HTTP/HTTPS and Amazon SQS are supported.
5
+ (HTTP, HTTPS, SQS, S3, FTP etc..) For now HTTP/HTTPS and Amazon SQS are
6
+ supported.
6
7
 
7
8
  ## Installation
8
9
 
@@ -20,7 +21,8 @@ Or install it yourself as:
20
21
 
21
22
  ## Usage
22
23
 
23
- For SQS, `AWS_REGION` `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables should be set on startup of the webservice or daemon.
24
+ For SQS, `AWS_REGION` `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`
25
+ environment variables should be set on startup of the webservice or daemon.
24
26
 
25
27
  ## Contributing
26
28
 
@@ -1,35 +1,48 @@
1
- require 'active_support/inflector'
2
- require "opener/callback_handler/version"
3
- require 'aws-sdk-core'
1
+ require 'json'
2
+ require 'aws-sdk'
4
3
  require 'httpclient'
5
4
 
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_relative "callback_handler/strategies/#{strategy}"
15
- end
5
+ require_relative 'callback_handler/version'
6
+ require_relative 'callback_handler/strategies/amazon_sqs'
7
+ require_relative 'callback_handler/strategies/http'
16
8
 
17
9
  module Opener
18
10
  class CallbackHandler
19
- attr_accessor :url
20
-
11
+ ##
12
+ # The available strategies. These are processed in order to make sure the
13
+ # order is correct (e.g. AmazonSqs should take precedence over Http).
14
+ #
15
+ # @return [Array]
16
+ #
17
+ STRATEGIES = [
18
+ Opener::CallbackHandler::Strategies::AmazonSqs,
19
+ Opener::CallbackHandler::Strategies::Http,
20
+ ]
21
+
22
+ ##
23
+ # @param [String] url
24
+ # @param [Hash] params
25
+ #
21
26
  def post(url, params = {})
22
27
  strategy = select_strategy(url)
23
- strategy.process(url, params)
28
+
29
+ unless strategy
30
+ raise ArgumentError, "No strategy for URL #{url.inspect}"
31
+ end
32
+
33
+ strategy.new.process(url, params)
24
34
  end
25
-
26
-
35
+
36
+ ##
37
+ # Returns the strategy class to use based on the input URL.
38
+ #
39
+ # @param [String] url
40
+ # @return [Class]
41
+ #
27
42
  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
43
+ return STRATEGIES.find do |const|
44
+ const.pass_validation?(url)
45
+ end
33
46
  end
34
- end
35
- end
47
+ end # CallbackHandler
48
+ end # Opener
@@ -1,25 +1,60 @@
1
- require 'json'
2
-
3
1
  module Opener
4
2
  class CallbackHandler
5
3
  module Strategies
6
- class AmazonSqs
7
- def pass_validation?(url)
8
- !!Regexp.new("^https:\/\/sqs.(.*)amazonaws.com\/.*").match(url)
4
+ ##
5
+ # Strategy for submitting data to an Amazon SQS queue. This strategy
6
+ # expects URIs in the following format:
7
+ #
8
+ # sqs://<name>
9
+ #
10
+ # Here `<name>` is the name of the queue to use.
11
+ #
12
+ # @!attribute [r] sqs
13
+ # @return [AWS::SQS]
14
+ #
15
+ class AmazonSqs
16
+ attr_reader :sqs
17
+
18
+ ##
19
+ # @param [String] url
20
+ # @return [TrueClass|FalseClass]
21
+ #
22
+ def self.pass_validation?(url)
23
+ return !!(url =~ /^sqs:\/\/.+/)
9
24
  end
10
-
11
- def process(url, params = {})
12
- send_message(url, params)
25
+
26
+ def initialize
27
+ @sqs = AWS::SQS.new
28
+ end
29
+
30
+ ##
31
+ # @param [String] uri The queue URI
32
+ # @param [Hash] params The message to submit.
33
+ #
34
+ def process(uri, params = {})
35
+ queue = queue_for_uri(uri)
36
+
37
+ queue.send_message(JSON.dump(params))
38
+ end
39
+
40
+ ##
41
+ # @param [String] uri
42
+ # @return [AWS::SQS::Queue]
43
+ #
44
+ def queue_for_uri(uri)
45
+ parsed = URI.parse(uri)
46
+
47
+ return queue_for_name(parsed.host)
13
48
  end
14
49
 
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))
50
+ ##
51
+ # @param [String] name
52
+ # @return [AWS::SQS::Queue]
53
+ #
54
+ def queue_for_name(name)
55
+ return sqs.queues.named(name)
21
56
  end
22
- end
23
- end
24
- end
25
- end
57
+ end # AmazonSqs
58
+ end # Strategies
59
+ end # CallbackHandler
60
+ end # Opener
@@ -1,24 +1,48 @@
1
1
  module Opener
2
2
  class CallbackHandler
3
3
  module Strategies
4
+ ##
5
+ # Strategy for submitting data to a regular HTTP URL. This strategy
6
+ # submits data as JSON while making sure the correct Content-Type header
7
+ # is set.
8
+ #
9
+ # @!attribute [r] http
10
+ # @return [HTTPClient]
11
+ #
4
12
  class Http
5
-
6
- def pass_validation?(url)
7
- !!Regexp.new("^https?:\/\/.*").match(url)
13
+ attr_reader :http
14
+
15
+ ##
16
+ # The headers to use when submitting data.
17
+ #
18
+ # @return [Hash]
19
+ #
20
+ HEADERS = {
21
+ 'Content-Type' => 'application/json'
22
+ }
23
+
24
+ ##
25
+ # @param [String] url
26
+ # @return [TrueClass|FalseClass]
27
+ #
28
+ def self.pass_validation?(url)
29
+ return !!Regexp.new("^https?:\/\/.+").match(url)
8
30
  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)
31
+
32
+ def initialize
33
+ @http = HTTPClient.new
13
34
  end
14
-
15
- def http_client
16
- client = ::HTTPClient.new
17
- client.connect_timeout = 120
18
35
 
19
- return client
36
+ ##
37
+ # @param [String] url
38
+ # @param [Hash] params
39
+ #
40
+ def process(url, params = {})
41
+ body = JSON.dump(params)
42
+
43
+ http.post(url, :body => body, :header => HEADERS)
20
44
  end
21
- end
22
- end
23
- end
24
- end
45
+ end # Http
46
+ end # Strategies
47
+ end # CallbackHandler
48
+ end # Opener
@@ -1,5 +1,5 @@
1
1
  module Opener
2
2
  class CallbackHandler
3
- VERSION = "0.0.2"
3
+ VERSION = '1.0.0'
4
4
  end
5
5
  end
@@ -1,10 +1,10 @@
1
1
  require File.expand_path('../lib/opener/callback_handler/version', __FILE__)
2
2
 
3
3
  Gem::Specification.new do |spec|
4
- spec.name = "opener-callback-handler"
4
+ spec.name = 'opener-callback-handler'
5
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.}
6
+ spec.authors = ['development@olery.com']
7
+ spec.summary = 'Tool for handling different callback URLs based on their protocol.'
8
8
  spec.description = spec.summary
9
9
 
10
10
  spec.license = 'Apache 2.0'
@@ -16,12 +16,10 @@ Gem::Specification.new do |spec|
16
16
  'LICENSE.txt'
17
17
  ]).select { |file| File.file?(file) }
18
18
 
19
- spec.add_development_dependency "bundler", "~> 1.3"
20
- spec.add_development_dependency "rake"
21
- spec.add_development_dependency "pry"
19
+ spec.add_dependency 'aws-sdk', '~> 1.0'
20
+ spec.add_dependency 'httpclient'
22
21
 
23
- spec.add_dependency "json"
24
- spec.add_dependency "activesupport"
25
- spec.add_dependency "aws-sdk-core"
26
- spec.add_dependency "httpclient"
22
+ spec.add_development_dependency 'bundler'
23
+ spec.add_development_dependency 'rake'
24
+ spec.add_development_dependency 'rspec'
27
25
  end
metadata CHANGED
@@ -1,148 +1,121 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opener-callback-handler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - development@olery.com
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-09 00:00:00.000000000 Z
11
+ date: 2014-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
15
- version_requirements: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ~>
18
- - !ruby/object:Gem::Version
19
- version: '1.3'
14
+ name: aws-sdk
20
15
  requirement: !ruby/object:Gem::Requirement
21
16
  requirements:
22
- - - ~>
17
+ - - "~>"
23
18
  - !ruby/object:Gem::Version
24
- version: '1.3'
19
+ version: '1.0'
20
+ type: :runtime
25
21
  prerelease: false
26
- type: :development
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
22
  version_requirements: !ruby/object:Gem::Requirement
30
23
  requirements:
31
- - - '>='
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- requirement: !ruby/object:Gem::Requirement
35
- requirements:
36
- - - '>='
24
+ - - "~>"
37
25
  - !ruby/object:Gem::Version
38
- version: '0'
39
- prerelease: false
40
- type: :development
26
+ version: '1.0'
41
27
  - !ruby/object:Gem::Dependency
42
- name: pry
43
- version_requirements: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - '>='
46
- - !ruby/object:Gem::Version
47
- version: '0'
28
+ name: httpclient
48
29
  requirement: !ruby/object:Gem::Requirement
49
30
  requirements:
50
- - - '>='
31
+ - - ">="
51
32
  - !ruby/object:Gem::Version
52
33
  version: '0'
34
+ type: :runtime
53
35
  prerelease: false
54
- type: :development
55
- - !ruby/object:Gem::Dependency
56
- name: json
57
36
  version_requirements: !ruby/object:Gem::Requirement
58
37
  requirements:
59
- - - '>='
38
+ - - ">="
60
39
  - !ruby/object:Gem::Version
61
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
62
43
  requirement: !ruby/object:Gem::Requirement
63
44
  requirements:
64
- - - '>='
45
+ - - ">="
65
46
  - !ruby/object:Gem::Version
66
47
  version: '0'
48
+ type: :development
67
49
  prerelease: false
68
- type: :runtime
69
- - !ruby/object:Gem::Dependency
70
- name: activesupport
71
50
  version_requirements: !ruby/object:Gem::Requirement
72
51
  requirements:
73
- - - '>='
52
+ - - ">="
74
53
  - !ruby/object:Gem::Version
75
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
76
57
  requirement: !ruby/object:Gem::Requirement
77
58
  requirements:
78
- - - '>='
59
+ - - ">="
79
60
  - !ruby/object:Gem::Version
80
61
  version: '0'
62
+ type: :development
81
63
  prerelease: false
82
- type: :runtime
83
- - !ruby/object:Gem::Dependency
84
- name: aws-sdk-core
85
64
  version_requirements: !ruby/object:Gem::Requirement
86
65
  requirements:
87
- - - '>='
66
+ - - ">="
88
67
  - !ruby/object:Gem::Version
89
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
90
71
  requirement: !ruby/object:Gem::Requirement
91
72
  requirements:
92
- - - '>='
73
+ - - ">="
93
74
  - !ruby/object:Gem::Version
94
75
  version: '0'
76
+ type: :development
95
77
  prerelease: false
96
- type: :runtime
97
- - !ruby/object:Gem::Dependency
98
- name: httpclient
99
78
  version_requirements: !ruby/object:Gem::Requirement
100
79
  requirements:
101
- - - '>='
80
+ - - ">="
102
81
  - !ruby/object:Gem::Version
103
82
  version: '0'
104
- requirement: !ruby/object:Gem::Requirement
105
- requirements:
106
- - - '>='
107
- - !ruby/object:Gem::Version
108
- version: '0'
109
- prerelease: false
110
- type: :runtime
111
83
  description: Tool for handling different callback URLs based on their protocol.
112
- email:
84
+ email:
113
85
  executables: []
114
86
  extensions: []
115
87
  extra_rdoc_files: []
116
88
  files:
89
+ - LICENSE.txt
90
+ - README.md
117
91
  - lib/opener/callback_handler.rb
118
- - lib/opener/callback_handler/version.rb
119
92
  - lib/opener/callback_handler/strategies/amazon_sqs.rb
120
93
  - lib/opener/callback_handler/strategies/http.rb
94
+ - lib/opener/callback_handler/version.rb
121
95
  - opener-callback-handler.gemspec
122
- - README.md
123
- - LICENSE.txt
124
- homepage:
96
+ homepage:
125
97
  licenses:
126
98
  - Apache 2.0
127
99
  metadata: {}
128
- post_install_message:
100
+ post_install_message:
129
101
  rdoc_options: []
130
102
  require_paths:
131
103
  - lib
132
104
  required_ruby_version: !ruby/object:Gem::Requirement
133
105
  requirements:
134
- - - '>='
106
+ - - ">="
135
107
  - !ruby/object:Gem::Version
136
108
  version: '0'
137
109
  required_rubygems_version: !ruby/object:Gem::Requirement
138
110
  requirements:
139
- - - '>='
111
+ - - ">="
140
112
  - !ruby/object:Gem::Version
141
113
  version: '0'
142
114
  requirements: []
143
- rubyforge_project:
144
- rubygems_version: 2.1.9
145
- signing_key:
115
+ rubyforge_project:
116
+ rubygems_version: 2.2.2
117
+ signing_key:
146
118
  specification_version: 4
147
119
  summary: Tool for handling different callback URLs based on their protocol.
148
120
  test_files: []
121
+ has_rdoc: