Git Product home page Git Product logo

skroutz.js's Introduction

skroutz.js

An npm module for using the skroutz.gr API with nodeJS

Installation

npm install skroutz

Quick start

Once you have an Identifier and a Secret you are ready to create a client.

var Client = require('skroutz');

var client = new Client({
	'client_id': 'Identifier',
	'client_secret': 'Secret'
});

After that, using the client to access the API is as simple as passing the methods you want and calling fetch().

client.Shop(40).fetch(function (err, response) {
 if(err){throw err;}
	console.log(response);
});

client.Category(40).skus().params({
	q: "samsung galaxy s8"
}).fetch(function (err, response) {
	console.log(response);
});

Available resources

client.Autocomplete()
client.Category()
client.Flag()
client.Manufacturer()
client.Product()
client.Search()
client.Shop()
client.Sku()

Usage

  • Accessing a specific API route is very simple. The URL is translated from all the method calls on the client object. For example if you want to access GET /categories/root you simply use js client.Category().root(). The fetch method must be called with a callback function argument in the end of the API call like this:
 .fetch(function(err, respond){ }); 

The final query will look like this:

client.Category().root().fetch(function(err, response){
//Check for errors and use the data from the api
});
  • Accessing routes that use dynamic URIs like GET /categories/:id/parent is as simple as using js client.Category(id).parent() and then fetching.
  • Accessing routes with parameters at the end like: GET http://api.skroutz.gr/categories/40/skus?manufacturer_ids[]=28&manufacturer_ids[]=2 will require the use of the method js .params({manufacturer_ids[]: 28, manufacturer_ids[]: 2}) like this:
client.Category(40).skus().params(({manufacturer_ids[]: 28, manufacturer_ids[]: 2})

and then fetching.

Conditional Requests

Most responses return Last-Modified and ETag headers. You can use the values of these headers to make subsequent requests to those resources. This headers are accessed by using js response.cache[`etag`] and js response.cache[`last-modified`]. You can only use one of them for every request by using either the methodjs.cacheEtag("the etag string") or js .cacheModified("Current date") before the fetch method. If no new data is available this small json will be present on the response: js { cached: true }

skroutz.js's People

Contributors

itsundefined avatar

Watchers

James Cloos 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.