Class: Spec::Performance::Client::HttpClient
- Inherits:
-
Object
- Object
- Spec::Performance::Client::HttpClient
- Defined in:
- lib/spec/performance/client/http_client.rb
Instance Attribute Summary collapse
-
#base_uri ⇒ Object
readonly
Returns the value of attribute base_uri.
-
#cookies ⇒ Object
Returns the value of attribute cookies.
-
#recording ⇒ Object
writeonly
Sets the attribute recording.
Instance Method Summary collapse
- #add_header(key, value) ⇒ Object
- #get(uri, params = {}) ⇒ Object
-
#initialize(base_uri) ⇒ HttpClient
constructor
A new instance of HttpClient.
- #post(uri, params = {}) ⇒ Object
- #recording? ⇒ Boolean
- #remove_header(key) ⇒ Object
Constructor Details
#initialize(base_uri) ⇒ HttpClient
Returns a new instance of HttpClient.
12 13 14 15 16 17 |
# File 'lib/spec/performance/client/http_client.rb', line 12 def initialize(base_uri) @base_uri = base_uri @headers = {} @cookies = {} @recording = true end |
Instance Attribute Details
#base_uri ⇒ Object (readonly)
Returns the value of attribute base_uri.
10 11 12 |
# File 'lib/spec/performance/client/http_client.rb', line 10 def base_uri @base_uri end |
#cookies ⇒ Object
Returns the value of attribute cookies.
10 11 12 |
# File 'lib/spec/performance/client/http_client.rb', line 10 def @cookies end |
#recording=(value) ⇒ Object (writeonly)
Sets the attribute recording
9 10 11 |
# File 'lib/spec/performance/client/http_client.rb', line 9 def recording=(value) @recording = value end |
Instance Method Details
#add_header(key, value) ⇒ Object
43 44 45 |
# File 'lib/spec/performance/client/http_client.rb', line 43 def add_header(key, value) @headers[key] = value end |
#get(uri, params = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/spec/performance/client/http_client.rb', line 30 def get(uri, params = {}) if params && params.size > 0 query = params2query(params) uri = URI.parse("#{uri}?#{query}") end http = Net::HTTP.start(uri.host, uri.port) response = http.get(uri.request_uri, headers) http.finish create_http_client_response(response) end |
#post(uri, params = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/spec/performance/client/http_client.rb', line 19 def post(uri, params = {}) request = Net::HTTP::Post.new(uri.path, headers) request.form_data = params request.basic_auth uri.user, uri.password if uri.user response = Net::HTTP.new(uri.host, uri.port).start do |http| http.request(request) end capture(response) if recording? create_http_client_response(response) end |
#recording? ⇒ Boolean
51 52 53 |
# File 'lib/spec/performance/client/http_client.rb', line 51 def recording? @recording end |
#remove_header(key) ⇒ Object
47 48 49 |
# File 'lib/spec/performance/client/http_client.rb', line 47 def remove_header(key) @headers.delete(key) end |