mobe-client 0.0.1

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.
Files changed (3) hide show
  1. checksums.yaml +15 -0
  2. data/lib/mobe-client.rb +135 -0
  3. metadata +45 -0
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NWZkNTBkMzNkYjdhYTc4ZmI2M2RlNWVmNThlMjlmY2JmY2U2YTQyNA==
5
+ data.tar.gz: !binary |-
6
+ MzNlODc1YjRiYTU4ZTJlZGZhOTUzMDhkMTIxYzQ3ZTQ1OTgwM2I0OQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ OTE3Y2QxOTViNTg3MzE4YWM3NzNlMmU5YTk3YmExNDRiMTE2NDE4NDk4YzFm
10
+ N2UyNjNkZjc3NTcxM2MwMGUyOGFjMjM2YTk5OThiZDVkYjAxOWE2NTIwZGUw
11
+ NWVhYmI5ZWI3YmIyMTRhMDAxMWYxMWIxYzY0Yzc3NjY5YjZhOTg=
12
+ data.tar.gz: !binary |-
13
+ MDQzMzc1MTdiZGIzNjY3MjBhNTkxMzRhYWE5MDAwOTMyYmQ4Y2QwMDU0NDYy
14
+ NTZhN2EyMTI1MWZmMGRmN2YxNDMzOTdhYmE0ZTU4YmI1NzJkNzEwMDE4Mjk2
15
+ ODU1YWEyYWJjYzc0ZGIyY2ZkMDViNjYzYWE4YTI4MTY4NWQwNjA=
@@ -0,0 +1,135 @@
1
+ require 'net/http'
2
+ require 'json'
3
+ require 'uri'
4
+
5
+
6
+ CONTENT_TYPE = 'application/json'
7
+
8
+ #Registers a mock response for a given path
9
+ #@param server [String]
10
+ #@param port [Fixnum]
11
+ #@param configurations [String] JSON representation of a string
12
+ #@option configurations [String] :method Method for the mocked response.
13
+ #@option configurations [String] :path Path for the mocked response.
14
+ #@option configurations [String] :response The response for the mocked response.
15
+ #@option configurations [String] :statusCode The status code for the mocked response.
16
+ def register_mock_response(server, port, configurations)
17
+ uri = URI('http://' + server + ':' + port.to_s + '/mobe/response/register')
18
+ req = Net::HTTP::Post.new uri.path
19
+ req.body = configurations
20
+ req.content_type = CONTENT_TYPE
21
+
22
+ res = Net::HTTP.start(uri.host, uri.port) do |http|
23
+ http.request req
24
+ end
25
+
26
+ if res.code != '200'
27
+ raise Exception.new("POST failed. Error code: #{res.code}")
28
+ end
29
+ end
30
+
31
+
32
+ #Registers an intercept for a given path
33
+ #@param server [String]
34
+ #@param port [Fixnum]
35
+ #@param configurations [String] JSON representation of a string
36
+ #@option configurations [String] :method Method for the mocked response.
37
+ #@option configurations [String] :path Path for the mocked response.
38
+ #@option configurations [String] :response The response for the mocked response.
39
+ #@option configurations [String] :statusCode The status code for the mocked response.
40
+ def register_intercept(server, port, configurations)
41
+ uri = URI('http://' + server + ':' + port.to_s + '/mobe/intercept/register')
42
+ req = Net::HTTP::Post.new uri.path
43
+
44
+ req.body = configurations
45
+ req.content_type = CONTENT_TYPE
46
+
47
+ Net::HTTP.start(uri.host, uri.port) do |http|
48
+ http.request req
49
+ end
50
+ end
51
+
52
+ #Retrieves an intercept from a given path
53
+ #@param server [String]
54
+ #@param port [Fixnum]
55
+ #@param configurations [String] JSON representation of a string
56
+ #@option configurations [String] :method Method for the mocked response.
57
+ #@option configurations [String] :path Path for the mocked response.
58
+ #@return [Hash] The intercepted request
59
+ def get_intercept(server, port, configurations)
60
+ uri = URI('http://' + server + ':' + port.to_s + '/mobe/intercept/get')
61
+ req = Net::HTTP::Post.new uri.path
62
+
63
+ req.body = configurations
64
+ req.content_type = CONTENT_TYPE
65
+
66
+ res = Net::HTTP.start(uri.host, uri.port) do |http|
67
+ http.request req
68
+ end
69
+
70
+ return res.body
71
+ end
72
+
73
+ #Unregisters a mock response for a given path
74
+ #@param server [String]
75
+ #@param port [Fixnum]
76
+ #@param configurations [String] JSON representation of a string
77
+ #@option configurations [String] :method Method for the mocked response.
78
+ #@option configurations [String] :path Path for the mocked response.
79
+ def unregister_mock_response(server, port, configurations)
80
+ uri = URI('http://' + server + ':' + port.to_s + '/mobe/response/unregister')
81
+ req = Net::HTTP::Post.new uri.path
82
+
83
+ req.body = configurations
84
+ req.content_type = CONTENT_TYPE
85
+
86
+ Net::HTTP.start(uri.host, uri.port) do |http|
87
+ http.request req
88
+ end
89
+ end
90
+
91
+ #Unregisters an intercept for a given path
92
+ #@param server [String]
93
+ #@param port [Fixnum]
94
+ #@param configurations [String] JSON representation of a string
95
+ #@option configurations [String] :method Method for the mocked response.
96
+ #@option configurations [String] :path Path for the mocked response.
97
+ def unregister_intercept(server, port, configurations)
98
+ uri = URI('http://' + server + ':' + port.to_s + '/mobe/intercept/unregister')
99
+ req = Net::HTTP::Post.new uri.path
100
+
101
+ req.body = configurations
102
+ req.content_type = CONTENT_TYPE
103
+
104
+ Net::HTTP.start(uri.host, uri.port) do |http|
105
+ http.request req
106
+ end
107
+ end
108
+
109
+ #Unregisters all intercepts
110
+ #@param server [String]
111
+ #@param port [Fixnum]
112
+ def unregister_all_intercepts(server, port)
113
+ uri = URI('http://' + server + ':' + port.to_s + '/mobe/intercept/unregister_all')
114
+ req = Net::HTTP::Post.new uri.path
115
+
116
+ req.content_type = CONTENT_TYPE
117
+
118
+ Net::HTTP.start(uri.host, uri.port) do |http|
119
+ http.request req
120
+ end
121
+ end
122
+
123
+ #Unregisters all mock responses
124
+ #@param server [String]
125
+ #@param port [Fixnum]
126
+ def unregister_all_mock_responses(server, port)
127
+ uri = URI('http://' + server + ':' + port.to_s + '/mobe/response/unregister_all')
128
+ req = Net::HTTP::Post.new uri.path
129
+
130
+ req.content_type = CONTENT_TYPE
131
+
132
+ Net::HTTP.start(uri.host, uri.port) do |http|
133
+ http.request req
134
+ end
135
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mobe-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Aaron Humerickhouse
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-07 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A simple hello world gem
14
+ email: a.humerickhouse@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/mobe-client.rb
20
+ homepage: http://github.com/TIMBERings/mobe-client
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.4.8
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Mock Out Back End
44
+ test_files: []
45
+ has_rdoc: