http_transport_provider 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +64 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/http_transport_provider.gemspec +25 -0
- data/lib/http_transport_provider.rb +62 -0
- data/lib/http_transport_provider/configuration_validation.rb +19 -0
- data/lib/http_transport_provider/request.rb +26 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 11e54fafb755b94f2d1af995804b3edd0673cf0e
|
4
|
+
data.tar.gz: ec19734274a2649d80b8e887ffc7fb9d8b98067e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 65641ecc16b5501b3c24c4fd872617de0867577c84f4aa4ec4f6a7f45d1eecd1c8a28464740fd2959b350866e19988f20d6524af9f088dac17fcf1258e87b9b9
|
7
|
+
data.tar.gz: 4416a3e0e564d6d01b5f27f0fab4931aecc62768dfe3459492ec61c22295785d148db48b0854f882d1a6a9623e52ad3f80cac6696878ba79ad0855ecc1bbb9c0
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
http_transport_provider
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.3.0
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 TODO: Write your name
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# HttpTransportProvider [![Build Status](https://travis-ci.org/hetznerZA/http_transport_provider.svg?branch=master)](https://travis-ci.org/hetznerZA/http_transport_provider)
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'http_transport_provider'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install http_transport_provider
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
The provider currently only supports GET & POST.
|
21
|
+
|
22
|
+
GET:
|
23
|
+
```ruby
|
24
|
+
htp = HttpTransportProvider.new('my_identifier')
|
25
|
+
htp.configure({'verb' => "GET")
|
26
|
+
htp.send_message('http://localhost:3000', {'body' => {}})
|
27
|
+
htp.receive_message
|
28
|
+
```
|
29
|
+
|
30
|
+
GET with parameters:
|
31
|
+
```ruby
|
32
|
+
htp = HttpTransportProvider.new('my_identifier')
|
33
|
+
htp.configure({'verb' => "GET")
|
34
|
+
htp.send_message('http://localhost:3000', {'body' => {'id' => 1}})
|
35
|
+
htp.receive_message
|
36
|
+
```
|
37
|
+
|
38
|
+
POST:
|
39
|
+
```ruby
|
40
|
+
htp = HttpTransportProvider.new('my_identifier')
|
41
|
+
htp.configure({'verb' => "POST")
|
42
|
+
htp.send_message('http://localhost:3000', {'body' => {'id' => 1}})
|
43
|
+
htp.receive_message
|
44
|
+
```
|
45
|
+
|
46
|
+
Basic Auth:
|
47
|
+
```ruby
|
48
|
+
message = {'body' => {}, 'credentials' => {'username' => 'user', 'password' => 'secret'}}
|
49
|
+
```
|
50
|
+
|
51
|
+
## Development
|
52
|
+
|
53
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
54
|
+
|
55
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
56
|
+
|
57
|
+
## Contributing
|
58
|
+
|
59
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/http_transport_provider.
|
60
|
+
|
61
|
+
|
62
|
+
## License
|
63
|
+
|
64
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "http_transport_provider"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "http_transport_provider"
|
7
|
+
spec.version = "0.1.0"
|
8
|
+
spec.authors = ["Tiaan van Deventer"]
|
9
|
+
spec.email = ["tiaanvandeventer@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{HTTP transport provider}
|
12
|
+
spec.description = %q{HTTP transport provider that makes use of the soar_transport_api}
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
spec.bindir = "exe"
|
17
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency 'soar_transport_api', '~> 0.1.1'
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
24
|
+
spec.add_development_dependency "webmock", "~> 2.1.0"
|
25
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'soar_transport_api'
|
2
|
+
require 'uri'
|
3
|
+
require 'net/http'
|
4
|
+
require 'openssl'
|
5
|
+
require 'http_transport_provider/configuration_validation'
|
6
|
+
require 'http_transport_provider/request'
|
7
|
+
|
8
|
+
class HttpTransportProvider < SoarTransportApi::TransportAPI
|
9
|
+
class NotConfigured < StandardError; end
|
10
|
+
|
11
|
+
def initialize(transport_identifier)
|
12
|
+
super(transport_identifier)
|
13
|
+
@message_response = []
|
14
|
+
end
|
15
|
+
|
16
|
+
def configure(config)
|
17
|
+
if ConfigurationValidation.valid?(config)
|
18
|
+
@configuration = config
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
def send_message(uri, message)
|
24
|
+
#TODO: Message validation
|
25
|
+
uri = URI::parse uri
|
26
|
+
raise NotConfigured if @configuration.nil?
|
27
|
+
|
28
|
+
request = Request.build(uri, @configuration, message['body'])
|
29
|
+
response = connection(uri).request(request)
|
30
|
+
|
31
|
+
@message_response.push(response)
|
32
|
+
map_response_code_to_delivery_status(response.code)
|
33
|
+
end
|
34
|
+
|
35
|
+
def receive_message
|
36
|
+
@message_response.pop.body
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
#TODO: enable/disable verify_mode
|
41
|
+
def connection(uri)
|
42
|
+
connection = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https', :verify_mode => OpenSSL::SSL::VERIFY_NONE)
|
43
|
+
end
|
44
|
+
|
45
|
+
def map_response_code_to_delivery_status(code)
|
46
|
+
if code == '200'
|
47
|
+
DELIVERY_SUCCESS
|
48
|
+
elsif code == '408'
|
49
|
+
DELIVERY_TIMEOUT
|
50
|
+
elsif code == '401'
|
51
|
+
DELIVERY_REJECTED
|
52
|
+
elsif code == '500'
|
53
|
+
DELIVERY_FAILURE
|
54
|
+
elsif code == '508'
|
55
|
+
DELIVERY_PENDING
|
56
|
+
elsif code == '208'
|
57
|
+
"Delivery status unkown"
|
58
|
+
else
|
59
|
+
"Delivery status unsupported"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ConfigurationValidation
|
2
|
+
class InvalidKeywordError < StandardError; end
|
3
|
+
class InvalidValueError < StandardError; end
|
4
|
+
class MissingKeywordError < StandardError; end
|
5
|
+
|
6
|
+
def self.valid?(config)
|
7
|
+
raise MissingKeywordError if config.include?('verb') == false
|
8
|
+
|
9
|
+
valid_verbs = ['GET', 'POST']
|
10
|
+
raise InvalidValueError if valid_verbs.include?(config['verb'].upcase) == false
|
11
|
+
|
12
|
+
supported_config_keys = ['verb', 'credentials']
|
13
|
+
config.each do |k,v|
|
14
|
+
raise InvalidKeywordError if supported_config_keys.include?(k) == false
|
15
|
+
end
|
16
|
+
|
17
|
+
true
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
module Request
|
5
|
+
def self.build(uri, config, params = {})
|
6
|
+
verb = config['verb']
|
7
|
+
if verb.upcase == 'GET'
|
8
|
+
if params.empty? == false
|
9
|
+
uri.query = URI.encode_www_form(params)
|
10
|
+
end
|
11
|
+
request = Net::HTTP::Get.new uri
|
12
|
+
elsif verb.upcase == 'POST'
|
13
|
+
request = Net::HTTP::Post.new(uri)
|
14
|
+
if params.empty? == false
|
15
|
+
request.set_form_data(params)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
if config['credentials'].nil? == false
|
20
|
+
request.basic_auth(config['credentials']['username'], config['credentials']['password'])
|
21
|
+
end
|
22
|
+
|
23
|
+
#TODO: check if return object is valid net/http request
|
24
|
+
request
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: http_transport_provider
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tiaan van Deventer
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: soar_transport_api
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.1.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.1.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.12'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.12'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.1.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 2.1.0
|
83
|
+
description: HTTP transport provider that makes use of the soar_transport_api
|
84
|
+
email:
|
85
|
+
- tiaanvandeventer@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".DS_Store"
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".ruby-gemset"
|
94
|
+
- ".ruby-version"
|
95
|
+
- ".travis.yml"
|
96
|
+
- Gemfile
|
97
|
+
- LICENSE.txt
|
98
|
+
- README.md
|
99
|
+
- Rakefile
|
100
|
+
- bin/console
|
101
|
+
- bin/setup
|
102
|
+
- http_transport_provider.gemspec
|
103
|
+
- lib/http_transport_provider.rb
|
104
|
+
- lib/http_transport_provider/configuration_validation.rb
|
105
|
+
- lib/http_transport_provider/request.rb
|
106
|
+
homepage:
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
metadata: {}
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 2.5.1
|
127
|
+
signing_key:
|
128
|
+
specification_version: 4
|
129
|
+
summary: HTTP transport provider
|
130
|
+
test_files: []
|