Class: Interage::Request::Start
- Inherits:
-
Object
- Object
- Interage::Request::Start
- Defined in:
- lib/interage/request/start.rb
Class Method Summary collapse
Instance Method Summary collapse
- #body ⇒ Object
- #code ⇒ Object
- #errors ⇒ Object
-
#initialize(klass, uri, params = {}, headers = {}, ssl = false) ⇒ Start
constructor
A new instance of Start.
- #perform ⇒ Object
- #success? ⇒ Boolean
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
#body ⇒ Object
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 |
#code ⇒ Object
36 37 38 |
# File 'lib/interage/request/start.rb', line 36 def code response_code.to_i end |
#errors ⇒ Object
44 45 46 |
# File 'lib/interage/request/start.rb', line 44 def errors body[:errors] || {} end |
#perform ⇒ Object
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
40 41 42 |
# File 'lib/interage/request/start.rb', line 40 def success? == 'OK' && errors.blank? end |