Giter VIP home page Giter VIP logo

paspartout.api.public.v2.js's Introduction

paspartout.api.public.v2.js 0.0.7

What is it?

Official JavaScript wrapper for the Paspartout.com public API.

Who should use it?

Developers or Paspartout site owners who want to create widgets, use public Paspartout data externally or extend behavior.

Usage

Installation

Include the file in your page:

<script src="paspartout.api.public.v2.js" type="text/javascript"></script>

Configuration

Before you perform any Paspartout related action define the site api id of the site you want to approach:

Paspartout.config.siteId = 'ppt-123456789';

The site api id can be found under 'settings' > 'Paspartout API'. Note that the length of the key can vary from site to site.

Load the Site

Paspartout.Api.Site.load({
  success: function(site) {
    ... your code ...
  },
  failure: function(error) {
    console.error(error);
  }
});

The object passed as the first argument in the success callback the site object including the following fields:

  • title (meta title)
  • description (meta description)
  • subdomain (e.g. subdomain.paspartout.com)
  • host
  • url
  • icon (the site icon in all available sizes: apple_touch_icon, favicon, original)
  • page (the homepage, including its children in case of a portfolio, lookbook, blog, news or shop page)
  • menu (array with pages and their basic fields: description, id, name, permaname, short_url, title, type, url)
  • footer (full Paspartout footer info)

Load a Page

Paspartout.Api.Page.load(page_id_or_permaname, {
  success: function(page) {
    ... your code ...
  },
  failure: function(error) {
    console.error(error);
  }
});

The object passed as the first argument in the success callback the page object including the following (possible) fields:

  • type
  • id
  • name
  • permaname (except for external page or a blog that is used externally)
  • url
  • target (only for external page or a blog that is used externally)
  • short_url (except for external page or a blog that is used externally)
  • created_at
  • updated_at
  • body (only project or product; about, sheet and post have their body in one or more blocks)
  • published_at
  • allow_comments (only for post)
  • number_of_comments (only for post)
  • categories (project, product and post)
  • keywords (project, product and post)
  • comments (only for post)
  • blocks (about, sheet and post)
  • children (portfolio, lookbook, blog, news and shop)
  • price (only for product)
  • big_shipment (only for product)
  • sold (only for product)
  • promotion_id (only for product)
  • thumb (project and product)
  • collections (only for product)
  • genders (only for product)
  • materials (only for product)
  • variations (only for product)
  • images (only for product)

The field sets vary for each page type.

Load Pages

Paspartout.Api.Page.all({
  success: function(pages) {
    ... your code ...
  },
  failure: function(error) {
    console.error(error);
  }
});

The first argument in the success callback is an array with all active pages.

Load Comments

Paspartout.Api.Comment.all({
  success: function(comments) {
    ... your code ...
  },
  failure: function(error) {
    console.error(error);
  }
});

The first argument in the success callback is an array with approved comments.

Optionally you can provide the 'pageId' option to scope comments to a given page:

Paspartout.Api.Comment.all({
  pageId: page_id_or_permaname,
  
  success: function(comments) {
    ... your code ...
  },
  failure: function(error) {
    console.error(error);
  }
});

By default a basic page object is included for each comment.

Load Images

Paspartout.Api.Image.all({
  success: function(comments) {
    ... your code ...
  },
  failure: function(error) {
    console.error(error);
  }
});

The first argument in the success callback is an array with images.

Like comments you can optionally provide the 'pageId' option to scope images to a given page:

Paspartout.Api.Image.all({
  pageId: page_id_or_permaname,
  
  success: function(comments) {
    ... your code ...
  },
  failure: function(error) {
    console.error(error);
  }
});

Include or exclude

When loading a portfolio page for example its children (the projects) are included by default. You can prevent that by passing the following option:

Paspartout.Api.Page.load(page_id_or_permaname, {
  include: {
    children: false
  },
  
  success...
});

When loading a blog post on the other hand, comments are not included. To include them:

Paspartout.Api.Page.load(page_id_or_permaname, {
  include: {
    comments: true
  },
  
  success...
});

This also works when loading a blog page. The comments for every post will then be included.

Other options

Other options are:

  • order: (the position order in which the records are loaded; options per record type are listed below)
    • project: name, position, created_at, updated_at or random
    • post: name, created_at, updated_at, published_at or random
    • product: name, position, price, created_at, updated_at or random
    • comment: name, created_at, updated_at or random
    • image: title, position, color, created_at, updated_at or random
  • way: (the direction of the order; only asc and desc are possible)
  • per_page: (the amount of records that are loaded; defaults to 30 if no value found in the paspartout settings)
  • page: (the page in pagination; for example if you have 40 projects and 30 per_page, project 32 will be on page 2)

Data you load will be cached. The second time you request the same url you will get the cached data returned. To get a fresh version of the url pass this option:

  • cache: false (false will prevent caching and force the data to be reloaded)

Important

The Paspartout API is currently in beta. As the API evolves this library will be updated as well.

This library is framework agnostic. If any problems arise, please let me know.

Testing

The included specs test the basic functionality. Tests are performed against a Paspartout Biz test site (http://gmc.paspartout.com/).

Contributing

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
  • Fork the project
  • Start a feature/bugfix branch
  • Commit and push until you are happy with your contribution
  • Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.

Copyright

Copyright (c) 2011 Wout Fierens. See LICENSE.txt for further details.

paspartout.api.public.v2.js's People

Stargazers

Fabien Franzen avatar

Watchers

Wout avatar James Cloos avatar Zwartopwit 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.