-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
2,496 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"plugins": ["transform-object-rest-spread", "transform-object-assign"], | ||
"presets": [ | ||
[ | ||
"env", | ||
{ | ||
"targets": { | ||
"node": 6 | ||
} | ||
} | ||
] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Typescript v1 declaration files | ||
typings/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2017 tumblbug | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,54 @@ | ||
# gatsby-source-asknicely | ||
Gatsby source plugin for loading responses from AskNicely | ||
> Loads testimonials from AskNicely into Gatsby.js | ||
## Installation | ||
|
||
```bash | ||
npm install gatsby-source-asknicely | ||
``` | ||
|
||
## Usage | ||
|
||
To use this source you need to supply an AskNicely API key and your AskNicely subdomain. You can create an API key by logging into AskNicely and going to `Cog > API`. You can see your subdomain by logging into your AskNicely backend and checking the URL, e.g. `mycompany.asknicely.com`. | ||
|
||
Next, edit `gatsby-config.js` to use the plugin: | ||
```javascript | ||
{ | ||
... | ||
plugins: [ | ||
... | ||
{ | ||
resolve: 'gatsby-source-asknicely', | ||
options: { | ||
subdomain: 'mycompany', | ||
apiKey: 'abc-123', | ||
// optional | ||
queryParams: { | ||
// See API docs | ||
// NB: camelCased! | ||
} | ||
}, | ||
}, | ||
] | ||
} | ||
``` | ||
|
||
By default, `gatsby-source-asknicely` will only retrieve testimonials that are published. To change this behavior, you can also supply an optional `queryParams` parameter inside of `options`. Possible query parameters are detailed in [AskNicely's API Documentation](https://timelyapp.asknice.ly/help/responses), **but camelCased**! (ie, `pagesize` = `pageSize`, `since_time` = `sinceTime`) | ||
|
||
## Querying | ||
|
||
You can query the nodes created by the plugin as follows: | ||
```graphql | ||
{ | ||
allAskNicelyTestimonial { | ||
edges { | ||
node { | ||
... | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Thanks | ||
Based on [@tumblbug's](https://github.com/tumblbug) [gatsby-source-workable](https://github.com/tumblbug/gatsby-source-workable) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
'use strict'; | ||
|
||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
|
||
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } | ||
|
||
const crypto = require('crypto'); | ||
const axios = require('axios'); | ||
// const unescape = require('lodash.unescape'); | ||
|
||
exports.sourceNodes = (() => { | ||
var _ref = _asyncToGenerator(function* ({ boundActionCreators: { createNode } }, { | ||
subdomain, | ||
apiKey, | ||
queryParams = { | ||
filter: 'published', | ||
sinceTime: 0, | ||
sort: 'desc', | ||
pageSize: 50, | ||
pageNumber: 1 | ||
} | ||
}) { | ||
const filter = queryParams.filter, | ||
sinceTime = queryParams.sinceTime, | ||
sort = queryParams.sort, | ||
pageSize = queryParams.pageSize, | ||
pageNumber = queryParams.pageNumber; | ||
|
||
const axiosClient = axios.create({ | ||
baseURL: `https://${subdomain}.asknice.ly/api/v1/responses/` | ||
}); | ||
|
||
// Get list of all testimonials | ||
|
||
var _ref2 = yield axiosClient.get(`/${sort}/${pageSize}/${pageNumber}/${sinceTime}/json/${filter}`, { params: { 'X-apikey': apiKey } }); | ||
|
||
const data = _ref2.data.data; | ||
|
||
// Create nodes for testimonials | ||
|
||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
|
||
try { | ||
for (var _iterator = data[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
const testimonial = _step.value; | ||
|
||
const jsonString = JSON.stringify(testimonial); | ||
const gatsbyNode = _extends({}, testimonial, { | ||
id: testimonial.response_id, | ||
comment: unescape(testimonial.comment), | ||
children: [], | ||
parent: '__SOURCE__', | ||
internal: { | ||
type: 'AskNicelyTestimonial', | ||
content: jsonString, | ||
contentDigest: crypto.createHash('md5').update(jsonString).digest('hex') | ||
} | ||
}); | ||
// Insert data into gatsby | ||
createNode(gatsbyNode); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
}); | ||
|
||
return function (_x, _x2) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
})(); |
Oops, something went wrong.