Skip to content

Commit

Permalink
docs(examples): update examples to contain environment
Browse files Browse the repository at this point in the history
  • Loading branch information
Benedikt Rötsch authored and axe312ger committed Feb 27, 2018
1 parent c97b74f commit ae6ef78
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 35 deletions.
78 changes: 53 additions & 25 deletions lib/create-environment-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ export default function createEnvironmentApi ({
* })
*
* client.getSpace('<space_id>')
* .then((space) => space.getContentType('<content_type_id>'))
* .then((space) => space.getEnvironment('<environment-id>'))
* .then((environment) => environment.getContentType('<content_type_id>'))
* .then((contentType) => console.log(contentType))
* .catch(console.error)
*/
Expand All @@ -153,7 +154,8 @@ export default function createEnvironmentApi ({
* })
*
* client.getSpace('<space_id>')
* .then((space) => space.getEditorInterfaceForContentType('<content_type_id>'))
* .then((space) => space.getEnvironment('<environment-id>'))
* .then((environment) => environment.getEditorInterfaceForContentType('<content_type_id>'))
* .then((EditorInterface) => console.log(EditorInterface))
* .catch(console.error)
*/
Expand All @@ -175,7 +177,8 @@ export default function createEnvironmentApi ({
* })
*
* client.getSpace('<space_id>')
* .then((space) => space.getContentTypes())
* .then((space) => space.getEnvironment('<environment-id>'))
* .then((environment) => environment.getContentTypes())
* .then((response) => console.log(response.items))
* .catch(console.error)
*/
Expand All @@ -198,7 +201,8 @@ export default function createEnvironmentApi ({
* })
*
* client.getSpace('<space_id>')
* .then((space) => space.createContentType({
* .then((space) => space.getEnvironment('<environment-id>'))
* .then((environment) => environment.createContentType({
* name: 'Blog Post',
* fields: [
* {
Expand Down Expand Up @@ -233,7 +237,8 @@ export default function createEnvironmentApi ({
* })
*
* client.getSpace('<space_id>')
* .then((space) => space.createContentTypeWithId('<custom-id>', {
* .then((space) => space.getEnvironment('<environment-id>'))
* .then((environment) => environment.createContentTypeWithId('<custom-id>', {
* name: 'Blog Post',
* fields: [
* {
Expand Down Expand Up @@ -269,7 +274,8 @@ export default function createEnvironmentApi ({
* })
*
* client.getSpace('<space_id>')
* .then((space) => space.getEntry('<entry-id>'))
* .then((space) => space.getEnvironment('<environment-id>'))
* .then((environment) => environment.getEntry('<entry-id>'))
* .then((entry) => console.log(entry))
* .catch(console.error)
*/
Expand All @@ -294,7 +300,8 @@ export default function createEnvironmentApi ({
* })
*
* client.getSpace('<space_id>')
* .then((space) => space.getEntries({'content_type': 'foo'})) // you can add more queries as 'key': 'value'
* .then((space) => space.getEnvironment('<environment-id>'))
* .then((environment) => environment.getEntries({'content_type': 'foo'})) // you can add more queries as 'key': 'value'
* .then((response) => console.log(response.items))
* .catch(console.error)
*/
Expand All @@ -319,7 +326,8 @@ export default function createEnvironmentApi ({
* })
*
* client.getSpace('<space_id>')
* .then((space) => space.createEntry('<content_type_id>', {
* .then((space) => space.getEnvironment('<environment-id>'))
* .then((environment) => environment.createEntry('<content_type_id>', {
* fields: {
* title: {
* 'en-US': 'Entry title'
Expand Down Expand Up @@ -355,7 +363,8 @@ export default function createEnvironmentApi ({
*
* // Create entry
* client.getSpace('<space_id>')
* .then((space) => space.createEntryWithId('<content_type_id>', '<entry_id>', {
* .then((space) => space.getEnvironment('<environment-id>'))
* .then((environment) => environment.createEntryWithId('<content_type_id>', '<entry_id>', {
* fields: {
* title: {
* 'en-US': 'Entry title'
Expand Down Expand Up @@ -390,7 +399,8 @@ export default function createEnvironmentApi ({
* })
*
* client.getSpace('<space_id>')
* .then((space) => space.getAsset('<asset_id>'))
* .then((space) => space.getEnvironment('<environment-id>'))
* .then((environment) => environment.getAsset('<asset_id>'))
* .then((asset) => console.log(asset))
* .catch(console.error)
*/
Expand All @@ -415,7 +425,8 @@ export default function createEnvironmentApi ({
* })
*
* client.getSpace('<space_id>')
* .then((space) => space.getAssets())
* .then((space) => space.getEnvironment('<environment-id>'))
* .then((environment) => environment.getAssets())
* .then((response) => console.log(response.items))
* .catch(console.error)
*/
Expand All @@ -438,7 +449,8 @@ export default function createEnvironmentApi ({
*
* // Create asset
* client.getSpace('<space_id>')
* .then((space) => space.createAsset({
* .then((space) => space.getEnvironment('<environment-id>'))
* .then((environment) => environment.createAsset({
* fields: {
* title: {
* 'en-US': 'Playsam Streamliner'
Expand Down Expand Up @@ -475,7 +487,8 @@ export default function createEnvironmentApi ({
*
* // Create asset
* client.getSpace('<space_id>')
* .then((space) => space.createAssetWithId('<asset_id>', {
* .then((space) => space.getEnvironment('<environment-id>'))
* .then((environment) => environment.createAssetWithId('<asset_id>', {
* title: {
* 'en-US': 'Playsam Streamliner'
* },
Expand Down Expand Up @@ -507,8 +520,10 @@ export default function createEnvironmentApi ({
* const client = contentful.createClient({
* accessToken: '<content_management_api_key>'
* })
*
* client.getSpace('<space_id>')
* .then((space) => space.createAssetFromFiles({
* .then((space) => space.getEnvironment('<environment-id>'))
* .then((environment) => environment.createAssetFromFiles({
* fields: {
* file: {
* 'en-US': {
Expand Down Expand Up @@ -573,8 +588,10 @@ export default function createEnvironmentApi ({
* accessToken: '<content_management_api_key>'
* })
* const uploadStream = createReadStream('path/to/filename_english.jpg')
*
* client.getSpace('<space_id>')
* .then((space) => space.createUpload({file: uploadStream, 'image/png'})
* .then((space) => space.getEnvironment('<environment-id>'))
* .then((environment) => environment.createUpload({file: uploadStream, 'image/png'})
* .then((upload) => console.log(upload))
* .catch(console.error)
*/
Expand Down Expand Up @@ -604,8 +621,10 @@ export default function createEnvironmentApi ({
* accessToken: '<content_management_api_key>'
* })
* const uploadStream = createReadStream('path/to/filename_english.jpg')
*
* client.getSpace('<space_id>')
* .then((space) => space.getUpload('<upload-id>')
* .then((space) => space.getEnvironment('<environment-id>'))
* .then((environment) => environment.getUpload('<upload-id>')
* .then((upload) => console.log(upload))
* .catch(console.error)
*/
Expand All @@ -628,7 +647,8 @@ export default function createEnvironmentApi ({
* })
*
* client.getSpace('<space_id>')
* .then((space) => space.getLocale('<locale_id>'))
* .then((space) => space.getEnvironment('<environment-id>'))
* .then((environment) => environment.getLocale('<locale_id>'))
* .then((locale) => console.log(locale))
* .catch(console.error)
*/
Expand All @@ -649,7 +669,8 @@ export default function createEnvironmentApi ({
* })
*
* client.getSpace('<space_id>')
* .then((space) => space.getLocales())
* .then((space) => space.getEnvironment('<environment-id>'))
* .then((environment) => environment.getLocales())
* .then((response) => console.log(response.items))
* .catch(console.error)
*/
Expand All @@ -673,7 +694,8 @@ export default function createEnvironmentApi ({
*
* // Create locale
* client.getSpace('<space_id>')
* .then((space) => space.createLocale({
* .then((space) => space.getEnvironment('<environment-id>'))
* .then((environment) => environment.createLocale({
* name: 'German (Austria)',
* code: 'de-AT',
* fallbackCode: 'de-DE',
Expand All @@ -700,7 +722,8 @@ export default function createEnvironmentApi ({
* })
*
* client.getSpace('<space_id>')
* .then((space) => space.getUiExtension('<ui-extension-id>'))
* .then((space) => space.getEnvironment('<environment-id>'))
* .then((environment) => environment.getUiExtension('<ui-extension-id>'))
* .then((uiExtension) => console.log(uiExtension))
* .catch(console.error)
*/
Expand All @@ -721,7 +744,8 @@ export default function createEnvironmentApi ({
* })
*
* client.getSpace('<space_id>')
* .then((space) => space.getUiExtensions()
* .then((space) => space.getEnvironment('<environment-id>'))
* .then((environment) => environment.getUiExtensions()
* .then((response) => console.log(response.items))
* .catch(console.error)
*/
Expand All @@ -744,7 +768,8 @@ export default function createEnvironmentApi ({
* })
*
* client.getSpace('<space_id>')
* .then((space) => space.createUiExtension({
* .then((space) => space.getEnvironment('<environment-id>'))
* .then((environment) => environment.createUiExtension({
* extension: {
* name: 'My awesome extension',
* src: 'https://example.com/my',
Expand Down Expand Up @@ -782,7 +807,8 @@ export default function createEnvironmentApi ({
* })
*
* client.getSpace('<space_id>')
* .then((space) => space.createUiExtensionWithId('<extension_id>', {
* .then((space) => space.getEnvironment('<environment-id>'))
* .then((environment) => environment.createUiExtensionWithId('<extension_id>', {
* extension: {
* name: 'My awesome extension',
* src: 'https://example.com/my',
Expand Down Expand Up @@ -818,7 +844,8 @@ export default function createEnvironmentApi ({
* })
*
* client.getSpace('<space_id>')
* .then((space) => space.getEntrySnapshots('<entry_id>'))
* .then((space) => space.getEnvironment('<environment-id>'))
* .then((environment) => environment.getEntrySnapshots('<entry_id>'))
* .then((snapshots) => console.log(snapshots.items))
* .catch(console.error)
*/
Expand All @@ -840,7 +867,8 @@ export default function createEnvironmentApi ({
* })
*
* client.getSpace('<space_id>')
* .then((space) => space.getContentTypeSnapshots('<contentTypeId>'))
* .then((space) => space.getEnvironment('<environment-id>'))
* .then((environment) => environment.getContentTypeSnapshots('<contentTypeId>'))
* .then((snapshots) => console.log(snapshots.items))
* .catch(console.error)
*/
Expand Down
16 changes: 6 additions & 10 deletions lib/create-space-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export default function createSpaceApi ({
* Creates an Environement
* @memberof ContentfulSpaceAPI
* @see {Environment}
* @param {object} data - Object representation of the Environment to be created
* @param {object} [data] - Object representation of the Environment to be created
* @return {Promise<Environment.Environment>} Promise for the newly created Environment
* @example
* const contentful = require('contentful-management')
Expand All @@ -200,13 +200,11 @@ export default function createSpaceApi ({
* })
*
* client.getSpace('<space_id>')
* .then((space) => space.createEnvironment({
* name: 'Blog Post',
* }))
* .then((space) => space.createEnvironment({ name: 'Staging' }))
* .then((environment) => console.log(environment))
* .catch(console.error)
*/
function createEnvironment (data) {
function createEnvironment (data = {}) {
return http.post('environments', data)
.then((response) => wrapEnvironment(http, response.data), errorHandler)
}
Expand All @@ -216,7 +214,7 @@ export default function createSpaceApi ({
* @memberof ContentfulSpaceAPI
* @see {Environment}
* @param id string - custom id
* @param {object} data - Object representation of the Environment to be created
* @param {object} [data] - Object representation of the Environment to be created
* @return {Promise<Environment.Environment>} Promise for the newly created Environment
* @example
* const contentful = require('contentful-management')
Expand All @@ -226,13 +224,11 @@ export default function createSpaceApi ({
* })
*
* client.getSpace('<space_id>')
* .then((space) => space.createEnvironment('<custom-id>', {
* name: 'Blog Post',
* }))
* .then((space) => space.createEnvironment('<custom-id>', { name: 'Staging' }))
* .then((environment) => console.log(environment))
* .catch(console.error)
*/
function createEnvironmentWithId (id, data) {
function createEnvironmentWithId (id, data = {}) {
return http.put('environments/' + id, data)
.then((response) => wrapEnvironment(http, response.data), errorHandler)
}
Expand Down

0 comments on commit ae6ef78

Please sign in to comment.