Top Level Namespace

Constant Summary collapse

CONTENT_TYPE =
'application/json'

Instance Method Summary collapse

Instance Method Details

#get_intercept(server, port, configurations) ⇒ Hash

Retrieves an intercept from a given path

Options Hash (configurations):

  • :method (String)

    Method for the mocked response.

  • :path (String)

    Path for the mocked response.



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/mobe-client.rb', line 65

def get_intercept(server, port, configurations)
  check_for_get_arguments(configurations)
  configurations = configurations.to_json

  uri = URI('http://' + server + ':' + port.to_s + '/mobe/intercept/get')
  req = Net::HTTP::Post.new uri.path

  req.body = configurations
  req.content_type = CONTENT_TYPE

  res = Net::HTTP.start(uri.host, uri.port) do |http|
    http.request req
  end

  return res.body
end

#register_intercept(server, port, configurations) ⇒ Object

Registers an intercept for a given path

Options Hash (configurations):

  • :method (String)

    Method for the mocked response.

  • :path (String)

    Path for the mocked response.

  • :response (String)

    The response for the mocked response.

  • :statusCode (String)

    The status code for the mocked response.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/mobe-client.rb', line 43

def register_intercept(server, port, configurations)
  check_for_register_arguments(configurations)
  configurations = configurations.to_json

  uri = URI('http://' + server + ':' + port.to_s + '/mobe/intercept/register')
  req = Net::HTTP::Post.new uri.path

  req.body = configurations
  req.content_type = CONTENT_TYPE

  Net::HTTP.start(uri.host, uri.port) do |http|
    http.request req
  end
end

#register_mock_response(server, port, configurations) ⇒ Object

Registers a mock response for a given path

Options Hash (configurations):

  • :method (String)

    Method for the mocked response.

  • :path (String)

    Path for the mocked response.

  • :response (String)

    The response for the mocked response.

  • :statusCode (String)

    The status code for the mocked response.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/mobe-client.rb', line 16

def register_mock_response(server, port, configurations)
  check_for_register_arguments(configurations)
  configurations = configurations.to_json

  uri = URI('http://' + server + ':' + port.to_s + '/mobe/response/register')
  req = Net::HTTP::Post.new uri.path
  req.body = configurations
  req.content_type = CONTENT_TYPE

  res = Net::HTTP.start(uri.host, uri.port) do |http|
    http.request req
  end

  if res.code != '200'
    raise Exception.new("POST failed. Error code: #{res.code}")
  end
end

#unregister_all_intercepts(server, port) ⇒ Object

Unregisters all intercepts



127
128
129
130
131
132
133
134
135
136
# File 'lib/mobe-client.rb', line 127

def unregister_all_intercepts(server, port)
  uri = URI('http://' + server + ':' + port.to_s + '/mobe/intercept/unregister_all')
  req = Net::HTTP::Post.new uri.path

  req.content_type = CONTENT_TYPE

  Net::HTTP.start(uri.host, uri.port) do |http|
    http.request req
  end
end

#unregister_all_mock_responses(server, port) ⇒ Object

Unregisters all mock responses



141
142
143
144
145
146
147
148
149
150
# File 'lib/mobe-client.rb', line 141

def unregister_all_mock_responses(server, port)
  uri = URI('http://' + server + ':' + port.to_s + '/mobe/response/unregister_all')
  req = Net::HTTP::Post.new uri.path

  req.content_type = CONTENT_TYPE

  Net::HTTP.start(uri.host, uri.port) do |http|
    http.request req
  end
end

#unregister_intercept(server, port, configurations) ⇒ Object

Unregisters an intercept for a given path

Options Hash (configurations):

  • :method (String)

    Method for the mocked response.

  • :path (String)

    Path for the mocked response.



109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/mobe-client.rb', line 109

def unregister_intercept(server, port, configurations)
  check_for_get_arguments(configurations)
  configurations = configurations.to_json

  uri = URI('http://' + server + ':' + port.to_s + '/mobe/intercept/unregister')
  req = Net::HTTP::Post.new uri.path

  req.body = configurations
  req.content_type = CONTENT_TYPE

  Net::HTTP.start(uri.host, uri.port) do |http|
    http.request req
  end
end

#unregister_mock_response(server, port, configurations) ⇒ Object

Unregisters a mock response for a given path

Options Hash (configurations):

  • :method (String)

    Method for the mocked response.

  • :path (String)

    Path for the mocked response.



88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/mobe-client.rb', line 88

def unregister_mock_response(server, port, configurations)
  check_for_get_arguments(configurations)
  configurations = configurations.to_json

  uri = URI('http://' + server + ':' + port.to_s + '/mobe/response/unregister')
  req = Net::HTTP::Post.new uri.path

  req.body = configurations
  req.content_type = CONTENT_TYPE

  Net::HTTP.start(uri.host, uri.port) do |http|
    http.request req
  end
end