Class: ThreadsApi::RequestHandler

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

Overview

The RequestHandler class provides methods for sending HTTP GET and POST requests.

Class Method Summary collapse

Class Method Details

.send_get_request(url) ⇒ Object

It is a class method that sends an HTTP GET request to the specified URL and returns the response body.



11
12
13
14
15
16
17
18
19
# File 'lib/request_handler.rb', line 11

def self.send_get_request(url)
  uri = URI(url)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true

  request = Net::HTTP::Get.new(uri)
  response = http.request(request)
  response.body
end

.send_request(url:, headers:, data:) ⇒ Object

It is a class method that sends an HTTP POST request to the specified URL with the provided headers and data.



22
23
24
25
26
27
28
29
30
31
# File 'lib/request_handler.rb', line 22

def self.send_request(url:, headers:, data:)
  uri = URI(url)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true

  request = Net::HTTP::Post.new(uri.path, headers)
  request.set_form_data(data)

  http.request(request)
end