Class: Httpsensible::Client
- Inherits:
-
Object
- Object
- Httpsensible::Client
- Defined in:
- lib/httpsensible/client.rb,
lib/httpsensible/client/response.rb
Defined Under Namespace
Classes: Response
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#initialize(user_agent: nil) ⇒ Client
constructor
A new instance of Client.
-
#request(*args, **options) ⇒ Object
TODO: test this.
-
#with(options, &blk) ⇒ Object
TODO: test this.
-
#with_authentication(authentication) ⇒ Object
TODO: test this.
- #with_headers(headers) ⇒ Object
-
#with_plugin(plugin) ⇒ Object
TODO: test this.
Constructor Details
#initialize(user_agent: nil) ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/httpsensible/client.rb', line 12 def initialize(user_agent: nil) headers = { "content-type" => "application/json", "accept" => "application/json", } if !user_agent.nil? && !user_agent.empty? headers["user-agent"] = user_agent end @client = HTTPX.plugin(:persistent) .plugin(:retries, max_retries: 3) .with_headers(headers) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
10 11 12 |
# File 'lib/httpsensible/client.rb', line 10 def client @client end |
Instance Method Details
#request(*args, **options) ⇒ Object
TODO: test this
50 51 52 53 54 55 56 57 |
# File 'lib/httpsensible/client.rb', line 50 def request(*args, **) responses = @client.request(*args, *) @last_response = if responses.is_a?(Array) responses.map { |response| Httpsensible::Client::Response.new(response) } else Httpsensible::Client::Response.new(responses) end end |
#with(options, &blk) ⇒ Object
TODO: test this
44 45 46 47 |
# File 'lib/httpsensible/client.rb', line 44 def with(, &blk) @client = @client.with(, &blk) self end |
#with_authentication(authentication) ⇒ Object
TODO: test this
33 34 35 36 |
# File 'lib/httpsensible/client.rb', line 33 def with_authentication(authentication) @client = @client.authentication(authentication) self end |
#with_headers(headers) ⇒ Object
38 39 40 41 |
# File 'lib/httpsensible/client.rb', line 38 def with_headers(headers) @client = @client.with(headers: headers) self end |
#with_plugin(plugin) ⇒ Object
TODO: test this
27 28 29 30 |
# File 'lib/httpsensible/client.rb', line 27 def with_plugin(plugin) @client = @client.plugin(plugin) self end |