How to use the cosmicjs.addObject function in cosmicjs

To help you get started, we’ve selected a few cosmicjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cosmicjs / cosmicapp-voting-app / components / AppState.js View on Github external
vote(object) {
    this.is_saving = true
    if (config.cosmicjs.bucket.write_key)
      object.write_key = config.cosmicjs.bucket.write_key
    addObject({ bucket: config.cosmicjs.bucket }, object, (err, res) => {
      // Set local storage
      window.localStorage.setItem(this.poll._id, _.find(this.options_selected, { poll: this.poll._id }).value)
      // Go to results page
      this.showResults()
    })
  }
  showResults() {
github cosmicjs / notetoself / index.js View on Github external
inquirer.prompt(question).then((answers) => {
    var params = {
      write_key: config.bucket.write_key,
      type_slug: 'notes',
      slug: Random.id().toLowerCase(),
      title: answers.note_text,
      content: ''
    }
    if(answers.note_text === ''){
      console.log(chalk.red("You cannot add an empty note"))
      MainMenu()
      return;
    }
    Cosmic.addObject(config, params, (error, response) =>{
      if(response.object){
        console.log(chalk.green("\u2713" + " Success"))
      }
      if(error){
        console.log(error)
      }
      MainMenu()
    })
  })
}
github cosmicjs / facebook-bot / index.js View on Github external
convo.ask("What would you like your reminder to be? etc 'I have an appointment tomorrow from 10 to 11 AM' the information will be added automatically", (payload, convo) => {
      datetime = chrono.parseDate(payload.message.text)
      var params = {
        write_key: config.bucket.write_key,
        type_slug: 'reminders',
        title: payload.message.text,
        metafields: [
         {
           key: 'date',
           type: 'text',
           value: datetime
         }
        ]
      }
      Cosmic.addObject(config, params, function(error, response){
        if(!error){
          eventEmitter.emit('new', response.object.slug, datetime)
          convo.say("reminder added correctly :)")
          convo.end()
        } else {
          convo.say("there seems to be a problem. . .")
          convo.end()
        }
      })
    })
  })
github tonyspiro / react-flux-cosmicjs / stores / ListStore.js View on Github external
addItem: function(payload){
    
    let new_item = payload.new_item;
    let _this = this;
    let object = {
      type_slug: 'list-items',
      title: new_item.title
    };

    Cosmic.addObject(config, object, function(err, response){
      
      if(response.object){
        let new_cosmic_item = response.object;
        _this.items.push(new_cosmic_item);
        _this.emitChange();
      }

    });
  },
github cosmicjs / medium-backup / routes / import-posts.js View on Github external
value: medium_link
                    }
                  ]
                }
                if (categories) {
                  var tags = ''
                  categories.forEach(category => {
                    tags += category + ', '
                  })
                  params.metafields.push({
                    key: 'tags',
                    title: 'Tags',
                    value: tags
                  })
                }
                Cosmic.addObject(cosmic_config, params, function(err, response) {
                  if (response)
                    posts_imported.push(post)
                  callback()
                })
              }
            })
          }, () => {
github tonyspiro / react-chat-app / models / Message.js View on Github external
title: 'Author',
          key: 'author',
          value: params.author,
          type: 'text',
          edit: 1
        }
      ],
      options: {
        slug_field: 0,
        content_editor: 0,
        add_metafields: 0,
        metafields_title: 0,
        metafields_key: 0
      }
    }
    Cosmic.addObject(config, object, (err, res) => {
      const new_object = res.object
      const message = {
        _id: new_object._id,
        metafield: {
          message: {
            value: new_object.metafields[0].value
          },
          author: {
            value: new_object.metafields[1].value
          }
        }
      }
      callback(message)
    })
  }
}

cosmicjs

The official client module for Cosmic. This module helps you easily add dynamic content to your website or application using the Cosmic headless CMS.

MIT
Latest version published 1 year ago

Package Health Score

42 / 100
Full package analysis