Coder Social home page Coder Social logo

riadhoq / js-parsely Goto Github PK

View Code? Open in Web Editor NEW

This project forked from emmettbutler/js-parsely

0.0 1.0 0.0 102 KB

Javascript bindings for the Parsely API

Home Page: http://parsely.com/api/api_ref.html

JavaScript 98.20% CSS 1.54% HTML 0.26%

js-parsely's Introduction

Parsely API Javascript Binding

This library provides a pure JavaScript interface for the Parsely API. The documentation on which this binding is based can be found here.

The library is lightweight at 8KB unminified and 4KB minified.

It is fully asynchronous and relies on no external libraries.

Getting the Code

git clone this repository

git clone https://github.com/emmett9001/js-parsely.git

Using js-parsely

To use the Parsely javascript binding on your website, include it in the head

<head>
    <script src="parsely.min.js"></script>
</head>

Any script included on the page after js-parsely will have access to the Parsely() constructor.

<script type="text/javascript">
    var parsely = new Parsely();
</script>

After creating parsely, you must authenticate with your public and secret keys. All of js-parsely's functions take a callback parameter - a function that will run with the result of the API call once the asynchronous request completes

parsely.authenticate("mysite.com", "039yqw78grya8w7eyba9874tb", function(success){
    if(success){
        console.log("Authenticated successfully");
    } else {
        console.log("oops...")
    }
});

Once you've created and authenticated the object, you can call methods on it to request API endpoints. A good starting point is analytics

parsely.analytics(function(res){
    console.log(res.data[0].title);
});

This call returns a list of the top posts on your site.

Options

There are a number of options accepted by the API endpoints. You can find the specific options for each call by either reading the code or reading the documentation. To set an option before making an API request, use the setOption() method.

parsely.clearOptions();
parsely.setOption('limit', 3);
parsely.analytics(function(res){
    console.log(res.data[1].title);
});

Always make sure to call clearOptions before setting new option values if you're making multiple requests and don't want the same options for each request.

To set a start or end date for your request, use a JavaScript Date object.

parsely.clearOptions();
parsely.setOption('pub_date_start', new Date("6/1/2013"));
parsely.setOption('pub_date_end', new Date('6/2/2013'));
parsely.analytics(function(res){
    var ret_date = new Date(res.data[0].pub_date);
    console.log(ret_date);
})

The pub_date_start, pub_date_end, start, and end parameters all accept js Date arguments.

Nesting

js-parsely API functions can be arbitrarily nested within each other's callbacks.

parsely.analytics(function(analytics_res){
    parsely.meta_detail(function(meta_res){
        console.log(meta_res.data[0].section);
    }, analytics_res.data[0], 'section');
});

Here, the one of the results from the analytics call is passed into the call to meta_detail - showing us the details for that particular section.

Recommendations

The related call accepts either a user id or a url. You can use it to get articles related by semantic content.

parsely.related(function(res){
    console.log(res.data[0].title);
}, 'my_uuid');

Testing

This library uses mocha and chai for testing. Running the tests is easy: just open tests.html in a browser.

License

Copyright (C) 2013 Emmett Butler, Parsely Inc.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

js-parsely's People

Contributors

drs1980 avatar emmettbutler avatar mortonfox avatar riadhoq avatar

Watchers

 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.