mobe-client 0.0.2 → 0.0.4
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 +8 -8
- data/lib/mobe-client.rb +33 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NzhiY2ExNTFhZDdiZDQ3YTA2Y2RkMmM2MDU0NjcxNTFhZDE4MWI1OQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YzM2NmQ0OTMxMmE5ZmEwZWVkOTBkY2RjNjdkODIyMDA4MGJiNTI4Yg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZWZhMzU4OGQzOTBiZDgyYmVkZmNkMDY5ZWViZWY3OGY3MDMwOGYxMGM1ZTIy
|
10
|
+
OTUyZTQ0ZjlmNjY4YTc1NmUwMDUxODYwYjhhNWZjNDllZGY4ZGQzMmZhMTAy
|
11
|
+
NDk3MWEwMjVlZDFlOTY2YmM5N2IwNTc3NDUxNWUyNTIzOWQ4NzY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MzA1YWQ5NjA3ZjdkYjRmNDlkYjQyZTAwMTMyMWFjZjU3M2I5MDAwZWQ5MThj
|
14
|
+
YjMzNDA2ODdlY2M3MzZhN2Y2ZmZiMmQzOGFhNTBlNWVhOGY4YjE4ZjZkMmJj
|
15
|
+
MDk4MjI2MGM1MGZhMDRlZmI1YTZjN2Q2NTY1NjFiYjJjYmIyNTI=
|
data/lib/mobe-client.rb
CHANGED
@@ -8,12 +8,15 @@ CONTENT_TYPE = 'application/json'
|
|
8
8
|
#Registers a mock response for a given path
|
9
9
|
#@param server [String]
|
10
10
|
#@param port [Fixnum]
|
11
|
-
#@param configurations [
|
11
|
+
#@param configurations [Hash] JSON representation of a string
|
12
12
|
#@option configurations [String] :method Method for the mocked response.
|
13
13
|
#@option configurations [String] :path Path for the mocked response.
|
14
14
|
#@option configurations [String] :response The response for the mocked response.
|
15
15
|
#@option configurations [String] :statusCode The status code for the mocked response.
|
16
16
|
def register_mock_response(server, port, configurations)
|
17
|
+
check_for_register_arguments(configurations)
|
18
|
+
configurations = configurations.to_json
|
19
|
+
|
17
20
|
uri = URI('http://' + server + ':' + port.to_s + '/mobe/response/register')
|
18
21
|
req = Net::HTTP::Post.new uri.path
|
19
22
|
req.body = configurations
|
@@ -32,12 +35,15 @@ end
|
|
32
35
|
#Registers an intercept for a given path
|
33
36
|
#@param server [String]
|
34
37
|
#@param port [Fixnum]
|
35
|
-
#@param configurations [
|
38
|
+
#@param configurations [Hash] JSON representation of a string
|
36
39
|
#@option configurations [String] :method Method for the mocked response.
|
37
40
|
#@option configurations [String] :path Path for the mocked response.
|
38
41
|
#@option configurations [String] :response The response for the mocked response.
|
39
42
|
#@option configurations [String] :statusCode The status code for the mocked response.
|
40
43
|
def register_intercept(server, port, configurations)
|
44
|
+
check_for_register_arguments(configurations)
|
45
|
+
configurations = configurations.to_json
|
46
|
+
|
41
47
|
uri = URI('http://' + server + ':' + port.to_s + '/mobe/intercept/register')
|
42
48
|
req = Net::HTTP::Post.new uri.path
|
43
49
|
|
@@ -52,11 +58,14 @@ end
|
|
52
58
|
#Retrieves an intercept from a given path
|
53
59
|
#@param server [String]
|
54
60
|
#@param port [Fixnum]
|
55
|
-
#@param configurations [
|
61
|
+
#@param configurations [Hash] JSON representation of a string
|
56
62
|
#@option configurations [String] :method Method for the mocked response.
|
57
63
|
#@option configurations [String] :path Path for the mocked response.
|
58
64
|
#@return [Hash] The intercepted request
|
59
65
|
def get_intercept(server, port, configurations)
|
66
|
+
check_for_get_arguments(configurations)
|
67
|
+
configurations = configurations.to_json
|
68
|
+
|
60
69
|
uri = URI('http://' + server + ':' + port.to_s + '/mobe/intercept/get')
|
61
70
|
req = Net::HTTP::Post.new uri.path
|
62
71
|
|
@@ -73,10 +82,13 @@ end
|
|
73
82
|
#Unregisters a mock response for a given path
|
74
83
|
#@param server [String]
|
75
84
|
#@param port [Fixnum]
|
76
|
-
#@param configurations [
|
85
|
+
#@param configurations [Hash] JSON representation of a string
|
77
86
|
#@option configurations [String] :method Method for the mocked response.
|
78
87
|
#@option configurations [String] :path Path for the mocked response.
|
79
88
|
def unregister_mock_response(server, port, configurations)
|
89
|
+
check_for_get_arguments(configurations)
|
90
|
+
configurations = configurations.to_json
|
91
|
+
|
80
92
|
uri = URI('http://' + server + ':' + port.to_s + '/mobe/response/unregister')
|
81
93
|
req = Net::HTTP::Post.new uri.path
|
82
94
|
|
@@ -91,10 +103,13 @@ end
|
|
91
103
|
#Unregisters an intercept for a given path
|
92
104
|
#@param server [String]
|
93
105
|
#@param port [Fixnum]
|
94
|
-
#@param configurations [
|
106
|
+
#@param configurations [Hash] JSON representation of a string
|
95
107
|
#@option configurations [String] :method Method for the mocked response.
|
96
108
|
#@option configurations [String] :path Path for the mocked response.
|
97
109
|
def unregister_intercept(server, port, configurations)
|
110
|
+
check_for_get_arguments(configurations)
|
111
|
+
configurations = configurations.to_json
|
112
|
+
|
98
113
|
uri = URI('http://' + server + ':' + port.to_s + '/mobe/intercept/unregister')
|
99
114
|
req = Net::HTTP::Post.new uri.path
|
100
115
|
|
@@ -133,3 +148,16 @@ def unregister_all_mock_responses(server, port)
|
|
133
148
|
http.request req
|
134
149
|
end
|
135
150
|
end
|
151
|
+
|
152
|
+
private
|
153
|
+
# Ensures configurations has the keys 'method', 'path', 'response', 'statusCode'
|
154
|
+
# @param configurations [Hash]
|
155
|
+
def check_for_register_arguments(configurations)
|
156
|
+
raise ArgumentError("Configurations doesn't have the correct keys: 'method', 'path','response', and 'statusCode'." ) unless (configurations.has_key?('method') && configurations.has_key?('path') && configurations.has_key?('response') && configurations.has_key?('statusCode'))
|
157
|
+
end
|
158
|
+
|
159
|
+
# Ensures configurations has the keys 'method', 'path'
|
160
|
+
# @param configurations [Hash]
|
161
|
+
def check_for_get_arguments(configurations)
|
162
|
+
raise ArgumentError("Configurations doesn't have the correct keys: 'method' and 'path'." ) unless (configurations.has_key?('method') && configurations.has_key?('path'))
|
163
|
+
end
|