pebble/devsite/source/_guides/pebble-timeline/timeline-libraries.md
2025-02-24 18:58:29 -08:00

6.6 KiB

title description guide_group order related_examples
Libraries for Pushing Pins A list of libraries available for interacting with the Pebble timeline. pebble-timeline 1
title url
Hello Timeline https://github.com/pebble-examples/hello-timeline
title url
Timeline TV Tracker https://github.com/pebble-examples/timeline-tv-tracker
title url
Timeline Push Pin https://github.com/pebble-examples/timeline-push-pin

This page contains libraries that are currently available to interact with the timeline. You can use these to build apps and services that push pins to your users.

timeline.js

JavaScript Code Snippet - Available on GitHub

Install

Copy into the src/pkjs/ directory of your project, add enableMultiJS: true in package.json, then require and use in index.js.

Example

var timeline = require('./timeline');

// Push a pin when the app starts
Pebble.addEventListener('ready', function() {
  // An hour ahead
  var date = new Date();
  date.setHours(date.getHours() + 1);

  // Create the pin
  var pin = {
    "id": "example-pin-0",
    "time": date.toISOString(),
    "layout": {
      "type": "genericPin",
      "title": "Example Pin",
      "tinyIcon": "system://images/SCHEDULED_EVENT"
    }
  };

  console.log('Inserting pin in the future: ' + JSON.stringify(pin));

  // Push the pin
  timeline.insertUserPin(pin, function(responseText) {
    console.log('Result: ' + responseText);
  });
});

pebble-api

Node Module - Available on NPM

Install

npm install pebble-api --save

Example

var Timeline = require('pebble-api');

var USER_TOKEN = 'a70b23d3820e9ee640aeb590fdf03a56';

var timeline = new Timeline();

var pin = new Timeline.Pin({
  id: 'test-pin-5245',
  time: new Date(),
  duration: 10,
  layout: new Timeline.Pin.Layout({
    type: Timeline.Pin.LayoutType.GENERIC_PIN,
    tinyIcon: Timeline.Pin.Icon.PIN,
    title: 'Pin Title'
  })
});

timeline.sendUserPin(USER_TOKEN, pin, function (err) {
  if (err) {
    return console.error(err);
  }

  console.log('Pin sent successfully!');
});

PebbleTimeline API Ruby

Ruby Gem - Available on RubyGems

Install

gem install pebble_timeline

Example

require 'pebble_timeline'

api = PebbleTimeline::API.new(ENV['PEBBLE_TIMELINE_API_KEY'])

# Shared pins
pins = PebbleTimeline::Pins.new(api)
pins.create(id: "test-1", topics: 'test', time: "2015-06-10T08:01:10.229Z", layout: { type: 'genericPin', title: 'test 1' })
pins.delete("test-1")

# User pins
user_pins = PebbleTimeline::Pins.new(api, 'user', USER_TOKEN)
user_pins.create(id: "test-1", time: "2015-06-12T16:42:00Z", layout: { type: 'genericPin', title: 'test 1' })
user_pins.delete("test-1")

pypebbleapi

Python Library - Available on pip

Install

pip install pypebbleapi

Example

from pypebbleapi import Timeline, Pin
import datetime

timeline = Timeline(my_api_key)

my_pin = Pin(id='123', datetime.date.today().isoformat())

timeline.send_shared_pin(['a_topic', 'another_topic'], my_pin)

php-pebble-timeline

PHPebbleTimeline - Available on Github

Install

Copy the TimelineAPI folder (from the above repository) to your project's directory and include the required files.

Example

{% highlight { "language": "php", "options": { "startinline": true } } %} //Include the timeline API require_once 'TimelineAPI/Timeline.php';

//Import the required classes use TimelineAPI\Pin; use TimelineAPI\PinLayout; use TimelineAPI\PinLayoutType; use TimelineAPI\PinIcon; use TimelineAPI\PinReminder; use TimelineAPI\Timeline;

//Create some layouts which our pin will use $reminderlayout = new PinLayout(PinLayoutType::GENERIC_REMINDER, 'Sample reminder!', null, null, null, PinIcon::NOTIFICATION_FLAG); $pinlayout = new PinLayout(PinLayoutType::GENERIC_PIN, 'Our title', null, null, null, PinIcon::NOTIFICATION_FLAG);

//Create a reminder which our pin will push before the event $reminder = new PinReminder($reminderlayout, (new DateTime('now')) -> add(new DateInterval('PT10M')));

//Create the pin $pin = new Pin('', (new DateTime('now')) -> add(new DateInterval('PT5M')), $pinlayout);

//Attach the reminder $pin -> addReminder($reminder);

//Push the pin to the timeline Timeline::pushPin('sample-userToken', $pin); {% endhighlight %}

PinPusher

PHP Library - Available on Composer

Install

composer require valorin/pinpusher

Example

{% highlight { "language": "php", "options": { "startinline": true } } %} use Valorin\PinPusher\Pusher; use Valorin\PinPusher\Pin;

$pin = new Pin( 'example-pin-generic-1', new DateTime('2015-03-19T18:00:00Z'), new Pin\Layout\Generic( "News at 6 o'clock", Pin\Icon::NOTIFICATION_FLAG ) );

$pusher = new Pusher() $pusher->pushToUser($userToken, $pin); {% endhighlight %}

pebble-api-dotnet

PCL C# Library - Available on Github

Install

git clone git@github.com:nothingmn/pebble-api-dotnet.git

Example

In your C# project, define your global API Key.

public static string APIKey = "APIKEY";

Launch your app on the watch, and make the API call...

Now, on the server, you can use your "userToken" from the client app, and send pins as follows:

var timeline = new Timeline(APIKey);
var result = await timeline.SendUserPin(userToken, new Pin()
{
    Id = System.Guid.NewGuid().ToString(),
    Layout = new GenericLayout()
    {
        Title = "Generic Layout",
        Type = LayoutTypes.genericPin,
        SmallIcon = Icons.Notification.Flag
    },
});

See more examples on the GitHub repo.