Giter Club home page Giter Club logo

pypebbleapi's Introduction

pypebbleapi

Build Status Documentation Status

Pebble Timeline APIs for python.

This is a library to ease the access to the Pebble Timeline and validate pins. It supports Python 2.7, 3.3 and 3.4.

Update

Starting from version 1.0.0, the API has changed. The Pin class has been removed. You should now supply a dict, which will be validated before sending.

Install

Just like you install any package:

$ pip install pypebbleapi

Usage

Here's an example:

from pypebbleapi import Timeline
import datetime

timeline = Timeline(
    api_key=my_api_key,  # Needed only if you are going to use shared pins
)

my_pin = dict(
    id='123',
    time=datetime.date.today().isoformat(),
    layout=dict(
        type="genericPin",
        title="This is a genericPin!",
        tinyIcon="system://images/NOTIFICATION_FLAG",
    )
)

# Send a shared pin
timeline.send_shared_pin(
    topics=['a_topic', 'another_topic'],  # List of the topics
    pin=my_pin,
)

# Send a user pin
timeline.send_user_pin(
    user_token='test-user-token',
    pin=my_pin,
)

It is possible that validation fails even if the pin is correct (it could happen if Pebble updates the pin specification). In this case you may want to skip the validation:

timeline.send_user_pin(
    user_token='test-user-token',
    pin=my_pin,
    skip_validation=True,
)

Error handling

The API raises errors in case the server is not available or if it returns error codes. You should always enclose calls in try/except:

try:
    timeline.send_shared_pin(...)
except Exception as e:
	print(e)

If the pin you provided is not valid, a DocumentError will be raised:

from pypebbleapi import DocumentError

bad_pin = {}  # Empty pin is not valid
try:
    timeline.send_shared_pin(['a_topic'], bad_pin)
except DocumentError as e:
    print(e)
    print(e.errors)  # e.errors contain a dictionary of the fields that failed the validation

pypebbleapi's People

Contributors

gregoiresage avatar youtux avatar

Watchers

 avatar  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.