Code Monkey home page Code Monkey logo

pushraven's Introduction

Pushraven

A library to easily send notifications over Firebase Cloud Messaging (FCM). The library was built with the purpose of making the process of sending messages as simple and modular as posible.

Legacy API

FCM has had a total makeover for the new "REST v1 API". I have decided not to include backwards compatibility in Pushraven.
If you wish to use the (simpler) legacy API see Legacy Instructions

How to use Pushraven

0. Import Pushraven to your Project.

NOTE: New package name to remove redundant 'pushraven' in groupId!
Add Pushraven.jar and it's dependencies to your project. Or add Pushraven as a dependency:
Maven:

<dependency>
  <groupId>us.raudi</groupId>
  <artifactId>pushraven</artifactId>
  <version>1.0.1</version>
</dependency>

Gradle:

compile group: 'us.raudi', name: 'pushraven', version: '1.0.1'

1. Give Pushraven your Project ID and your Service Account

Both of these can be found in your Firebase console Project Settings:

  • The ID is found in the "General" tab
  • The Service Account JSON file can be downloaded from the "Service Account" tab.
Pushraven.setAccountFile(new File("service_account.json"));
Pushraven.setProjectId("project-1234");

2. Build your 'Message' using parameters from the FCM reference[1]

In Pushraven all the JSON Objects from the API are implemented as classes, and all fields are implemented as methods.

2.1 Create Notification

Notification not = new Notification()
		.title("Hello World")
		.body("This is a notification");

2.2 (Optional) Create target specific configurations.

AndroidConfig droidCfg = new AndroidConfig()
			.notification(
				new AndroidNotification()
				.color("#ff0000")
			)
			.priority(Priority.HIGH);

2.3 Create the Message (using Notification and any configs)

Message raven = new Message()
		.name("id")
		.notification(not)
		.token(CLIENT_ID) // could instead use: topic(String) or condition(String)
		.android(droidCfg);
NOTE: Missing attributes

If the API updates and implements new fields to any class, these may not have been added to Pushraven yet. You can use the following methods (for any of the constructor classes: Message, Notification, config classes...):

addAttribute(String key, Object value);
addAttributeMap(String key, Map<?, ?> map);
addAttributeArray(String key, Collection<?> arr);
addAttributePayload(String key, Payload payload); // see: Payload.java

3. Send the raven

Pushraven.push(raven);
// or (if you want to access the response)
FcmResponse response = Pushraven.push(raven);

[1] https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages

pushraven's People

Contributors

raudius avatar aulaga avatar amyboyd avatar equintana avatar brodoin avatar mojojojo961 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.