Class: Interage::Request::Start

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, uri, params = {}, headers = {}, ssl = false) ⇒ Start

Returns a new instance of Start.



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

def initialize(klass, uri, params = {}, headers = {}, ssl = false)
  @klass = klass
  @uri = URI(uri.to_s)
  @params = params
  @headers = headers
  @ssl = ssl
end

Class Method Details

.call(*args) ⇒ Object



8
9
10
# File 'lib/interage/request/start.rb', line 8

def self.call(*args)
  new(*args).perform
end

Instance Method Details

#bodyObject



30
31
32
33
34
# File 'lib/interage/request/start.rb', line 30

def body
  @body ||= JSON.parse(response_body, symbolize_names: true)
rescue JSON::ParserError
  {}
end

#codeObject



36
37
38
# File 'lib/interage/request/start.rb', line 36

def code
  response_code.to_i
end

#errorsObject



44
45
46
# File 'lib/interage/request/start.rb', line 44

def errors
  body[:errors] || {}
end

#performObject



20
21
22
23
24
25
26
27
28
# File 'lib/interage/request/start.rb', line 20

def perform
  @response = Net::HTTP.start(uri.host, uri.port) do |http|
    http.use_ssl = true if ssl?

    http.request(request)
  end

  self
end

#success?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/interage/request/start.rb', line 40

def success?
  response_message == 'OK' && errors.blank?
end