Class: Hubspot::HttpRequest
- Defined in:
- lib/hubspot/http_request.rb
Direct Known Subclasses
Constant Summary collapse
- BASE_URL =
"https://api.hubapi.com"
Instance Attribute Summary collapse
-
#http ⇒ Object
Returns the value of attribute http.
-
#uri ⇒ Object
Returns the value of attribute uri.
Attributes inherited from Object
Instance Method Summary collapse
- #get(path, options = {}) ⇒ Object
-
#initialize(debug = true) ⇒ HttpRequest
constructor
A new instance of HttpRequest.
- #post(path, options = {}) ⇒ Object
Methods inherited from Object
call, #call, #constructor, #errors, #failure?, #success?
Constructor Details
#initialize(debug = true) ⇒ HttpRequest
Returns a new instance of HttpRequest.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/hubspot/http_request.rb', line 10 def initialize(debug = true) @uri = URI(BASE_URL) @http = Net::HTTP.new(uri.host, uri.port) if uri.scheme == "https" @http.use_ssl = true @http.verify_mode = OpenSSL::SSL::VERIFY_PEER end @http.set_debug_output($stdout) if debug end |
Instance Attribute Details
#http ⇒ Object
Returns the value of attribute http.
8 9 10 |
# File 'lib/hubspot/http_request.rb', line 8 def http @http end |
#uri ⇒ Object
Returns the value of attribute uri.
8 9 10 |
# File 'lib/hubspot/http_request.rb', line 8 def uri @uri end |
Instance Method Details
#get(path, options = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/hubspot/http_request.rb', line 22 def get(path, = {}) raise ArgumentError, "Path Error" if path.blank? body = JSON.dump() request = Net::HTTP::Get.new(path, body) response = http.request(request) HttpResponse.call(response) end |
#post(path, options = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/hubspot/http_request.rb', line 32 def post(path, = {}) raise ArgumentError, "Path Error" if path.blank? body = JSON.dump() request = Net::HTTP::Post.new(path) # fyi: uri.path or just uri request.add_field("Content-Type", "application/json") request.body = body response = http.request(request) HttpResponse.call(response) end |