Class: AtProto::Request
- Inherits:
-
Object
- Object
- AtProto::Request
- Defined in:
- lib/atproto_client/request.rb
Overview
Handles HTTP requests for the AT Protocol client Throw the errors needed for the flow (Dpop and TokenInvalid)
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#initialize(method, uri, headers = {}, body = nil) ⇒ Request
constructor
Creates a new Request instance.
-
#run ⇒ Hash
Executes the HTTP request.
Constructor Details
#initialize(method, uri, headers = {}, body = nil) ⇒ Request
Creates a new Request instance
20 21 22 23 24 25 |
# File 'lib/atproto_client/request.rb', line 20 def initialize(method, uri, headers = {}, body = nil) @uri = URI(uri) @method = method @headers = headers @body = body end |
Instance Attribute Details
#body ⇒ URI, ...
11 12 13 |
# File 'lib/atproto_client/request.rb', line 11 def body @body end |
#headers ⇒ URI, ...
11 12 13 |
# File 'lib/atproto_client/request.rb', line 11 def headers @headers end |
#method ⇒ URI, ...
11 12 13 |
# File 'lib/atproto_client/request.rb', line 11 def method @method end |
#uri ⇒ URI, ...
11 12 13 |
# File 'lib/atproto_client/request.rb', line 11 def uri @uri end |
Instance Method Details
#run ⇒ Hash
Executes the HTTP request
Makes the HTTP request with configured parameters and handles the response. Automatically sets Content-Type and Accept headers to application/json.
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/atproto_client/request.rb', line 37 def run request_class = HTTP_METHODS[method] req = request_class.new(uri).tap do |request| headers.each { |k, v| request[k] = v } request['Content-Type'] = 'application/json' request['Accept'] = 'application/json' request.body = body end response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http| http.request(req) end handle_response(response) end |