Class: Postmen::Connection
- Inherits:
-
Object
- Object
- Postmen::Connection
- Defined in:
- lib/postmen/connection.rb
Overview
Connection class is used to perform any HTTP connections, it also does error handling.
Constant Summary collapse
- MAX_REQUESTS =
Maximum number of retries
5- MAIN_DOMAIN =
Main domain used during normal usage.
'postmen.com'.freeze
- FAILOVER_DOMAIN =
Failover domain used during DNS issues with main domain
'postmen.net'.freeze
Class Method Summary collapse
-
.endpoint(subdomain, failover = false) ⇒ Object
Returns the endpoint used in SDK, based on the region(subdomain) and a failover switch.
-
.hostname(subdomain, failover) ⇒ Object
Returns the hostname based on the region(subdomain) and a failover switch.
Instance Method Summary collapse
-
#delete(path) ⇒ Object
Performs a HTTP DELETE request.
-
#get(path, options = {}) ⇒ Object
Performs a HTTP GET request.
-
#initialize ⇒ Connection
constructor
A new instance of Connection.
-
#post(path, options = {}) ⇒ Object
Performs a HTTP POST request.
-
#put(path, options = {}) ⇒ Object
Performs a HTTP PUT request.
Constructor Details
#initialize ⇒ Connection
14 15 16 |
# File 'lib/postmen/connection.rb', line 14 def initialize @requests = 0 end |
Class Method Details
.endpoint(subdomain, failover = false) ⇒ Object
Returns the endpoint used in SDK, based on the region(subdomain) and a failover switch
73 74 75 76 77 |
# File 'lib/postmen/connection.rb', line 73 def self.endpoint(subdomain, failover = false) URI::HTTPS.build(scheme: 'https', host: hostname(subdomain, failover), path: '/v3').to_s end |
.hostname(subdomain, failover) ⇒ Object
Returns the hostname based on the region(subdomain) and a failover switch
83 84 85 86 |
# File 'lib/postmen/connection.rb', line 83 def self.hostname(subdomain, failover) base = failover ? FAILOVER_DOMAIN : MAIN_DOMAIN [subdomain, base].join('.') end |
Instance Method Details
#delete(path) ⇒ Object
Performs a HTTP DELETE request
62 63 64 65 66 |
# File 'lib/postmen/connection.rb', line 62 def delete(path) HTTP .headers(headers) .delete(get_full_url(path)) end |
#get(path, options = {}) ⇒ Object
Performs a HTTP GET request.
25 26 27 28 29 |
# File 'lib/postmen/connection.rb', line 25 def get(path, = {}) with_error_handling do Response.new(raw_get(path, )).tap(&:parse_response!) end end |
#post(path, options = {}) ⇒ Object
Performs a HTTP POST request.
38 39 40 41 42 |
# File 'lib/postmen/connection.rb', line 38 def post(path, = {}) with_error_handling do Response.new(raw_post(path, )) end end |
#put(path, options = {}) ⇒ Object
Performs a HTTP PUT request.
51 52 53 54 55 |
# File 'lib/postmen/connection.rb', line 51 def put(path, = {}) with_error_handling do Response.new(raw_put(path, )).tap(&:parse_response!) end end |