class Object

Constants

CONTENT_TYPE

Public Instance Methods

check_for_get_arguments(configurations) click to toggle source

Ensures configurations has the keys 'method', 'path' @param configurations [Hash]

# File lib/mobe-client.rb, line 161
def check_for_get_arguments(configurations)
  raise ArgumentError("Configurations doesn't have the correct keys: 'method' and 'path'." ) unless (configurations.has_key?('method') && configurations.has_key?('path'))
end
check_for_register_arguments(configurations) click to toggle source

Ensures configurations has the keys 'method', 'path', 'response', 'statusCode' @param configurations [Hash]

# File lib/mobe-client.rb, line 155
def check_for_register_arguments(configurations)
  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'))
end
get_intercept(server, port, configurations) click to toggle source

Retrieves an intercept from a given path @param server [String] @param port [Fixnum] @param configurations [Hash] JSON representation of a string @option configurations [String] :method Method for the mocked response. @option configurations [String] :path Path for the mocked response. @return [Hash] The intercepted request

# 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) click to toggle source

Registers an intercept for a given path @param server [String] @param port [Fixnum] @param configurations [Hash] JSON representation of a string @option configurations [String] :method Method for the mocked response. @option configurations [String] :path Path for the mocked response. @option configurations [String] :response The response for the mocked response. @option configurations [String] :statusCode The status code for the mocked response.

# 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) click to toggle source

Registers a mock response for a given path @param server [String] @param port [Fixnum] @param configurations [Hash] JSON representation of a string @option configurations [String] :method Method for the mocked response. @option configurations [String] :path Path for the mocked response. @option configurations [String] :response The response for the mocked response. @option configurations [String] :statusCode The status code for the mocked response.

# 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) click to toggle source

Unregisters all intercepts @param server [String] @param port [Fixnum]

# 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) click to toggle source

Unregisters all mock responses @param server [String] @param port [Fixnum]

# 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) click to toggle source

Unregisters an intercept for a given path @param server [String] @param port [Fixnum] @param configurations [Hash] JSON representation of a string @option configurations [String] :method Method for the mocked response. @option configurations [String] :path Path for the mocked response.

# 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) click to toggle source

Unregisters a mock response for a given path @param server [String] @param port [Fixnum] @param configurations [Hash] JSON representation of a string @option configurations [String] :method Method for the mocked response. @option configurations [String] :path Path for the mocked response.

# 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