Class: SimpleFCM::Client
- Inherits:
-
Object
- Object
- SimpleFCM::Client
- Defined in:
- lib/simple_fcm/client.rb
Instance Method Summary collapse
-
#initialize(config = nil) {|conn| ... } ⇒ Client
constructor
A new instance of Client.
-
#push(message) ⇒ string
Send a push notification to a device or topic through Firebase Cloud Messaging.
Constructor Details
#initialize(config = nil) {|conn| ... } ⇒ Client
Returns a new instance of Client.
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/simple_fcm/client.rb', line 22 def initialize(config = nil) @credentials = build_credentials(config) @client = Faraday::Connection.new(ENDPOINT) do |conn| conn.request :simple_fcm_auth, @credentials conn.request :json conn.response :json, parser_options: {symbolize_names: true} if block_given? yield conn end end end |
Instance Method Details
#push(message) ⇒ string
Send a push notification to a device or topic through Firebase Cloud Messaging.
45 46 47 48 49 50 51 52 53 |
# File 'lib/simple_fcm/client.rb', line 45 def push() resp = @client.post("/v1/projects/#{project_id}/messages:send", ) if !resp.success? raise ::SimpleFCM::APIError, resp end resp.body[:name] end |