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.
- #join(timeout: nil) ⇒ Object
- #on(event, &block) ⇒ Object
- #prepare_push(notification) ⇒ Object
- #push(notification, options = {}) ⇒ Object
- #push_async(push) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Connection
Returns a new instance of Connection.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/apnotic/connection.rb', line 20 def initialize(={}) @url = [:url] || APPLE_PRODUCTION_SERVER_URL @cert_path = [:cert_path] @cert_pass = [:cert_pass] @connect_timeout = [:connect_timeout] || 30 @auth_method = [:auth_method] || :cert @team_id = [:team_id] @key_id = [:key_id] @first_push = true raise "Cert file not found: #{@cert_path}" unless @cert_path && (@cert_path.respond_to?(:read) || File.exist?(@cert_path)) = { ssl_context: ssl_context, connect_timeout: @connect_timeout } PROXY_SETTINGS_KEYS.each do |key| [key] = [key] if [key] end @client = NetHttp2::Client.new(@url, ) end |
Instance Attribute Details
#cert_path ⇒ Object (readonly)
Returns the value of attribute cert_path.
11 12 13 |
# File 'lib/apnotic/connection.rb', line 11 def cert_path @cert_path end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
11 12 13 |
# File 'lib/apnotic/connection.rb', line 11 def url @url end |
Class Method Details
.development(options = {}) ⇒ Object
14 15 16 17 |
# File 'lib/apnotic/connection.rb', line 14 def development(={}) .merge!(url: APPLE_DEVELOPMENT_SERVER_URL) new() end |
Instance Method Details
#close ⇒ Object
71 72 73 |
# File 'lib/apnotic/connection.rb', line 71 def close @client.close end |
#join(timeout: nil) ⇒ Object
75 76 77 |
# File 'lib/apnotic/connection.rb', line 75 def join(timeout: nil) @client.join(timeout: timeout) end |
#on(event, &block) ⇒ Object
79 80 81 |
# File 'lib/apnotic/connection.rb', line 79 def on(event, &block) @client.on(event, &block) end |
#prepare_push(notification) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/apnotic/connection.rb', line 62 def prepare_push(notification) request = prepare_request(notification) http2_request = @client.prepare_request(:post, request.path, body: request.body, headers: request.headers ) Apnotic::Push.new(http2_request) end |
#push(notification, options = {}) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/apnotic/connection.rb', line 43 def push(notification, ={}) request = prepare_request(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 |
#push_async(push) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/apnotic/connection.rb', line 53 def push_async(push) if @first_push @client.call_async(push.http2_request) @first_push = false else delayed_push_async(push) end end |