Giter Club home page Giter Club logo

inbox.js's Introduction

inbox.js Build Status

NOTE: This SDK is currently not actively maintained, and may need some TLC. Please feel free to use it and send us a pull request if you fix anything or add a feature.

The Inbox Javascript SDK makes writing email clients for the web simple and enjoyable. The Javascript SDK is still a work in progress, and will be significantly expanded in the coming months to be a feature complete wrapper around the Inbox API.

Before using the Inbox JS SDK, make sure you've followed the instructions for installing the open-source Inbox server. We'll be making Inbox available as a hosted solution soon, but for now you'll need to run the Inbox Sync Engine on your local machine to develop your applications.

The Inbox Javascript SDK is open source and we welcome pull requests on Github! If you find problems with the Javascript SDK, please submit them as issues on the Inbox.js repository.

##Building Inbox.js

To begin with, it's necessary to set up a development environment:

git clone https://github.com/inboxapp/inbox.js.git

cd inbox.js

npm install

sudo npm install -g gulp karma-cli

Once a development environment is set up, you can build using the following command:

gulp build

Additionally, you can run tests with the following command:

gulp test

To run the examples web-server, begin by ensuring that you've set up inbox and have the API server up and running, then simply run the following command:

gulp serve --port=<OPTIONAL PORT> --host=<OPTIONAL HOST>

##Contributing

We'd love your help making Inbox better! Join the Google Group for project updates and feature discussion. We also hang out in ##inbox on irc.freenode.net, or you can email [email protected].

Please sign the Contributor License Agreement before submitting patches. (It's similar to other projects, like NodeJS.)

A more detailed guide on development, testing and contributing code is available in CONTRIBUTING.md.

##License

Please see the file LICENSE.md for the copyright licensing conditions attached to this codebase.

Angular Example


Download the Javascript SDK from Github—for this example, we'll be using the angular bindings included with the SDK.

To get started, we need to first create our global service for communicating with Inbox. There should typically be only one of these per application, and so in the AngularJS build, it’s registered as a configurable service. In VanillaJS, it’s possible to create as many of these as desired.

To begin with, lets configure the Inbox service to talk to the default API server hosted in the vagrant VM from port 5555. If you’re hosting the Inbox server from a specific host or port, you can change the base URL accordingly:

angular.module('inboxExampleApp', ['inbox', 'ngSanitize']).
  config(function($inboxProvider) {
    $inboxProvider.
      baseUrl('http://localhost:5555').
      appId('test');
  });

In VanillaJS, we can do this instead:

window.$inbox = InboxAPI({
  baseUrl: 'http://localhost:5555',
  appId: 'test',
  promise: window.Promise || YourFavouriteES6CompatiblePromiseConstructor
});

Now that we’re all set, we’re going to want to get a handle on the accounts we have access to. Currently, it’s not quite possible to only get the accounts we have access to, proper authentication is forthcoming. However, we can view all of the namespaces exposed from the service and use those.

To query for all namespaces accessible, you can do this:

function namespacesController($scope, $inbox) {
  function update() {
    $inbox.namespaces($scope.namespaces).
      then(null, function(error) {
        // We got an erroneous response! Alert the user!
        $scope.namespaces = [];
      });
  }
  $scope.updateNamespaces = update;
  $scope.namespaces = [];
  update();
}

It’s not necessary to pass an array to $inbox.namespaces(), however this will allow references to namespaces in the array to remain valid and be updated with new data, and this is generally a nice thing.

For Vanilla JS, this is very similar:

window.$inboxNamespacesList = window.$inboxNamespacesList || [];
// We previously created an InboxAPI object named window.$inbox
$inbox.namespaces($inboxNamespacesList).
  then(function(namespaces) {
    // We got our new namespaces! $inboxNamespaceList has already
    // been populated with these, but we can do something useful
    // with them anyways.
  }, function(error) {
    // We got an error, alert the user!
  });

Now that we’ve got our namespaces, likely the next thing we’ll want to look at is threads of messages. At the time of writing, it’s only possible to ask for threads of messages per namespace, rather than per-user.

In this example, lets say we want to get a list of threads where the last message was newer than last night. While it is often desirable to perform this filtering on the client-side, in this case we’ll use the web service’s own filtering capabilities to do this for us.

namespace.threads({
  lastMessageAfter: moment().subtract('days', 1).toDate()
}).
  then(function(threads) {
    // threads have arrived!
  }, function(error) {
    // An error occurred! Alert the user!
  });

So, we’ve got our set of threads, but we probably want to also look at the messages from those threads. There are a few options, but the simplest method for getting a collection of messages for a single thread is the following:

thread.getMessages({
  lastMessageAfter: moment().subtract('days', 1).toDate()
}).
  then(function(messages) {
    // messages have arrived!
  }, function(error) {
    // An error occurred! Alert the user!
  });

This looks very similar to the previous query for threads, because it essentially works the same way. Once we get a response, it gets transformed into a collection of objects which we can render to the client.

Using AngularJS, it’s very easy to make an attractive list of thread messages visible here. The markup might look something like this (using Bootstrap CSS, and angular-sanitize):

<div class="panel panel-default" ng-repeat="msg in threadMessages">
  <div class="panel-heading">
    <p>{{msg.subject}}</p>
  </div>
  <div class="panel-body" ng-bind-html="msg.body"></div>
</div>

We can expose as much or as little information associated with a message as we like here, but this example is aimed to showcase a very simple case.

With a little more work, we can add pagination, filtering messages, transforming the way participants are rendered, and many more fancy things, are quite possible.

While it’s currently not possible to create new drafts or send messages, and certain querying faculties are not yet implemented, the JS SDK is evolving quickly and will shortly be able to perform these tasks. This document will be updated accordingly when that is the case.

inbox.js's People

Contributors

caitp avatar bengotow avatar khamidou avatar spang avatar shidhincr avatar

Stargazers

antihero avatar Cat  avatar  avatar Panupong avatar Joe Ross avatar Pradeep Rawat avatar noa avatar  avatar Adam Boulanger avatar Lucas avatar Abd ar-Rahman Hamidi avatar Chirag Chauhan avatar James Benner avatar Prem Rose avatar iamchiriru avatar Hernan (Yidi) Ke avatar Joseph McCarron avatar Pana avatar nswbmw avatar Huy Nguyen Quang avatar David Bautista avatar Nagarjun Palavalli avatar Amir Amazigh BOUBEKKI avatar askender avatar  avatar  avatar Yılmaz Uğurlu avatar  avatar Ali Halabyah avatar Aslam Tajwala avatar Barış Akpunar avatar Stan Chollet avatar rosco5 avatar  avatar Adam Nowak avatar Paul Wozniak avatar Tomas Ruzicka avatar Jeff Allen avatar Panayiotis Tzagkarakis avatar Amal Khezami avatar Mark Thomas avatar M Haidar Hanif avatar Connor Walsh avatar Sheva Xu avatar Isaac Sukin avatar Hideki Sasaki avatar HIRAKI Satoru avatar Marc Riera avatar Rick Armbrust avatar Edgar Wong Baxter Jr. avatar Jacek Mitręga avatar Reuben Cummings avatar Bertrand CHEVRIER avatar Jakob Hohlfeld avatar Christoph Hochstrasser avatar Manuel Vila avatar Robert Lum avatar Vaidik Kapoor avatar Mauricio Wolff avatar Ryan O'Shea avatar Been Kyung-yoon avatar Alfred Xing avatar Tom avatar Ross Masters avatar JR Saucedo avatar Charleno Pires avatar Paulo Henrique Lopes Prado avatar Yichen Wei avatar Sean Zhu avatar Bruno Melo avatar Swaroop Kishen avatar Andrew Gerst avatar Chris Kihneman avatar Thomas avatar Maksim Morozov avatar Cody Krieger avatar Mathieu Ripert avatar Gilad Foyer avatar Jason Kulatunga avatar James Miller avatar  avatar Biko Tushinde avatar Adam Timberlake avatar Jérôme Foray avatar Ya Zhuang avatar Stefan avatar Omer Katz avatar Austris avatar Barney Chen avatar Emil Nikov avatar EM avatar Tanmay Patel avatar Ismael Canal avatar Nick avatar Angelo Nania avatar Joey Baker avatar James Giang avatar  avatar Phillip Burch avatar Nicky Toh avatar

Watchers

Sam Stokes avatar Brian Lauer avatar  avatar Horia Dragomir avatar Barney Chen avatar Jennie avatar Jermops avatar Kartik Talwar avatar Ram avatar Howard Lin avatar James Cloos avatar Ethan Hartman avatar  avatar  avatar Blag avatar Colin Hom avatar Jeff Roberts avatar kavya avatar Danny Manesh avatar Ash Ryan Arnwine avatar Max Mautner avatar ajay-k avatar Amal Khezami avatar Prasanna Swaminathan avatar Jonny Hatch avatar Max Maclaren avatar Brett Gerry avatar Ethan Blackburn avatar nimbosa avatar René Cannaò avatar Bill avatar Meredith avatar Angelo Nania avatar Kevin Fayle avatar Zach Seaman avatar Terence Yang avatar Halla Moore avatar Nick Vyzas avatar  avatar Kate Brender avatar  avatar David Ting avatar Lou Kaileh avatar jackie luo avatar Saaharjit Singh avatar Bolaji Fatade avatar Breanne Boland avatar iamchiriru avatar thedzy avatar Teo Toplak avatar  avatar Gleb Polyakov avatar LRubin avatar Saif Khan avatar  avatar Brian Tian avatar Ramsay Grove avatar Charu Jaiswal  avatar Erikka avatar  avatar Kris avatar Adnan avatar

inbox.js's Issues

Add AngularJS build

AngularJS support was initially requested, and is being shipped shortly. It's fairly easy to implement, however there are a few things which are a little unfortunate which can't be addressed at this time.

Details in the PR.

TODO: provide means to set default headers

Cross-origin requests and authentication and CSRF strategies may require headers, and currently there is no way to hand specify these. It would be a good thing to add.

Caching strategies

So, something that you notice when trying to run the sample applications against gunks is, it takes quite a long time to fetch updates from the server for endpoints with a lot of data, like /n/<namespaceId>/threads.

So what we really need here is an option to store this stuff on the client-side, so that we don't need to do as much querying, and querying can happen sort of in the background, and ideally we should support multiple caching "back-ends", so for instance, the HTML5 File API, HTML5 Web Storage, Cordova plugins, IndexedDB, and so forth.

I haven't really come up with a design for making this properly "pluggable" like this, since IndexedDB in particular adds some complexity to this, but it would be worth putting some thought into this before implementing anything.

Authentication strategy

In particular this means ensuring that we can use withCredentials for cookie authentication, custom headers (also important for XSRF tokens), and similar.

I see this as being a relatively difficult operation to test without an end2end testing setup which does not currently exist, but ignoring that for now, it shouldn't be too bad to hack something together for this.

`InboxThread#getMessages()` -> `InboxThread#messages`

Currently, this is called getMessages() because it's undesirable to shadow the property messages, which in a thread is an array of base 36 message IDs.

I think it would be more elegant for InboxThread to automatically replace message IDs with InboxMessage objects, like a proper REST api fetching nested/related resources. Naturally this is partly blocked on #18, because for performance reasons we'll want to use a cached item first.

So, we should handle nested resources properly, and use a consistent naming convention for accessing them.

On the other hand, there are cases where it may be desirable to query from the server and bypass cached instances, so perhaps in those cases a name like getMessages() is appropriate.

Making this work in node.js

It seems like a node.js build of this library could be fairly easily produced. All that would be needed would be a pluggable cache implementation (or just no caching support) and an alternative implementation of the xmlhttprequest utility. It would be really good to have the same API work server side and client side.

Add test coverage reports

I have a project called karma-coveralls which should integrate well with this repo, and help fill in the blanks dug by my own laziness, will look at setting this up in a bit.

publishing to npm

I see the notice about this SDK no longer being actively managed--but why not ever publish this to npm?

TBD: License for client code

The package.json is already claiming that this is MIT licensed, but this is subject to change.

It's an inboxapp product in the end, so it should be up to some of you guys to decide how you want to license it.

My 2c: Google is pushing all of their new open-source efforts under Apache 2.0, as of earlier in the year. But MIT or BSD tend to be good for wide adoption on the web.

I think it will be at least a week before this is something which can be released publicly though.

TODO: Run linting/tests on CI server

Travis-CI is easy, so I'm just going to set that up, it can be changed over later if needed. Not too worried about testing multiple browsers yet, but that should be implemented later

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.