Created
August 2, 2015 16:21
-
-
Save r7kamura/8103a08a5a064ed1d551 to your computer and use it in GitHub Desktop.
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
var AWS = require('aws-sdk'); | |
var Client = require('amazon-api-gateway-client').Client; | |
var RequestLogger = require('stackable-fetcher').RequestLogger; | |
var ResponseLogger = require('stackable-fetcher').ResponseLogger; | |
var client = new Client({ | |
accessKeyId: AWS.config.credentials.accessKeyId, | |
region: 'us-east-1', | |
secretAccessKey: AWS.config.credentials.secretAccessKey, | |
}).use(RequestLogger).use(ResponseLogger); | |
// これ叩くと全部消せてお得 | |
// client.listRestapis().then(function (restapis) { | |
// restapis.forEach(function (restapi) { | |
// client.deleteRestapi({ restapiId: restapi.source.id }); | |
// }); | |
// }); | |
client.createRestapi({ | |
name: 'test' | |
}).then(function (restapi) { | |
return client.deleteModel({ | |
modelName: 'Empty', | |
restapiId: restapi.source.id | |
}).then(function () { | |
return restapi; | |
}); | |
}).then(function (restapi) { | |
return client.deleteModel({ | |
modelName: 'Error', | |
restapiId: restapi.source.id | |
}).then(function () { | |
return restapi; | |
}); | |
}).then(function (restapi) { | |
return client.createResources({ | |
paths: ['/articles', '/recipes'], | |
restapiId: restapi.source.id | |
}).then(function () { | |
return restapi; | |
}); | |
}).then(function (restapi) { | |
return Promise.all( | |
[ | |
{ | |
httpMethod: 'GET', | |
path: '/articles' | |
}, | |
{ | |
httpMethod: 'GET', | |
path: '/recipes' | |
} | |
].map(function (endpoint) { | |
return client.findResourceByPath({ | |
path: endpoint.path, | |
restapiId: restapi.source.id | |
}).then(function (resource) { | |
return client.putMethod({ | |
httpMethod: endpoint.httpMethod, | |
resourceId: resource.source.id, | |
restapiId: restapi.source.id | |
}).then(function () { | |
return resource; | |
}); | |
}).then(function (resource) { | |
return client.putIntegration({ | |
httpMethod: endpoint.httpMethod, | |
integrationHttpMethod: 'GET', | |
resourceId: resource.source.id, | |
restapiId: restapi.source.id, | |
type: 'HTTP', | |
uri: 'https://api.github.com/users/r7kamura' | |
}).then(function (response) { | |
console.log(response); | |
}); | |
}); | |
}) | |
); | |
}).catch(function (error) { | |
console.log(error); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
実行するとこうなる