Code Monkey home page Code Monkey logo

recline.backend.gdocs's Introduction

A simple javascript library that wraps the Google Docs JSON API. Part of the Recline suite of data libraries (but has no dependencies on core Recline).

Usage

Get data from the API:

recline.Backend.GDocs.fetch({
  url: 'https://docs.google.com/a/okfn.org/spreadsheet/ccc?key=0Aon3JiuouxLUdDlGV2lCakoydVh1U014cHRqcXpoWVE#gid=0'
})
  .done(function(result) {
    // structure of result is below
    console.log(result);
  });

Results

The result of fetch has a convenient structure of the following form:

result = {
  records: // array of Objects
  fields: // array of Field Objects as per http://www.dataprotocols.org/en/latest/json-table-schema.html
  metadata: {
    spreadsheetTitle: ...,
    worksheetTitle: ...,
    title: spreadsheetTitle +" :: "+ result.worksheetTitle
  }
}

You can also use GDocs parsing without depending on jQuery:

// json should be the JSON you get from the Google Docs JSON API
var out = recline.Backend.GDocs.parseData(json);

Config options

You may specify info about the Google Spreadsheet in several ways

// GDocs spreadsheet URL
{
  url: 'https://docs.google.com/spreadsheet/ccc?key=0Aon3JiuouxLUdGlQVDJnbjZRSU1tUUJWOUZXRG53VkE#gid=0'
}

// OR the key 
{
  url: '0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc'
}

// OR URL to API
{
  url: 'https://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values?alt=json'
}

In addition you can provide a worksheet index (starting at 1):

{
  url: ...
  worksheetIndex: 2
}

NB: we try to guess from #gid={worksheetIndex} and o/w default to 1. A problem with guessing from gid is that the API worksheet indexes follow the order of the worksheets as shown in the spreadsheet but #gid seems to follow creation order so the gid and worksheetIndex may not be the same if you have re-ordered spreadsheets

Dependencies

  • underscore
  • jQuery (optional) - only if you want ajax requests
  • underscore.deferred (optional) - only needed if no jQuery

One of the reasons for the different options is that it ensures you can use this library in the browser and in webworkers (where jQuery does not function).

recline.backend.gdocs's People

Contributors

andylolz avatar krishnapg avatar rufuspollock 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.