Skip to content

Commit

Permalink
Merge pull request #39 from magynhard/issue-38_proxy_support
Browse files Browse the repository at this point in the history
  • Loading branch information
miyataka authored Oct 14, 2023
2 parents 0ad4d3e + 3ee902b commit 341953d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ Fcmpush.configure do |config|
config.server_key = 'your firebase server key'
# Or set environment variables
# ENV['FCM_SERVER_KEY'] = 'your firebase server key'

# Proxy ENV variables are considered by default if set by net/http, but you can explicitly define your proxy host here
# user and password are optional
# config.proxy = { uri: "http://proxy.host:3128", user: nil, password: nil }
# explicitly disable using proxy, even ignore environment variables if set
# config.proxy = false
end
```

Expand Down
11 changes: 11 additions & 0 deletions lib/fcmpush/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ def initialize(domain, project_id, configuration, **options)
@access_token_expiry = Time.now.utc + access_token_response['expires_in']
@server_key = configuration.server_key
@connection = Net::HTTP::Persistent.new
if configuration.proxy && configuration.proxy[:uri]
uri = URI(configuration.proxy[:uri])
# user name must not be a empty string, password can
if configuration.proxy[:user] && configuration.proxy[:user].strip != ''
uri.user = configuration.proxy[:user]
uri.password = configuration.proxy[:password] if configuration.proxy[:password]
end
@connection.proxy = uri
elsif configuration.proxy != false
@connection.proxy = :ENV
end
end

def v1_authorize
Expand Down
2 changes: 1 addition & 1 deletion lib/fcmpush/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Fcmpush
class Configuration
attr_accessor :scope, :json_key_io, :server_key
attr_accessor :scope, :json_key_io, :server_key, :proxy

def initialize
@scope = ['https://www.googleapis.com/auth/firebase.messaging']
Expand Down

0 comments on commit 341953d

Please sign in to comment.