-
Notifications
You must be signed in to change notification settings - Fork 757
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
Remove "curried" nested resources and manually specified urlParams #625
Changes from all commits
b8cbd25
d88a3e7
b3cfe88
aeabd82
7842939
e52219b
e5eccb8
71d5200
f650b77
d58bbf8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,31 @@ | ||
'use strict'; | ||
|
||
const utils = require('./utils'); | ||
const OPTIONAL_REGEX = /^optional!/; | ||
|
||
function getRequestOpts(self, requestArgs, spec, overrideData) { | ||
// Extract spec values with defaults. | ||
const commandPath = | ||
typeof spec.path == 'function' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we had no |
||
? spec.path | ||
: utils.makeURLInterpolator(spec.path || ''); | ||
const commandPath = utils.makeURLInterpolator(spec.path || ''); | ||
const requestMethod = (spec.method || 'GET').toUpperCase(); | ||
const urlParams = spec.urlParams || []; | ||
const encode = spec.encode || ((data) => data); | ||
const host = spec.host; | ||
const path = self.createResourcePathWithSymbols(spec.path); | ||
|
||
// Don't mutate args externally. | ||
const args = [].slice.call(requestArgs); | ||
|
||
// Generate and validate url params. | ||
const urlData = self.createUrlData(); | ||
for (let i = 0, l = urlParams.length; i < l; ++i) { | ||
var path; | ||
|
||
// Note that we shift the args array after every iteration so this just | ||
// grabs the "next" argument for use as a URL parameter. | ||
const arg = args[0]; | ||
|
||
let param = urlParams[i]; | ||
|
||
const isOptional = OPTIONAL_REGEX.test(param); | ||
param = param.replace(OPTIONAL_REGEX, ''); | ||
|
||
if (param == 'id' && typeof arg !== 'string') { | ||
path = self.createResourcePathWithSymbols(spec.path); | ||
const urlData = urlParams.reduce((urlData, param) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that we're on Node 6+, we can use "modern" features like |
||
const arg = args.shift(); | ||
if (typeof arg !== 'string') { | ||
throw new Error( | ||
`Stripe: "id" must be a string, but got: ${typeof arg} (on API request to \`${requestMethod} ${path}\`)` | ||
`Stripe: Argument "${param}" must be a string, but got: ${arg} (on API request to \`${requestMethod} ${path}\`)` | ||
); | ||
} | ||
|
||
if (!arg) { | ||
if (isOptional) { | ||
urlData[param] = ''; | ||
continue; | ||
} | ||
|
||
path = self.createResourcePathWithSymbols(spec.path); | ||
throw new Error( | ||
`Stripe: Argument "${ | ||
urlParams[i] | ||
}" required, but got: ${arg} (on API request to \`${requestMethod} ${path}\`)` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this error wasn't as good as the other, combined it. |
||
); | ||
} | ||
|
||
urlData[param] = args.shift(); | ||
} | ||
urlData[param] = arg; | ||
return urlData; | ||
}, {}); | ||
|
||
// Pull request data and options (headers, auth) from args. | ||
const dataFromArgs = utils.getDataFromArgs(args); | ||
|
@@ -62,7 +34,6 @@ function getRequestOpts(self, requestArgs, spec, overrideData) { | |
|
||
// Validate that there are no more args. | ||
if (args.length) { | ||
path = self.createResourcePathWithSymbols(spec.path); | ||
throw new Error( | ||
`Stripe: Unknown arguments (${args}). Did you mean to pass an options object? See https://github.com/stripe/stripe-node/wiki/Passing-Options. (on API request to ${requestMethod} \`${path}\`)` | ||
); | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we had no url params specified as optional anymore