Class: Bitly::HTTP::Client
- Inherits:
-
Object
- Object
- Bitly::HTTP::Client
- Defined in:
- lib/bitly/http/client.rb
Instance Method Summary collapse
-
#initialize(adapter = Bitly::HTTP::Adapters::NetHTTP.new) ⇒ Client
constructor
A new instance of Client.
-
#request(request) ⇒ Bitly::HTTP::Response
The main method for the HTTP client.
Constructor Details
#initialize(adapter = Bitly::HTTP::Adapters::NetHTTP.new) ⇒ Client
Returns a new instance of Client.
6 7 8 9 |
# File 'lib/bitly/http/client.rb', line 6 def initialize(adapter=Bitly::HTTP::Adapters::NetHTTP.new) @adapter = adapter raise ArgumentError, "Adapter must have a request method." unless @adapter.respond_to?(:request) end |
Instance Method Details
#request(request) ⇒ Bitly::HTTP::Response
The main method for the HTTP client. It receives a Bitly::HTTP::Request object, makes the request described and returns a Bitly::HTTP::Response.
22 23 24 25 26 27 28 29 30 |
# File 'lib/bitly/http/client.rb', line 22 def request(request) status, body, headers, success = @adapter.request(request) response = Bitly::HTTP::Response.new(status: status, body: body, headers: headers, request: request) if success return response else raise Bitly::Error, response end end |