Skip to content
This repository has been archived by the owner on Oct 20, 2020. It is now read-only.

Commit

Permalink
Merge release-v0.1.1 into master
Browse files Browse the repository at this point in the history
  • Loading branch information
johnboxall authored Nov 3, 2017
2 parents e0d0811 + c15e91d commit a1ed443
Show file tree
Hide file tree
Showing 266 changed files with 483 additions and 1,271 deletions.
7 changes: 6 additions & 1 deletion .jsdocrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@
"destination": "docs",
"readme": "README.md"
},
"plugins": ["plugins/markdown"]
"plugins": ["plugins/markdown"],
"templates": {
"default": {
"includeDate": false
}
}
}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## v0.1.1 (November 3, 2017)
- Authentication update [#4](https://github.com/mobify/hybris-api-js-client/pull/4)
- Allowed the client to accept access token, and several other options as parameters
- Moved requestAccessToken and clearAccessToken to `/test/utils.js`

## v0.1.0 (November 2, 2017)
- Added tests for most of the endpoints [#1](https://github.com/mobify/hybris-api-js-client/pull/1)
- Renamed methods so they are more intuitive
Expand Down
45 changes: 19 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
/____/
```
[![NPM](https://nodei.co/npm/hybris-occ-client.png)](https://nodei.co/npm/hybris-occ-client/)
[![CircleCI](https://circleci.com/gh/mobify/hybris-occ-client/tree/develop.svg?style=svg)](https://circleci.com/gh/mobify/hybris-occ-client/tree/develop)

> A JavaScript Client library crafted for Hybris Commerce OCC API.
Expand All @@ -22,35 +23,23 @@ npm install hybris-occ-client --save

## Usage

### Single Instance
Example: fetch supported titles from Hybris OCC API
### Example: create your hybris client instance

```javascript
import * as cilent from 'hybris-occ-client'
import * as hybris from 'hybris-occ-client'

const config = {
baseSite: "apparel-uk",
baseUrl: "https://<Your Hybris Instance>/rest/v2",
authorizationUrl: "https://<Your Hybris Instance>/authorizationserver/oauth/token"
oauth: {
client_id: 'client-side',
grant_type: 'client_credentials',
client_secret: 'secret'
}
basePath: "https://api-example.hybris.com/rest/v2/apparel-uk",
defaultHeaders: {},
timeout: 60000,
cache: true,
enableCookies: false
access_token: your_OAuth_access_token
}

// This client instance will be the default instance
client.ApiClient.instance = new client.ApiClient(
`${config.baseUrl}/${config.baseSite}`,
config.authorizationUrl,
config.oauth
)

const titleApi = new client.TitlesApi()

titleApi.getTitles()
.then((res) => console.log(titles))

// Override the default instance with your configuration
hybris.ApiClient.instance = new hybris.ApiClient(config)
const client = hybris.ApiClient.instance
```

## API documentation
Expand All @@ -64,9 +53,13 @@ Because Hybris OCC is not public available, you need to have a running instance
Example:
```json
{
"baseSite": "apparel-uk",
"baseUrl": "https://<Your Hybris Instance>/rest/v2",
"authorizationUrl": "https://<Your Hybris Instance>/authorizationserver/oauth/token"
"basePath": "https://<Your Hybris Instance>/rest/v2/apparel-uk",
"OAuth": {
"authorizationUrl": "https://<Your Hybris Instance>/authorizationserver/oauth/token",
"client_id": "mobile_android",
"client_secret": "secret",
"grant_type": "client_credentials"
}
}
```

Expand Down
76 changes: 27 additions & 49 deletions docs/ApiClient.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ <h1 class="page-title">Source: ApiClient.js</h1>
* @version v2
*/

const defaultConfig = {
basePath: 'http://api-example.hybris.com/rest/v2/DefaultParameterValue',
defaultHeaders: {},
timeout: 60000,
cache: true,
enableCookies: false
}

/**
* Manages low level client-server communications, parameter marshalling, etc. There should not be any need for an
* application to use this class directly - the *Api and model classes provide the public API for the service. The
Expand All @@ -59,76 +67,62 @@ <h1 class="page-title">Source: ApiClient.js</h1>
* @class
*/
export default class ApiClient {
constructor(
basePath = 'http://api-example.hybris.com/rest/v2/DefaultParameterValue',
authorizationUrl = 'http://api-example.hybris.com/rest/authorizationserver/authorize',
oauth = {
client_id: 'client-side',
grant_type: 'client_credentials',
client_secret: 'secret'
}
) {
constructor(config = defaultConfig) {
const {
basePath,
defaultHeaders,
timeout,
cache,
enableCookies,
accessToken
} = Object.assign({}, defaultConfig, config)

/**
* The base URL against which to resolve every API call's (relative) path.
* @type {String}
* @default http://api-example.hybris.com/rest/v2/DefaultParameterValue/
*/
this.basePath = basePath.replace(/\/+$/, '')

/**
* The authorization URL that grant user with oauth2 access token
* @type {String}
* @default http://api-example.hybris.com/rest/authorizationserver/authorize
*/
this.authorizationUrl = authorizationUrl

/**
* The oauth2 information used to request access token
* @type {object}
* @default {
* client_id:'client-side',
* grant_type:'client_credentials',
* client_secret:'secret'
* }
*/
this.oauth = oauth

/**
* The authentication methods to be included for all API calls.
* @type {Array.&lt;String>}
*/
this.authentications = {
auth: {type: 'oauth2'}
auth: {
type: 'oauth2',
accessToken
}
}

/**
* The default HTTP headers to be included for all API calls.
* @type {Array.&lt;String>}
* @default {}
*/
this.defaultHeaders = {}
this.defaultHeaders = defaultHeaders

/**
* The default HTTP timeout for all API calls.
* @type {Number}
* @default 60000
*/
this.timeout = 60000
this.timeout = timeout

/**
* If set to false an additional timestamp parameter is added to all API GET calls to
* prevent browser caching
* @type {Boolean}
* @default true
*/
this.cache = true
this.cache = cache

/**
* If set to true, the client will save the cookies from each server
* response, and return them in the next request.
* @default false
*/
this.enableCookies = false
this.enableCookies = enableCookies

/*
* Used to save and return cookies in a node.js (non-browser) setting,
Expand Down Expand Up @@ -572,22 +566,6 @@ <h1 class="page-title">Source: ApiClient.js</h1>
}
}
}

requestAccessToken() {
return superagent.post(this.authorizationUrl)
.set('Content-Type', 'application/x-www-form-urlencoded')
.send(this.oauth)
.then((res) => {
this.authentications.auth.accessToken = res.body.access_token
})
.catch((err) => {
throw new Error(err)
})
}

clearAccessToken() {
this.authentications.auth.accessToken = null
}
}

/**
Expand All @@ -611,7 +589,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-ap
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Nov 02 2017 11:37:57 GMT-0700 (PDT)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/api_CardtypesApi.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-ap
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Nov 02 2017 11:37:57 GMT-0700 (PDT)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/api_CatalogsApi.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-ap
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Nov 02 2017 11:37:57 GMT-0700 (PDT)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/api_CurrenciesApi.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-ap
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Nov 02 2017 11:37:57 GMT-0700 (PDT)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/api_CustomergroupsApi.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-ap
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Nov 02 2017 11:37:57 GMT-0700 (PDT)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/api_DeliverycountriesApi.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-ap
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Nov 02 2017 11:37:57 GMT-0700 (PDT)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/api_ExportApi.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-ap
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Nov 02 2017 11:37:57 GMT-0700 (PDT)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/api_FeedsApi.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-ap
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Nov 02 2017 11:37:57 GMT-0700 (PDT)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/api_ForgottenpasswordtokensApi.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-ap
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Nov 02 2017 11:37:57 GMT-0700 (PDT)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/api_LanguagesApi.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-ap
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Nov 02 2017 11:37:57 GMT-0700 (PDT)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/api_OrdersApi.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-ap
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Nov 02 2017 11:37:57 GMT-0700 (PDT)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/api_ProductsApi.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-ap
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Nov 02 2017 11:37:57 GMT-0700 (PDT)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/api_PromotionsApi.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-ap
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Nov 02 2017 11:37:57 GMT-0700 (PDT)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/api_StoresApi.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-ap
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Nov 02 2017 11:37:57 GMT-0700 (PDT)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/api_TitlesApi.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-ap
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Nov 02 2017 11:37:57 GMT-0700 (PDT)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/api_UsersApi.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -4484,7 +4484,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-ap
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Nov 02 2017 11:37:57 GMT-0700 (PDT)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/api_VouchersApi.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-ap
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Nov 02 2017 11:37:57 GMT-0700 (PDT)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
</footer>

<script> prettyPrint(); </script>
Expand Down
Loading

0 comments on commit a1ed443

Please sign in to comment.