Class: SimpleHttpService::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Client

Returns a new instance of Client.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/simple_http_service/client.rb', line 7

def initialize(opts)
  raise 'URL must be present' unless opts[:url]
  raise 'http_method must be present' unless opts[:http_method]

  @uri = URI(opts[:url])
  @http_method = opts[:http_method]
  @headers = opts[:headers] || {}
  @request_body = opts[:request_body]
  @open_timeout = opts[:open_timeout] || false
  @read_timeout = opts[:read_timeout] || false
  @write_timeout = opts[:write_timeout] || false
  @max_retries = opts[:max_retries] || 1
  @additional_headers = opts[:additional_headers] || {}
end

Instance Attribute Details

#additional_headersObject

Returns the value of attribute additional_headers.



4
5
6
# File 'lib/simple_http_service/client.rb', line 4

def additional_headers
  @additional_headers
end

#headersObject

Returns the value of attribute headers.



4
5
6
# File 'lib/simple_http_service/client.rb', line 4

def headers
  @headers
end

#http_methodObject

Returns the value of attribute http_method.



4
5
6
# File 'lib/simple_http_service/client.rb', line 4

def http_method
  @http_method
end

#max_retriesObject

Returns the value of attribute max_retries.



4
5
6
# File 'lib/simple_http_service/client.rb', line 4

def max_retries
  @max_retries
end

#open_timeoutObject

Returns the value of attribute open_timeout.



4
5
6
# File 'lib/simple_http_service/client.rb', line 4

def open_timeout
  @open_timeout
end

#read_timeoutObject

Returns the value of attribute read_timeout.



4
5
6
# File 'lib/simple_http_service/client.rb', line 4

def read_timeout
  @read_timeout
end

#request_bodyObject

Returns the value of attribute request_body.



4
5
6
# File 'lib/simple_http_service/client.rb', line 4

def request_body
  @request_body
end

#uriObject

Returns the value of attribute uri.



4
5
6
# File 'lib/simple_http_service/client.rb', line 4

def uri
  @uri
end

#write_timeoutObject

Returns the value of attribute write_timeout.



4
5
6
# File 'lib/simple_http_service/client.rb', line 4

def write_timeout
  @write_timeout
end

Instance Method Details

#callObject



22
23
24
25
26
27
# File 'lib/simple_http_service/client.rb', line 22

def call
  enable_ssl
  set_headers
  set_timeout
  http.request(request)
end