Class: SocketLabs::InjectionApi::Core::HttpRequest
- Inherits:
-
Object
- Object
- SocketLabs::InjectionApi::Core::HttpRequest
- Defined in:
- lib/socketlabs/injectionapi/core/http_request.rb
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
The SocketLabs Injection API endpoint.
-
#http ⇒ Object
readonly
The Net::HTTP used when making the HTTP request.
-
#proxy ⇒ Object
readonly
The Proxy to use when making the HTTP request.
-
#request_method ⇒ Object
readonly
The HTTP Request Method to use.
Class Method Summary collapse
-
.http_request_method ⇒ Object
Hash enumeration of HTTP Request Methods.
Instance Method Summary collapse
-
#initialize(http_request_method, arguments = nil) ⇒ HttpRequest
constructor
A new instance of HttpRequest.
-
#send_request(request) ⇒ Object
Send the HTTP Request.
Constructor Details
#initialize(http_request_method, arguments = nil) ⇒ HttpRequest
Returns a new instance of HttpRequest.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/socketlabs/injectionapi/core/http_request.rb', line 36 def initialize( http_request_method, arguments = nil ) @request_method = http_request_method @endpoint = "https://inject.socketlabs.com/api/v1/email" @proxy = Array.new unless arguments.nil? || arguments.empty? unless arguments[:http_endpoint].nil? || arguments[:http_endpoint].empty? @endpoint = arguments[:http_endpoint] end unless arguments[:proxy].nil? || arguments[:proxy].empty? @proxy = arguments[:proxy] end end @http = nil @request = build_request end |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
The SocketLabs Injection API endpoint
26 27 28 |
# File 'lib/socketlabs/injectionapi/core/http_request.rb', line 26 def endpoint @endpoint end |
#http ⇒ Object (readonly)
The Net::HTTP used when making the HTTP request
30 31 32 |
# File 'lib/socketlabs/injectionapi/core/http_request.rb', line 30 def http @http end |
#proxy ⇒ Object (readonly)
The Proxy to use when making the HTTP request
28 29 30 |
# File 'lib/socketlabs/injectionapi/core/http_request.rb', line 28 def proxy @proxy end |
#request_method ⇒ Object (readonly)
The HTTP Request Method to use
24 25 26 |
# File 'lib/socketlabs/injectionapi/core/http_request.rb', line 24 def request_method @request_method end |
Class Method Details
.http_request_method ⇒ Object
Hash enumeration of HTTP Request Methods
14 15 16 17 18 19 20 21 |
# File 'lib/socketlabs/injectionapi/core/http_request.rb', line 14 def self.http_request_method { :Get => { :method => "GET" }, :Post => { :method => "POST" }, :Put => { :method => "PUT" }, :Delete => { :method => "DELETE" } } end |
Instance Method Details
#send_request(request) ⇒ Object
Send the HTTP Request
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/socketlabs/injectionapi/core/http_request.rb', line 62 def send_request(request) factory_hash = request.to_hash @request.body = factory_hash.to_json # send request response = @http.request(@request) http_response = HttpResponse.new(response) parser = InjectionResponseParser.new parser.parse(http_response) end |