Class: Zonomi::API::Request

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

Constant Summary collapse

REQUEST_METHOD =
:get
RESULT_KEY =
'dnsapi_result'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Request

Returns a new instance of Request.



10
11
12
13
14
15
16
17
# File 'lib/zonomi/api/request.rb', line 10

def initialize(params = {})
  @params = params
  @client = @params.delete(:client)
  @request_path = @params.delete(:request_path)
  @response = nil
  @result = nil
  self
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



8
9
10
# File 'lib/zonomi/api/request.rb', line 8

def client
  @client
end

#paramsObject (readonly)

Returns the value of attribute params.



8
9
10
# File 'lib/zonomi/api/request.rb', line 8

def params
  @params
end

#responseObject (readonly)

Returns the value of attribute response.



8
9
10
# File 'lib/zonomi/api/request.rb', line 8

def response
  @response
end

#resultObject (readonly)

Returns the value of attribute result.



8
9
10
# File 'lib/zonomi/api/request.rb', line 8

def result
  @result
end

Instance Method Details

#send!Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/zonomi/api/request.rb', line 19

def send!
  request_params = [
    REQUEST_METHOD,
    path_for(*@request_path),
    { query: prepare(@params) }
  ]
  @response = self.client.class.send(*request_params)
  @result = Result.new(@response[RESULT_KEY])
  self
end