Class: Request

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

Overview

The Request class handles making HTTP requests using the HTTParty gem.

Instance Method Summary collapse

Constructor Details

#initialize(url, headers = {}, params = {}) ⇒ Request

Initializes a new instance of the Request class.

Parameters:

  • url (String)

    The URL for the HTTP request.

  • headers (Hash) (defaults to: {})

    (optional) The headers to include in the HTTP request.

  • params (Hash) (defaults to: {})

    (optional) The parameters to include in the HTTP request.



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

def initialize(url, headers = {}, params = {})
  @url = url
  @params = params
  @headers = headers
  @lang = 'en'

  @response = send_request(url, headers, params)
end

Instance Method Details

#contentHash

Returns the parsed content of the HTTP response.

Returns:

  • (Hash)

    The parsed content of the HTTP response.



24
25
26
# File 'lib/flight_radar/request.rb', line 24

def content
  @response.parsed_response
end

#content_typeString

Returns the content type of the HTTP response.

Returns:

  • (String)

    The content type of the HTTP response.



31
32
33
# File 'lib/flight_radar/request.rb', line 31

def content_type
  @response.content_type
end

#status_codeInteger

Returns the status code of the HTTP response.

Returns:

  • (Integer)

    The status code of the HTTP response.



38
39
40
# File 'lib/flight_radar/request.rb', line 38

def status_code
  @response.code
end

#success?Boolean

Checks if the HTTP response code indicates success.

Returns:

  • (Boolean)

    Returns true if the response code is within the range 200 to 299 (inclusive), indicating success.



45
46
47
# File 'lib/flight_radar/request.rb', line 45

def success?
  (200..299).include?(@response.code)
end