imperium 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/imperium/error.rb +13 -0
- data/lib/imperium/http_client.rb +25 -7
- data/lib/imperium/testing.rb +37 -0
- data/lib/imperium/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f59bdee1b6ac9ba26ac29376201e2287dc2a0d40
|
4
|
+
data.tar.gz: 607de30419fe22615ff7449c70e27f8757520278
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f14950628947bcf8e279b07d6ad39d3cf812347d5899962fbfef983c03a461434ceca309eb17973c0d3e9917d31252cd44ae762774d0f99cf828c982b542c45e
|
7
|
+
data.tar.gz: 99ce04ef3f3cf342bcf51b0566acfee85b6f7daa97b99e902bffe04670377de1b536c22bac5217cba571cc6329920574fabd8396673acc7567b77aa138d6e63c
|
data/lib/imperium/error.rb
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
|
2
2
|
module Imperium
|
3
3
|
class Error < StandardError; end
|
4
|
+
|
4
5
|
class InvalidConsistencySpecification < Error; end
|
6
|
+
|
7
|
+
# Generic Network timeout error
|
8
|
+
class TimeoutError < Error; end
|
9
|
+
|
10
|
+
# Raised when opening the TCP socket times out
|
11
|
+
class ConnectTimeout < TimeoutError; end
|
12
|
+
|
13
|
+
# Raised when sending the request body took too long
|
14
|
+
class SendTimeout < TimeoutError; end
|
15
|
+
|
16
|
+
# Raised when the remote server took too long to respond.
|
17
|
+
class ReceiveTimeout < TimeoutError; end
|
5
18
|
end
|
data/lib/imperium/http_client.rb
CHANGED
@@ -13,19 +13,25 @@ module Imperium
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def delete(path)
|
16
|
-
|
17
|
-
|
16
|
+
wrapping_timeouts do
|
17
|
+
url = config.url.join(path)
|
18
|
+
@driver.delete(url)
|
19
|
+
end
|
18
20
|
end
|
19
21
|
|
20
22
|
def get(path, query: {})
|
21
|
-
|
22
|
-
|
23
|
-
|
23
|
+
wrapping_timeouts do
|
24
|
+
url = config.url.join(path)
|
25
|
+
url.query_values = query
|
26
|
+
@driver.get(url, header: build_request_headers)
|
27
|
+
end
|
24
28
|
end
|
25
29
|
|
26
30
|
def put(path, value)
|
27
|
-
|
28
|
-
|
31
|
+
wrapping_timeouts do
|
32
|
+
url = config.url.join(path)
|
33
|
+
@driver.put(url, body: value)
|
34
|
+
end
|
29
35
|
end
|
30
36
|
|
31
37
|
private
|
@@ -37,5 +43,17 @@ module Imperium
|
|
37
43
|
{}
|
38
44
|
end
|
39
45
|
end
|
46
|
+
|
47
|
+
# We're doing this wrap and re-raise dance to give a more consistent set of
|
48
|
+
# exceptions that can come from us.
|
49
|
+
def wrapping_timeouts
|
50
|
+
yield
|
51
|
+
rescue HTTPClient::ConnectTimeout => ex
|
52
|
+
raise Imperium::ConnectTimeout, ex.message
|
53
|
+
rescue HTTPClient::SendTimeout => ex
|
54
|
+
raise Imperium::SendTimeout, ex.message
|
55
|
+
rescue HTTPClient::ReceiveTimeout => ex
|
56
|
+
raise Imperium::ReceiveTimeout, ex.message
|
57
|
+
end
|
40
58
|
end
|
41
59
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'imperium'
|
2
|
+
|
3
|
+
module Imperium
|
4
|
+
# A collection of functions to build responses for use in tests needing mock
|
5
|
+
# responses.
|
6
|
+
module Testing
|
7
|
+
class Client < Imperium::Client
|
8
|
+
def initialize
|
9
|
+
end
|
10
|
+
public :hashify_options
|
11
|
+
end
|
12
|
+
private_constant :Client
|
13
|
+
|
14
|
+
MockResponse = Struct.new(:content, :status, :headers)
|
15
|
+
|
16
|
+
@client = Client.new
|
17
|
+
def self.kv_get_response(body: '[]', status: 200, headers: {}, prefix: '', options: [])
|
18
|
+
expanded_options = @client.hashify_options(options)
|
19
|
+
string_body = if String === body
|
20
|
+
body
|
21
|
+
else
|
22
|
+
body.map { |obj|
|
23
|
+
obj['Value'] = Base64.encode64(obj['Value']) if obj['Value']
|
24
|
+
obj[:Value] = Base64.encode64(obj[:Value]) if obj[:Value]
|
25
|
+
obj
|
26
|
+
}.to_json
|
27
|
+
end
|
28
|
+
|
29
|
+
response = MockResponse.new(string_body, status, headers)
|
30
|
+
KVGETResponse.new(response, prefix: prefix, options: expanded_options)
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.kv_not_found_response(headers: {}, options: [])
|
34
|
+
kv_get_response(body: '', status: 404, headers: headers, options: options)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/imperium/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imperium
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Pickett
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03
|
11
|
+
date: 2017-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -165,6 +165,7 @@ files:
|
|
165
165
|
- lib/imperium/kv_get_response.rb
|
166
166
|
- lib/imperium/kv_pair.rb
|
167
167
|
- lib/imperium/response.rb
|
168
|
+
- lib/imperium/testing.rb
|
168
169
|
- lib/imperium/version.rb
|
169
170
|
homepage: https://github.com/instructure/imperium
|
170
171
|
licenses:
|