Class: Stn::Request Private
- Inherits:
-
Object
- Object
- Stn::Request
- Defined in:
- lib/stn/http_request.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
A wrapper around Net::HTTP to send HTTP requests to the ServiceTitan API and return their result or raise an error if the result is unexpected. The basic way to use HTTPRequest is by calling run on an instance.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Request
constructor
private
Initializes an HTTPRequest object.
-
#run ⇒ Hash
private
Sends the request and returns the body parsed from the JSON response.
Constructor Details
#initialize(options = {}) ⇒ Request
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializes an HTTPRequest object.
25 26 27 28 29 30 |
# File 'lib/stn/http_request.rb', line 25 def initialize( = {}) @host = [:host] @path = [:path] @body = [:body] @headers = .fetch :headers, {} end |
Instance Method Details
#run ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Sends the request and returns the body parsed from the JSON response.
36 37 38 39 40 41 |
# File 'lib/stn/http_request.rb', line 36 def run return {} if response.body.empty? JSON(response.body).tap do |data| raise Error, data['error'] if data['error'] end end |