Class: ActionPushNative::Service::Fcm::HttpxSession

Inherits:
Object
  • Object
show all
Defined in:
lib/action_push_native/service/fcm/httpx_session.rb

Constant Summary collapse

DEFAULT_REQUEST_TIMEOUT =

FCM suggests at least a 10s timeout for requests, we set 15 to add some buffer. firebase.google.com/docs/cloud-messaging/scale-fcm#timeouts

15.seconds
DEFAULT_POOL_SIZE =
5

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ HttpxSession



9
10
11
12
13
14
15
16
17
# File 'lib/action_push_native/service/fcm/httpx_session.rb', line 9

def initialize(config)
  @session = \
    HTTPX.
      plugin(:persistent, close_on_fork: true).
      with(timeout: { request_timeout: config[:request_timeout] || DEFAULT_REQUEST_TIMEOUT }).
      with(pool_options: { max_connections: config[:connection_pool_size] || DEFAULT_POOL_SIZE }).
      with(origin: "https://fcm.googleapis.com")
  @token_provider = ActionPushNative::Service::Fcm::TokenProvider.new(config)
end

Instance Method Details

#post(*uri, **options) ⇒ Object



19
20
21
22
23
# File 'lib/action_push_native/service/fcm/httpx_session.rb', line 19

def post(*uri, **options)
  options[:headers] ||= {}
  options[:headers][:authorization] = "Bearer #{token_provider.fresh_access_token}"
  session.post(*uri, **options)
end