Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small tweaks to docs #77

Merged
merged 1 commit into from
Dec 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions doc/GETTING_STARTED.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ To initialize a client, you only need an API key which can be obtained on the [A

```js
const recurly = require('recurly')
// You should store your api key somewhere safe
// You should store your API key somewhere safe
// and not in plain text if possible
const myApiKey = '<myapikey>'
const client = new recurly.Client(myApiKey)
Expand Down Expand Up @@ -64,9 +64,9 @@ async function myFunc () {

### Creating Resources

For creating or updating resources, pass a json object to one of the create* or update* methods.
Keep in mind that the api accepts snake-cased keys but this library expects camel-cased keys.
We do the translation for you so this library can conform to js style standards.
For creating or updating resources, pass a plain object to one of the create* or update* methods.

> **Note**: Keep in mind that the API accepts snake-cased keys but this library expects camel-cased keys. We do the translation for you so this library can conform to js style standards.

```js

Expand All @@ -78,14 +78,14 @@ try {
}
const account = await client.createAccount(acctReq)
} catch (err) {
if (err && err instanceof recurly.errors.ValidationError) {
if (err instanceof recurly.errors.ValidationError) {
// If the request was not valid, you may want to tell your user
// why. You can find the invalid params and reasons in err.params
console.log('Failed validation', err.params)
console.log('Failed validation:', err.params)
} else {
// If we don't know what to do with the err, we should
// probably re-raise and let our web framework and logger handle it
console.log('Unknown Error: ', err)
console.log('Unknown Error:', err)
}
}
```
Expand Down Expand Up @@ -187,21 +187,21 @@ try {
if (err) {
if (err.getResponse()) {
const requstId = err.getResponse().requestId
console.log("Request Id useful for support: ", requestId)
console.log('Request Id useful for support:', requestId)
}

if (err instanceof recurly.errors.ValidationError) {
// If the request was not valid, you may want to tell your user
// why. You can find the invalid params and reasons in err.params
console.log('Failed validation', err.params)
// } else if (err instanceof recurly.errors.NotFoundError) {
// console.log('Failed validation', err.params)
console.log('Failed validation:', err.params)
} else if (err instanceof recurly.errors.NotFoundError) {
console.log('Subscription not found:', err)
} else if (err instanceof recurly.ApiError) {
console.log('generic api error', err)
console.log('generic API error:', err)
} else {
// If we don't know what to do with the err, we should
// probably re-raise and let our web framework and logger handle it
console.log('Unknown Error: ', err)
console.log('Unknown Error:', err)
}
}
}
Expand Down Expand Up @@ -241,7 +241,7 @@ try {
// You can also get the Response here
const response = err.getResponse()
} else {
console.log('Unknown Error: ', err)
console.log('Unknown Error:', err)
}
}
```
Expand Down Expand Up @@ -281,7 +281,7 @@ const xml = `

parseString(xml, function (err, result) {
const code = result.new_account_notification.account[0].account_code[0];
console.log("New account created with code: ", code);
console.log('New account created with code:', code);
})
```

Expand Down
31 changes: 16 additions & 15 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2086,7 +2086,7 @@ <h3>Creating a client</h3>
each <code>operation</code> that can be performed in the API as a method.</p>
<p>To initialize a client, you only need an API key which can be obtained on the <a href="https://app.recurly.com/go/integrations/api_keys">API Credentials Page</a>.</p>
<pre class='hljs'><span class="hljs-keyword">const</span> recurly = <span class="hljs-built_in">require</span>(<span class="hljs-string">'recurly'</span>)
<span class="hljs-comment">// You should store your api key somewhere safe</span>
<span class="hljs-comment">// You should store your API key somewhere safe</span>
<span class="hljs-comment">// and not in plain text if possible</span>
<span class="hljs-keyword">const</span> myApiKey = <span class="hljs-string">'&lt;myapikey&gt;'</span>
<span class="hljs-keyword">const</span> client = <span class="hljs-keyword">new</span> recurly.Client(myApiKey)</pre>
Expand All @@ -2106,9 +2106,10 @@ <h3>Operations</h3>
}
}</pre>
<h3>Creating Resources</h3>
<p>For creating or updating resources, pass a json object to one of the create<em> or update</em> methods.
Keep in mind that the api accepts snake-cased keys but this library expects camel-cased keys.
We do the translation for you so this library can conform to js style standards.</p>
<p>For creating or updating resources, pass a plain object to one of the create<em> or update</em> methods.</p>
<blockquote>
<p><strong>Note</strong>: Keep in mind that the API accepts snake-cased keys but this library expects camel-cased keys. We do the translation for you so this library can conform to js style standards.</p>
</blockquote>
<pre class='hljs'><span class="hljs-keyword">try</span> {
<span class="hljs-keyword">const</span> acctReq = {
<span class="hljs-attr">code</span>: <span class="hljs-string">'new-account-code'</span>,
Expand All @@ -2117,14 +2118,14 @@ <h3>Creating Resources</h3>
}
<span class="hljs-keyword">const</span> account = <span class="hljs-keyword">await</span> client.createAccount(acctReq)
} <span class="hljs-keyword">catch</span> (err) {
<span class="hljs-keyword">if</span> (err &amp;&amp; err <span class="hljs-keyword">instanceof</span> recurly.errors.ValidationError) {
<span class="hljs-keyword">if</span> (err <span class="hljs-keyword">instanceof</span> recurly.errors.ValidationError) {
<span class="hljs-comment">// If the request was not valid, you may want to tell your user</span>
<span class="hljs-comment">// why. You can find the invalid params and reasons in err.params</span>
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Failed validation'</span>, err.params)
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Failed validation:'</span>, err.params)
} <span class="hljs-keyword">else</span> {
<span class="hljs-comment">// If we don't know what to do with the err, we should</span>
<span class="hljs-comment">// probably re-raise and let our web framework and logger handle it</span>
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Unknown Error: '</span>, err)
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Unknown Error:'</span>, err)
}
}</pre>
<h3>Pagination</h3>
Expand Down Expand Up @@ -2202,21 +2203,21 @@ <h3>Error Handling</h3>
<span class="hljs-keyword">if</span> (err) {
<span class="hljs-keyword">if</span> (err.getResponse()) {
<span class="hljs-keyword">const</span> requstId = err.getResponse().requestId
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Request Id useful for support: "</span>, requestId)
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Request Id useful for support:'</span>, requestId)
}

<span class="hljs-keyword">if</span> (err <span class="hljs-keyword">instanceof</span> recurly.errors.ValidationError) {
<span class="hljs-comment">// If the request was not valid, you may want to tell your user</span>
<span class="hljs-comment">// why. You can find the invalid params and reasons in err.params</span>
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Failed validation'</span>, err.params)
<span class="hljs-comment">// } else if (err instanceof recurly.errors.NotFoundError) {</span>
<span class="hljs-comment">// console.log('Failed validation', err.params)</span>
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Failed validation:'</span>, err.params)
} <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (err <span class="hljs-keyword">instanceof</span> recurly.errors.NotFoundError) {
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Subscription not found:'</span>, err)
} <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (err <span class="hljs-keyword">instanceof</span> recurly.ApiError) {
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">'generic api error'</span>, err)
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">'generic API error:'</span>, err)
} <span class="hljs-keyword">else</span> {
<span class="hljs-comment">// If we don't know what to do with the err, we should</span>
<span class="hljs-comment">// probably re-raise and let our web framework and logger handle it</span>
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Unknown Error: '</span>, err)
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Unknown Error:'</span>, err)
}
}
}</pre>
Expand All @@ -2242,7 +2243,7 @@ <h3>HTTP Metadata</h3>
<span class="hljs-comment">// You can also get the Response here</span>
<span class="hljs-keyword">const</span> response = err.getResponse()
} <span class="hljs-keyword">else</span> {
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Unknown Error: '</span>, err)
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Unknown Error:'</span>, err)
}
}</pre>
<h3>Webhooks</h3>
Expand Down Expand Up @@ -2274,7 +2275,7 @@ <h3>Webhooks</h3>

parseString(xml, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">err, result</span>) </span>{
<span class="hljs-keyword">const</span> code = result.new_account_notification.account[<span class="hljs-number">0</span>].account_code[<span class="hljs-number">0</span>];
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">"New account created with code: "</span>, code);
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">'New account created with code:'</span>, code);
})</pre>
<p>You can do this without dependencies, but you'll need to heed warnings about security concerns.
Read more about the security implications of parsing untrusted XML in <a href="https://cheatsheetseries.owasp.org/cheatsheets/XML_Security_Cheat_Sheet.html">this OWASP cheatsheet</a>.</p>
Expand Down
41 changes: 30 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.