roar 0.12.8 → 0.12.9
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 +4 -4
- data/CHANGES.markdown +4 -0
- data/lib/roar.rb +4 -1
- data/lib/roar/representer/transport/net_http.rb +1 -59
- data/lib/roar/representer/transport/net_http/request.rb +75 -0
- data/lib/roar/version.rb +1 -1
- data/test/fixtures/sample.pem +31 -0
- data/test/lib/roar/representer/transport/net_http/request_test.rb +64 -0
- metadata +7 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bcbcc9501060b58047a296ceab9a48a3dd235251
|
4
|
+
data.tar.gz: 45ada5410ffee101229c7f07edf8bf33f80e5c45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18f9be695ec8707c8bf5591aa669d6dcc38cc65c0b41eba490f54146298d9284eb7be8afd1dffcd6f121f862b230bce1cd14459d224b4f2ac62003122f7a3bca
|
7
|
+
data.tar.gz: 2d47ba5c28f74c6cc4952db4a298b90ad618a7b6730cfac6286c43773d1a05284fac56bea603f1b310f7752c1b888a7f5a9de12d08bf5d503e25866e186b530a
|
data/CHANGES.markdown
CHANGED
data/lib/roar.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
require
|
2
|
-
require "uri"
|
1
|
+
require 'roar/representer/transport/net_http/request'
|
3
2
|
|
4
3
|
module Roar
|
5
4
|
module Representer
|
@@ -10,63 +9,6 @@ module Roar
|
|
10
9
|
#
|
11
10
|
# The following options are available:
|
12
11
|
class NetHTTP
|
13
|
-
class Request # TODO: implement me.
|
14
|
-
def initialize(options)
|
15
|
-
@uri = parse_uri(options[:uri]) # TODO: add :uri.
|
16
|
-
@as = options[:as]
|
17
|
-
@body = options[:body]
|
18
|
-
@options = options
|
19
|
-
|
20
|
-
@http = Net::HTTP.new(uri.host, uri.port)
|
21
|
-
end
|
22
|
-
|
23
|
-
def call(what)
|
24
|
-
@req = what.new(uri.request_uri)
|
25
|
-
|
26
|
-
# if options[:ssl]
|
27
|
-
# uri.port = Net::HTTP.https_default_port()
|
28
|
-
# end
|
29
|
-
https!
|
30
|
-
basic_auth!
|
31
|
-
|
32
|
-
req.content_type = as
|
33
|
-
req["accept"] = as # TODO: test me. # DISCUSS: if Accept is not set, rails treats this request as as "text/html".
|
34
|
-
req.body = body if body
|
35
|
-
|
36
|
-
yield req if block_given?
|
37
|
-
|
38
|
-
http.request(req).tap do |res|
|
39
|
-
raise UnauthorizedError if res.is_a?(Net::HTTPUnauthorized) # FIXME: make this better. # DISCUSS: abstract all that crap here?
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def get
|
44
|
-
call(Net::HTTP::Get)
|
45
|
-
end
|
46
|
-
|
47
|
-
private
|
48
|
-
attr_reader :uri, :as, :body, :options, :req, :http
|
49
|
-
|
50
|
-
def parse_uri(url)
|
51
|
-
uri = URI(url)
|
52
|
-
raise "Incorrect URL `#{url}`. Maybe you forgot http://?" if uri.instance_of?(URI::Generic)
|
53
|
-
uri
|
54
|
-
end
|
55
|
-
|
56
|
-
def https!
|
57
|
-
return unless uri.scheme == 'https'
|
58
|
-
|
59
|
-
@http.use_ssl = true
|
60
|
-
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
61
|
-
end
|
62
|
-
|
63
|
-
def basic_auth!
|
64
|
-
return unless options[:basic_auth]
|
65
|
-
|
66
|
-
@req.basic_auth(*options[:basic_auth])
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
12
|
|
71
13
|
def get_uri(*options, &block)
|
72
14
|
call(Net::HTTP::Get, *options, &block)
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "uri"
|
3
|
+
require "openssl"
|
4
|
+
|
5
|
+
module Roar
|
6
|
+
module Representer
|
7
|
+
module Transport
|
8
|
+
class NetHTTP
|
9
|
+
class Request # TODO: implement me.
|
10
|
+
def initialize(options)
|
11
|
+
@uri = parse_uri(options[:uri]) # TODO: add :uri.
|
12
|
+
@as = options[:as]
|
13
|
+
@body = options[:body]
|
14
|
+
@options = options
|
15
|
+
|
16
|
+
@http = Net::HTTP.new(uri.host, uri.port)
|
17
|
+
unless options[:pem_file].nil?
|
18
|
+
pem = File.read(options[:pem_file])
|
19
|
+
@http.use_ssl = true
|
20
|
+
@http.cert = OpenSSL::X509::Certificate.new(pem)
|
21
|
+
@http.key = OpenSSL::PKey::RSA.new(pem)
|
22
|
+
@http.verify_mode = options[:ssl_verify_mode].nil? ? OpenSSL::SSL::VERIFY_PEER : options[:ssl_verify_mode]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def call(what)
|
27
|
+
@req = what.new(uri.request_uri)
|
28
|
+
|
29
|
+
# if options[:ssl]
|
30
|
+
# uri.port = Net::HTTP.https_default_port()
|
31
|
+
# end
|
32
|
+
https!
|
33
|
+
basic_auth!
|
34
|
+
|
35
|
+
req.content_type = as
|
36
|
+
req["accept"] = as # TODO: test me. # DISCUSS: if Accept is not set, rails treats this request as as "text/html".
|
37
|
+
req.body = body if body
|
38
|
+
|
39
|
+
yield req if block_given?
|
40
|
+
|
41
|
+
http.request(req).tap do |res|
|
42
|
+
raise UnauthorizedError if res.is_a?(Net::HTTPUnauthorized) # FIXME: make this better. # DISCUSS: abstract all that crap here?
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def get
|
47
|
+
call(Net::HTTP::Get)
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
attr_reader :uri, :as, :body, :options, :req, :http
|
52
|
+
|
53
|
+
def parse_uri(url)
|
54
|
+
uri = URI(url)
|
55
|
+
raise "Incorrect URL `#{url}`. Maybe you forgot http://?" if uri.instance_of?(URI::Generic)
|
56
|
+
uri
|
57
|
+
end
|
58
|
+
|
59
|
+
def https!
|
60
|
+
return unless uri.scheme == 'https'
|
61
|
+
|
62
|
+
@http.use_ssl = true
|
63
|
+
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
64
|
+
end
|
65
|
+
|
66
|
+
def basic_auth!
|
67
|
+
return unless options[:basic_auth]
|
68
|
+
|
69
|
+
@req.basic_auth(*options[:basic_auth])
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/lib/roar/version.rb
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIICcTCCAdqgAwIBAgIJAMvA30EY1rKtMA0GCSqGSIb3DQEBBQUAMDAxCzAJBgNV
|
3
|
+
BAYTAlVTMQ0wCwYDVQQKEwRLZWFzMRIwEAYDVQQDEwlsb2NhbGhvc3QwHhcNMDgw
|
4
|
+
OTA0MTU1MTU5WhcNMTgwOTAyMTU1MTU5WjAwMQswCQYDVQQGEwJVUzENMAsGA1UE
|
5
|
+
ChMES2VhczESMBAGA1UEAxMJbG9jYWxob3N0MIGfMA0GCSqGSIb3DQEBAQUAA4GN
|
6
|
+
ADCBiQKBgQDK17rB/KVaK8MVjiEkvA4ZncOOIC3nStZ/erXM+qwkghPM4Tfr2FTU
|
7
|
+
iTgwwdLdu/ht74oWnppttfaTQ+sVz2rFXnPgfqKTGoJTwWFiuNuZhSRDVssGVnL/
|
8
|
+
RatZW6wns8UNf+W4hUe6/vGQP6obNTe2T4R+t2hXP51OkOy4BMcq0QIDAQABo4GS
|
9
|
+
MIGPMB0GA1UdDgQWBBQDIsX7HoSqbxKrCawi64MkXRmtmzBgBgNVHSMEWTBXgBQD
|
10
|
+
IsX7HoSqbxKrCawi64MkXRmtm6E0pDIwMDELMAkGA1UEBhMCVVMxDTALBgNVBAoT
|
11
|
+
BEtlYXMxEjAQBgNVBAMTCWxvY2FsaG9zdIIJAMvA30EY1rKtMAwGA1UdEwQFMAMB
|
12
|
+
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qo8BFkWtDW1/C
|
29
|
+
GXrtQRbMDPzD40UYB2UCQQCmJpJp+u2lHj7zuZikHIHQBNyXyoGnzgNs6XUj1Bs6
|
30
|
+
Y4vjue8w6RkRLZ1YGP+xqsngVqb9IRygyLDpEgwEnOT4
|
31
|
+
-----END RSA PRIVATE KEY-----
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'roar/representer/transport/net_http/request'
|
3
|
+
|
4
|
+
class NetHTTPTransportRequestTest < MiniTest::Spec
|
5
|
+
|
6
|
+
describe Roar::Representer::Transport::NetHTTP::Request do
|
7
|
+
|
8
|
+
describe "instance methods" do
|
9
|
+
describe "#initialize" do
|
10
|
+
|
11
|
+
describe "client certificate configuration" do
|
12
|
+
|
13
|
+
let(:uri) { URI.parse("http://www.bbc.co.uk") }
|
14
|
+
let(:options) { { uri: uri, pem_file: pem_file, ssl_verify_mode: ssl_verify_mode } }
|
15
|
+
|
16
|
+
let(:request) { Roar::Representer::Transport::NetHTTP::Request.new(options) }
|
17
|
+
let(:net_http_instance) { request.instance_variable_get(:@http) }
|
18
|
+
let(:ssl_verify_mode) { nil }
|
19
|
+
|
20
|
+
describe "when a pem file has been provided with the request options" do
|
21
|
+
|
22
|
+
let(:pem_file) { File.expand_path("test/fixtures/sample.pem", Roar.root) }
|
23
|
+
|
24
|
+
let(:pem) { File.read(pem_file) }
|
25
|
+
let(:cert) { OpenSSL::X509::Certificate.new(pem) }
|
26
|
+
let(:key) { OpenSSL::PKey::RSA.new(pem) }
|
27
|
+
|
28
|
+
it "sets the client to use an ssl connection" do
|
29
|
+
assert(net_http_instance.use_ssl?, "Net::HTTP connection uses ssl")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "sets the client cert" do
|
33
|
+
assert_equal(net_http_instance.cert.to_s, cert.to_s)
|
34
|
+
end
|
35
|
+
it "sets the client key" do
|
36
|
+
assert_equal(net_http_instance.key.to_s, key.to_s)
|
37
|
+
end
|
38
|
+
it "defaults the verify mode to OpenSSL::SSL::VERIFY_PEER when no option provided" do
|
39
|
+
assert_equal(net_http_instance.verify_mode, OpenSSL::SSL::VERIFY_PEER)
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "verify mode is specified" do
|
43
|
+
|
44
|
+
let(:ssl_verify_mode) { OpenSSL::SSL::VERIFY_NONE }
|
45
|
+
|
46
|
+
it "sets the client verify mode to that option provided" do
|
47
|
+
assert_equal(net_http_instance.verify_mode, ssl_verify_mode)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "when a pem file has not been provided in the request options" do
|
53
|
+
|
54
|
+
let(:pem_file) { nil }
|
55
|
+
|
56
|
+
it "does not set the client to use an ssl connection" do
|
57
|
+
refute(net_http_instance.use_ssl?, "Net::HTTP connection do not use SSL")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.
|
4
|
+
version: 0.12.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: representable
|
@@ -160,6 +160,7 @@ files:
|
|
160
160
|
- lib/roar/representer/json/hal.rb
|
161
161
|
- lib/roar/representer/transport/faraday.rb
|
162
162
|
- lib/roar/representer/transport/net_http.rb
|
163
|
+
- lib/roar/representer/transport/net_http/request.rb
|
163
164
|
- lib/roar/representer/xml.rb
|
164
165
|
- lib/roar/version.rb
|
165
166
|
- roar.gemspec
|
@@ -168,6 +169,7 @@ files:
|
|
168
169
|
- test/collection_json_test.rb
|
169
170
|
- test/decorator_test.rb
|
170
171
|
- test/faraday_http_transport_test.rb
|
172
|
+
- test/fixtures/sample.pem
|
171
173
|
- test/hal_json_test.rb
|
172
174
|
- test/hal_links_test.rb
|
173
175
|
- test/http_verbs_test.rb
|
@@ -179,6 +181,7 @@ files:
|
|
179
181
|
- test/integration/server.rb
|
180
182
|
- test/integration/ssl_server.rb
|
181
183
|
- test/json_representer_test.rb
|
184
|
+
- test/lib/roar/representer/transport/net_http/request_test.rb
|
182
185
|
- test/net_http_transport_test.rb
|
183
186
|
- test/representer_test.rb
|
184
187
|
- test/test_helper.rb
|
@@ -203,29 +206,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
203
206
|
version: '0'
|
204
207
|
requirements: []
|
205
208
|
rubyforge_project:
|
206
|
-
rubygems_version: 2.2.
|
209
|
+
rubygems_version: 2.2.2
|
207
210
|
signing_key:
|
208
211
|
specification_version: 4
|
209
212
|
summary: Resource-oriented architectures in Ruby.
|
210
|
-
test_files:
|
211
|
-
- test/client_test.rb
|
212
|
-
- test/coercion_feature_test.rb
|
213
|
-
- test/collection_json_test.rb
|
214
|
-
- test/decorator_test.rb
|
215
|
-
- test/faraday_http_transport_test.rb
|
216
|
-
- test/hal_json_test.rb
|
217
|
-
- test/hal_links_test.rb
|
218
|
-
- test/http_verbs_test.rb
|
219
|
-
- test/hypermedia_feature_test.rb
|
220
|
-
- test/hypermedia_test.rb
|
221
|
-
- test/integration/Gemfile
|
222
|
-
- test/integration/band_representer.rb
|
223
|
-
- test/integration/runner.rb
|
224
|
-
- test/integration/server.rb
|
225
|
-
- test/integration/ssl_server.rb
|
226
|
-
- test/json_representer_test.rb
|
227
|
-
- test/net_http_transport_test.rb
|
228
|
-
- test/representer_test.rb
|
229
|
-
- test/test_helper.rb
|
230
|
-
- test/xml_representer_test.rb
|
231
|
-
has_rdoc:
|
213
|
+
test_files: []
|