Class: SmsAero2::Request

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

Defined Under Namespace

Classes: HttpError, InvalidResponse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Request

Returns a new instance of Request.



12
13
14
15
# File 'lib/sms_aero2/request.rb', line 12

def initialize(client)
  @client = client
  @logger = client.logger
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



10
11
12
# File 'lib/sms_aero2/request.rb', line 10

def client
  @client
end

#loggerObject (readonly)

Returns the value of attribute logger.



10
11
12
# File 'lib/sms_aero2/request.rb', line 10

def logger
  @logger
end

Instance Method Details

#call(url, **params) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/sms_aero2/request.rb', line 17

def call(url, **params)
  uri = URI(url)
  uri.query = URI.encode_www_form(params)

  response = send_request(uri)
  logger&.info(
      "Send http request to GET #{url} with params: #{params}"
  )
  response_body(response)

rescue SmsAero2::Error => e
  logger&.error("http request to #{url} with params: #{params} is failed message: #{e.message}")
  raise e
end