Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(service): add fcm #272

Merged
merged 2 commits into from
May 9, 2022
Merged

Conversation

svaloumas
Copy link
Collaborator

Description

Adds Firebase Cloud Messaging (FCM) service.

Motivation and Context

Adds a new service to the list of the currently supported ones.

How Has This Been Tested?

Unit tests implemented under service/fcm/fcm_test.go.

Integration tests have been performed using FCM toolbox.

Sample code to run an integration test.

package main

import (
	"context"
	"log"

	"github.com/nikoksr/notify"
	"github.com/nikoksr/notify/service/fcm"
)

func main() {
	fcmSvc, err := fcm.New("server_api_key")
	if err != nil {
		log.Fatalf("fcm.New() failed: %s", err.Error())
	}

	fcmSvc.AddReceivers("deviceToken1")

	notifier := notify.New()
	notifier.UseServices(fcmSvc)

	// Use context.Background() if you want to send a simple notification message.
	ctx := context.Background()

	// Optionally, you can include additional data in the message payload by adding the corresponding value to the context.
	ctxWithData := context.WithValue(ctx, fcm.DataKey, map[string]interface{}{
		"some-key":  "some-value",
		"other-key": "other-value",
	})

	// Optionally, you can specify a total of retry attempts per each message by adding the corresponding value to the context.
	ctxWithDataAndRetries := context.WithValue(ctxWithData, fcm.RetriesKey, 3)

	err = notifier.Send(ctxWithDataAndRetries, "subject", "message")
	if err != nil {
		log.Fatalf("notifier.Send() failed: %s", err.Error())
	}

	log.Println("notification sent")
}

Please find below sample images from the results of the integration tests.

Screenshots / Output (if appropriate):

notify1
notify2

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (no code change)
  • Refactor (refactoring production code)
  • Other

Checklist:

  • My code follows the code style of this project.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@codecov-commenter
Copy link

codecov-commenter commented May 8, 2022

Codecov Report

Merging #272 (a38dbb0) into main (4564e02) will increase coverage by 3.23%.
The diff coverage is 75.34%.

@@            Coverage Diff             @@
##             main     #272      +/-   ##
==========================================
+ Coverage   51.39%   54.62%   +3.23%     
==========================================
  Files          12       14       +2     
  Lines         467      540      +73     
==========================================
+ Hits          240      295      +55     
- Misses        208      222      +14     
- Partials       19       23       +4     
Impacted Files Coverage Δ
service/fcm/mock_fcmClient.go 73.91% <73.91%> (ø)
service/fcm/fcm.go 76.00% <76.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4564e02...a38dbb0. Read the comment docs.

@nikoksr
Copy link
Owner

nikoksr commented May 9, 2022

Hey @svaloumas, this one of the cleanest and most complete PRs, yet. I'm really impressed by and appreciative for your contribution! I would be very excited to see more contributions from you.

@nikoksr nikoksr merged commit d448ef6 into nikoksr:main May 9, 2022
@svaloumas
Copy link
Collaborator Author

Thanks for your kind comment @nikoksr ! I'm glad you liked it, I enjoyed it myself as well ✌️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants