Class: Spec::Client::HttpClient

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_uri) ⇒ HttpClient

Returns a new instance of HttpClient.



9
10
11
12
# File 'lib/spec/client/http_client.rb', line 9

def initialize(base_uri)
  @base_uri = base_uri
  @session = Http::Session.new(self)
end

Instance Attribute Details

#base_uriObject (readonly)

Returns the value of attribute base_uri.



7
8
9
# File 'lib/spec/client/http_client.rb', line 7

def base_uri
  @base_uri
end

#sessionObject (readonly)

Returns the value of attribute session.



7
8
9
# File 'lib/spec/client/http_client.rb', line 7

def session
  @session
end

Instance Method Details

#full_url(path) ⇒ Object



26
27
28
# File 'lib/spec/client/http_client.rb', line 26

def full_url(path)
  URI.join(base_uri, path).to_s
end

#get(path, params = {}) ⇒ Object



18
19
20
# File 'lib/spec/client/http_client.rb', line 18

def get(path, params = {})
  session.get(full_url(path), params)
end

#new_sessionObject



14
15
16
# File 'lib/spec/client/http_client.rb', line 14

def new_session()
  @session = Http::Session.new(self)
end

#post(path, params = {}) ⇒ Object



22
23
24
# File 'lib/spec/client/http_client.rb', line 22

def post(path, params = {})
  session.post(full_url(path), params)
end