Socket
Book a DemoInstallSign in
Socket

ncmb-ruby-client

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ncmb-ruby-client

0.2.0
bundlerRubygems
Version published
Maintainers
1
Created
Source

ncmb-ruby-client

A simple Ruby client for the nifty cloud mobile backend REST API. This is developer preview.

Basic Usage

NCMB.initialize application_key: application_key,  client_key: client_key

@todo = NCMB::DataStore.new 'Todo'
@todo = @todo.limit(20)

@todo.each do |item|
  puts item[:String]
  puts "  #{item[:Array]} -> #{item[:Array].class}"
end

@todo = NCMB::Object.new 'Todo'
@todo.set('String', 'Test String')
@todo.set('Integer', 100)
@todo.set('Boolean', true)
@todo.set('Array', [1, 2, 3, "Orange", "Tomato"])
@todo.set('Object', {test1: 'a', test2: 'b'})
@todo.set('Location', NCMB::GeoPoint.new(50, 30))
@todo.set('MultipleLine', "test\ntest\n")
@todo.set('Increment', NCMB::Increment.new(2))
@todo.set('Date', Time.new(2016, 2, 24, 12, 30, 45))
@todo.save

Register push notification

NCMB.initialize application_key: application_key,  client_key: client_key

@push = NCMB::Push.new
@push.immediateDeliveryFlag = true
@push.target = ['ios']
@push.message = "This is test message"
@push.deliveryExpirationTime = "3 day"
if @push.save
  puts "Push save successful."
else
  puts "Push save faild."
end

Unit test

Settings

  • Install libraries
bundle install
  • Rename file setting_default.yml to setting.yml and then fill you application_key, client_key

Run unit test

Run spec task:

rake spec

Run all examples

Run examples task:

rake examples

Or you can run every single example

ruby examples/example_file_name.rb

Test script

Before run examples/script.rb, you should upload the below script files to Script function on the Console screen.

helloworld.js

  • File Name: helloworld.js
  • Method: GET
  • File Status: Executable
module.exports = function(req, res) {
  res.send('{"msg":"Hello World!"}');
}

helloworld2.js

  • File Name: helloworld2.js
  • Method: GET
  • File Status: Executable
module.exports = function(req, res) {
  if (req.query.name) {
    res.send('{"msg":"Hello ' + req.query.name +'!"}');
  } else {
    res.send('{"msg":"Hello World!"}');
  }
}

email.js

  • File Name: email.js
  • Method: POST
  • File Status: Executable

(Don't forget to change YOUR-APPLICATION-KEY and YOUR-CLIENT-KEY to your value before upload.)

function saveData(req, res) {
  // POSTのデータを取得
  var email = req.body.email;
  var message = req.body.body;
  
  var NCMB = require('ncmb');
  var ncmb = new NCMB('YOUR-APPLICATION-KEY', 'YOUR-CLIENT-KEY');

  // データを保存する
  var Item = ncmb.DataStore('Item');
  var item = new Item();
  item.set("email", email)
      .set("message", message)
      .save()
      .then(function(item){
        // 成功
        res.send('{"msg":"POST data successfully!"}');

      })
      .catch(function(err){
        // 失敗
        res.send('{"msg":"' + err + '"}');
      });
}

module.exports = saveData;

Environment to confirm

  • Ruby v2.7.3 - Bundler version 2.1.4
  • Ruby v3.0.1 - Bundler version 2.2.15

License

MIT.

ニフクラ mobile backend

FAQs

Package last updated on 15 Jun 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.