Class: Apnotic::Connection
- Inherits:
-
Object
- Object
- Apnotic::Connection
- Defined in:
- lib/apnotic/connection.rb
Instance Attribute Summary collapse
-
#cert_path ⇒ Object
readonly
Returns the value of attribute cert_path.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(options = {}) ⇒ Connection
constructor
A new instance of Connection.
- #push(notification, options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Connection
19 20 21 22 23 24 25 26 27 |
# File 'lib/apnotic/connection.rb', line 19 def initialize(={}) @url = [:url] || APPLE_PRODUCTION_SERVER_URI @cert_path = [:cert_path] @cert_pass = [:cert_pass] raise "Cert file not found: #{@cert_path}" unless @cert_path && File.exist?(@cert_path) @client = NetHttp2::Client.new(@url, ssl_context: ssl_context) end |
Instance Attribute Details
#cert_path ⇒ Object (readonly)
Returns the value of attribute cert_path.
10 11 12 |
# File 'lib/apnotic/connection.rb', line 10 def cert_path @cert_path end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
10 11 12 |
# File 'lib/apnotic/connection.rb', line 10 def url @url end |
Class Method Details
.development(options = {}) ⇒ Object
13 14 15 16 |
# File 'lib/apnotic/connection.rb', line 13 def development(={}) .merge!(url: APPLE_DEVELOPMENT_SERVER_URI) new() end |
Instance Method Details
#close ⇒ Object
39 40 41 |
# File 'lib/apnotic/connection.rb', line 39 def close @client.close end |
#push(notification, options = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/apnotic/connection.rb', line 29 def push(notification, ={}) request = Apnotic::Request.new(notification) response = @client.call(:post, request.path, body: request.body, headers: request.headers, timeout: [:timeout] ) Apnotic::Response.new(headers: response.headers, body: response.body) if response end |