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.
-
#timeout ⇒ Object
readonly
The Timeout to use when making the HTTP request.
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.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/socketlabs/injectionapi/core/http_request.rb', line 38 def initialize( http_request_method, arguments = nil ) @request_method = http_request_method @endpoint = "https://inject.socketlabs.com/api/v1/email" @proxy = Array.new @timeout = 120 @headers = [ { :key => "User-Agent", :value => user_agent}, { :key => "Content-Type", :value => "application/json; charset=utf-8" }, { :key => "Accept", :value => "application/json"} ] 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 unless arguments[:timeout].nil? @timeout = arguments[:timeout] end unless arguments[:authorization].nil? || arguments[:authorization].empty? @headers.push({ :key => "Authorization", :value => 'Bearer ' + arguments[:authorization]}) 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 |
#timeout ⇒ Object (readonly)
The Timeout to use when making the HTTP request
32 33 34 |
# File 'lib/socketlabs/injectionapi/core/http_request.rb', line 32 def timeout @timeout 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
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/socketlabs/injectionapi/core/http_request.rb', line 79 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) http_response end |