├── .gitignore ├── README.md ├── lib └── siteleaf.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **ALPHA: This is a work in progress node library for the Siteleaf v2 API.** 2 | 3 | # About Siteleaf 4 | 5 | Siteleaf is a smart, lightweight platform for creating and maintaining websites. We believe that content management shouldn’t be hard. That you should be able to host your website anywhere you want. That websites should be able to outlive their CMS. That our tools should be simplified, not dumbed down. 6 | 7 | # Installation 8 | 9 | ``` 10 | npm install siteleaf 11 | ``` 12 | 13 | # Usage 14 | 15 | ```js 16 | var Siteleaf = require('siteleaf') 17 | 18 | var client = new Siteleaf({ 19 | apiKey: "YOUR SITELEAF API KEY HERE", 20 | apiSecret: "YOUR SITELEAF API SECRET HERE" 21 | }); 22 | ``` 23 | 24 | (Access your API keys from your [Siteleaf account page](https://manage.siteleaf.com/account)) 25 | 26 | All requests are made using the [`request-promise`](https://www.npmjs.com/package/request-promise) package, therefore **all requests return a Promise with the response as the first argument.** 27 | 28 | ## request(path, params) 29 | 30 | A generic method for making Siteleaf API requests: 31 | 32 | GET requests: 33 | 34 | ```js 35 | client.request(`sites/${config.site_id}/pages`, { 36 | qs: { per_page: 50 } 37 | }).then(function (pages) { 38 | console.log(pages); 39 | }); 40 | ``` 41 | 42 | POST/PUT requests: 43 | 44 | ```js 45 | client.request(`sites/${config.site_id}/pages`, { 46 | method: 'POST', 47 | body: { 48 | body: "Hello world", 49 | title: "Example", 50 | path: "example", 51 | metadata: { 52 | colors: ["Red", "Green", "Blue"] 53 | } 54 | } 55 | }).then(function (page) { 56 | console.log("Created page with slug: %s", page.slug); 57 | }); 58 | ``` 59 | 60 | DELETE requests: 61 | 62 | ```js 63 | client.request(`pages/${page.id}`, { method: 'DELETE' }); 64 | ``` 65 | -------------------------------------------------------------------------------- /lib/siteleaf.js: -------------------------------------------------------------------------------- 1 | var rp = require("request-promise"); 2 | var merge = require("merge"); 3 | var request; 4 | 5 | function Siteleaf(options) { 6 | this.options = options || {}; 7 | this.options = merge({ 8 | apiKey: process.env['SITELEAF_APIKEY'], 9 | apiSecret: process.env['SITELEAF_APISECRET'] 10 | }, this.options); 11 | 12 | request = rp.defaults({ 13 | baseUrl: "https://api.siteleaf.com/v2/", 14 | auth: { 15 | user: this.options.apiKey, 16 | pass: this.options.apiSecret 17 | }, 18 | headers: { 19 | 'Content-Type': 'application/json', 20 | 'User-Agent': 'Siteleaf-Node/0.1.0' 21 | }, 22 | json: true 23 | }); 24 | }; 25 | 26 | Siteleaf.prototype.request = function(uri, options){ 27 | options = options || {}; 28 | options = merge(options, { uri: uri }); 29 | var self = this; 30 | 31 | return request(options).catch(function(err){ 32 | self.onerror(err) 33 | }); 34 | }; 35 | 36 | Siteleaf.prototype.onerror = function(err) { 37 | console.error(err.response.body); 38 | }; 39 | 40 | module.exports = Siteleaf; 41 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "siteleaf", 3 | "description": "Siteleaf v2 API library", 4 | "version": "0.2.0", 5 | "author": { 6 | "name": "Siteleaf" 7 | }, 8 | "maintainers": [ 9 | { 10 | "name": "Siteleaf", 11 | "email": "support@siteleaf.com" 12 | } 13 | ], 14 | "repository": { 15 | "type": "git", 16 | "url": "git+ssh://git@github.com/siteleaf/siteleaf-node.git" 17 | }, 18 | "main": "./lib/siteleaf", 19 | "license": "MIT", 20 | "keywords": [ 21 | "api", 22 | "siteleaf", 23 | "cms" 24 | ], 25 | "bugs": { 26 | "url": "https://github.com/siteleaf/siteleaf-node/issues" 27 | }, 28 | "homepage": "https://github.com/siteleaf/siteleaf-node#readme", 29 | "directories": {}, 30 | "dependencies": { 31 | "bluebird": "^2.10.2", 32 | "merge": "^1.2.0", 33 | "request-promise": "^1.0.1" 34 | } 35 | } 36 | --------------------------------------------------------------------------------