Class: RackStubs::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/rack_stubs/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(service, rest_client = RestClient) ⇒ Client

Returns a new instance of Client.



6
7
8
9
# File 'lib/rack_stubs/client.rb', line 6

def initialize(service, rest_client = RestClient)
  @service = service 
  @rest_client = rest_client
end

Instance Method Details

#clear_all!Object



23
24
25
# File 'lib/rack_stubs/client.rb', line 23

def clear_all!
  @rest_client.post(service_url("rack_stubs/clear"), "", {"Content-Type" => "application/json+rack-stub"})
end

#get(path) ⇒ Object



15
16
17
# File 'lib/rack_stubs/client.rb', line 15

def get(path)
  PathSpecification.new(service_url(path), 'GET', @rest_client)
end

#post(path) ⇒ Object



19
20
21
# File 'lib/rack_stubs/client.rb', line 19

def post(path)
  PathSpecification.new(service_url(path), 'POST', @rest_client)
end

#service_url(path) ⇒ Object



11
12
13
# File 'lib/rack_stubs/client.rb', line 11

def service_url(path)
  @service.gsub(/\/+$/, '') + '/' + path.gsub(/^\/+/, '')
end