Giter Club home page Giter Club logo

hypchat's Introduction

HypChat

A Python package for HipChat's v2 JSON REST API. It's based on v2's navigability and self-declaration.

Installation

HypChat can either be installed from PyPI: :

pip install hypchat

Or from source: :

python setup.py install

Concepts

There are two basic types in HypChat: Linker and RestObject. They are not meant to be instantiated directly but instead created as references from other objects.

Linker

A simple callable that represents an unfollowed reference.

l.url

The URL this object points to

l()

Calling a Linker will perform the request and return a RestObject

RestObject

A subclass of dict, contains additional functionality for links and actions.

As part of the v2 API, all objects have a links property with references to other objects. This is used to create Linker objects as attributes.

For example, all objects have a link called self. This may be referenced as: :

obj.self

And the request performed by calling it: :

obj.self()

If Title Expansion is desired, just past a list of things to be expanded as the expand keyword argument.

Other Actions

Many of the v2 types define additional types, eg Rooms have methods for messaging, setting the topic, getting the history, and inviting users to the room. These are implemented as methods of subclasses. The complete listing is in the Type List.

Timezone Handling

HypChat uses aware datetime objects throughout by the dateutil module. However, the HipChat API universally uses UTC.

For methods that take a datetime, if a naive object is given, it will be assumed to be in UTC. If this is not what you mean, dateutil.tz has a wonderful selection of timezones available.

Usage

First, create a HypChat object with the token

hc = HypChat("mytoken")

If you use Hipchat Server

hc = HypChat("mytoken", endpoint="https://hipchat.example.com")

There are several root links:

rooms = hc.rooms()
users = hc.users()
emots = hc.emoticons()
caps = hc.capabilities()

In addition, the HypChat object has methods for creating objects and directly referencing the basic types.

For example, you might do:

for room in (r for r in hipchat.rooms(expand='items') if r['last_active'] < datetime.datetime(2013, 12, 1)):
    room.owner.message("Your room is dead; maybe archive it")

Since room.owner is a User stub, not just a generic object. (The Room objects are not stubs, since the expand keyword is used).

Downloading history is as easy as:

list(HypChat(token).get_room(id).history(datetime.datetime.utcnow()).contents())

Note that this may eat up many requests for large rooms.

Navigation

Any time an object is referenced in a value (eg room['owner']), a stub of that object is created, and the full object may be found with .self(). Stubs contain the ID of the object, the name (if applicable), and any links that object has-including self. This can be avoided by using the expand keyword.

Collections-such as rooms, users, and emots above-all have an 'items' key containing their list of things. In addition, the .contents() method will generate all of the items, handling pagination. As usual, object

Console

If you call python -m hypchat, a interactive prompt (using IPython if available) will appear. The environment will contain hipchat, an instance of the HypChat object. The token is pulled from ~/.hypchat, /etc/hypchat, or the environment variable HIPCHAT_TOKEN.

Type List

See TYPES.rst

TODO List

  • API Links

hypchat's People

Contributors

astraluma avatar cu2 avatar cwood avatar dlamotte avatar froque avatar grissess avatar iaintshine avatar netmarkjp avatar philipsd6 avatar slavi avatar successamp avatar tanelpuhu avatar willdehaan 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.