ncmb-ruby-client 0.1.2 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 9dc6e5511f6ca2807e381b8b30e46c7564f0e0e2
4
- data.tar.gz: 8b103fbf74d9e3a0536b34fa1c8339dba15128fb
2
+ SHA256:
3
+ metadata.gz: 0a10b2934a9d081c46122c95bf8e2aac94bff22122f091cf047d18fddcff697c
4
+ data.tar.gz: 481533a0839eece8d941d21864c4954b42804f66298e96b06bed1132ed96575e
5
5
  SHA512:
6
- metadata.gz: 64d06fa4dd1bee428bb610a12b88a2bead91d5f54d9113af10a3551b2037cd3f49a6d430586d2632462a5f367cc12ddd768753a035c79d45879e0a17b8c8c8e6
7
- data.tar.gz: 96a493b26c18838f7fd7c5bab128a14243febbca8a8cda36c25aa46fc3bc2d95a328c14c0fcf67925a0bbb87c396e883e4187aea7e07d97a9430e5fd8b092c4a
6
+ metadata.gz: 1fb5b8d73347ea247529c74c7a2950bad8e516d78602244801bf7de3770f63597dc92662e1f8660f02fae4508bb0a06234d6b2dfd22f446bea221efde7531e7d
7
+ data.tar.gz: 6627eb644136a10b8219e7ef595703cb40b191e74cccbfebde2d20bba6c0189d79e4da4a23897156b25aaac090e100e47018e3802c4200f731ada9952ae220a1
data/.rubocop.yml ADDED
@@ -0,0 +1,2 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.3
data/Gemfile CHANGED
@@ -1,6 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
4
+
5
+ gem 'mime-types'
2
6
  gem 'simplecov'
3
7
  gem 'simplecov-gem-profile'
4
- gem 'mime-types'
5
8
  # Specify your gem's dependencies in ncmb-ruby-client.gemspec
6
9
  gemspec
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  ncmb-ruby-client
2
2
  ================
3
3
 
4
- A simple Ruby client for the nifty cloud mobile backend REST API
4
+ A simple Ruby client for the nifty cloud mobile backend REST API. This is developer preview.
5
5
 
6
6
  Basic Usage
7
7
  -----------
@@ -47,4 +47,8 @@ else
47
47
  end
48
48
  ```
49
49
 
50
- [ニフティクラウド mobile backend](http://mb.cloud.nifty.com/)
50
+ ## License
51
+
52
+ MIT.
53
+
54
+ [ニフクラ mobile backend](http://mb.cloud.nifty.com/)
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
 
3
5
  Bundler.setup
@@ -6,4 +8,8 @@ require 'rspec/core/rake_task'
6
8
  desc "run spec"
7
9
  RSpec::Core::RakeTask.new(:spec) do |t|
8
10
  t.rspec_opts = ["--color", "--format documentation"]
11
+ end
12
+
13
+ task :default do
14
+ FileList['examples/d*.rb'].each { |file| ruby file }
9
15
  end
data/examples/acl_test.rb CHANGED
@@ -1,16 +1,22 @@
1
- $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- $:.unshift(File.dirname(__FILE__))
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+
3
6
  require 'rubygems'
4
7
  require 'ncmb'
5
8
  require 'yaml'
6
9
  yaml = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'setting.yml'))
7
- NCMB.initialize application_key: yaml['application_key'], client_key: yaml['client_key']
10
+ NCMB.initialize(
11
+ application_key: yaml['application_key'],
12
+ client_key: yaml['client_key']
13
+ )
8
14
 
9
15
  @users = []
10
16
 
11
17
  @ids = [
12
- {id: 'testUser1', password: 'testPassword1'},
13
- {id: 'testUser2', password: 'testPassword2'}
18
+ { id: 'testUser1', password: 'testPassword1' },
19
+ { id: 'testUser2', password: 'testPassword2' }
14
20
  ]
15
21
  @ids.each do |hash|
16
22
  @user = NCMB::User.login(hash[:id], hash[:password])
@@ -37,7 +43,7 @@ end
37
43
  @item.acl.public('write', false)
38
44
  @item.acl.user(@users[0], 'read', true)
39
45
  @item.acl.user(@users[0], 'write', true)
40
- @role = NCMB::Role.find_or_create("manager2")
46
+ @role = NCMB::Role.find_or_create('manager2')
41
47
 
42
48
  @item.acl.role(@role, 'read', true)
43
49
  @item.acl.role(@role, 'write', true)
data/examples/csv_test.rb CHANGED
@@ -1,23 +1,32 @@
1
- $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- $:.unshift(File.dirname(__FILE__))
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+
3
6
  require 'rubygems'
4
7
  require 'ncmb'
5
8
  require 'yaml'
6
9
  require 'csv'
7
10
 
8
11
  yaml = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'setting.yml'))
9
- NCMB.initialize application_key: yaml['application_key'], client_key: yaml['client_key']
12
+ NCMB.initialize(
13
+ application_key: yaml['application_key'],
14
+ client_key: yaml['client_key']
15
+ )
10
16
  @todo = NCMB::DataStore.new 'TestClass'
11
- 1000.times do |i|
12
- @todo.post(message: "Hello! #{i}")
17
+ 20.times do |i|
18
+ item = @todo.new
19
+ item.set('message', "Hello! #{i}")
20
+ item.save
13
21
  end
14
- @todos = @todo.limit(20).count(1).skip(0)
22
+
23
+ @todos = @todo.limit(10).skip(0)
15
24
 
16
25
  csv_string = CSV.generate do |csv|
17
- csv << @todos.first.columns
26
+ csv << @todos.first.fields.keys
18
27
  @todos.each do |todo|
19
28
  params = []
20
- todo.columns.each do |name|
29
+ todo.fields.keys.each do |name|
21
30
  params << todo.call(name)
22
31
  end
23
32
  csv << params
@@ -1,10 +1,16 @@
1
- $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- $:.unshift(File.dirname(__FILE__))
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+
3
6
  require 'rubygems'
4
7
  require 'ncmb'
5
8
  require 'yaml'
6
9
  yaml = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'setting.yml'))
7
- NCMB.initialize application_key: yaml['application_key'], client_key: yaml['client_key']
10
+ NCMB.initialize(
11
+ application_key: yaml['application_key'],
12
+ client_key: yaml['client_key']
13
+ )
8
14
 
9
15
  example = NCMB::DataStore.new 'Example'
10
16
  example.delete_all
@@ -14,7 +20,7 @@ example.delete_all
14
20
  item.set('String', "テスト#{i}00")
15
21
  item.set('Integer', i)
16
22
  item.set('Boolean', true)
17
- item.set('Array', [i, i * 2, i * 3, "Orange", "Tomato"])
23
+ item.set('Array', [i, i * 2, i * 3, 'Orange', 'Tomato'])
18
24
  item.set('Object', {test1: 'a', test2: 'b'})
19
25
  item.set('Location', NCMB::GeoPoint.new((i + 1) * 10, (i + 2) * 5))
20
26
  item.set('MultipleLine', "test\ntest\n")
@@ -37,7 +43,8 @@ geo1 = NCMB::GeoPoint.new(50, 30);
37
43
  geo2 = NCMB::GeoPoint.new(51, 31);
38
44
 
39
45
  # @todo = @todo.limit(20).withinKilometers("Location", geo1, 1000)
40
- example = example.limit(1).withinSquare("Location", geo1, geo2)
46
+
47
+ example = example.limit(1).withinSquare('Location', geo1, geo2)
41
48
  begin
42
49
  example.each_with_index do |item, i|
43
50
  puts item[:String]
@@ -50,6 +57,7 @@ begin
50
57
  # item.update
51
58
  end
52
59
  rescue NCMB::FetchError => e
60
+ puts e
53
61
  puts example.error
54
62
  end
55
63
 
@@ -1,20 +1,36 @@
1
- $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- $:.unshift(File.dirname(__FILE__))
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+
3
6
  require 'rubygems'
4
7
  require 'ncmb'
5
8
  require 'yaml'
6
9
  require 'open-uri'
7
10
  yaml = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'setting.yml'))
8
- NCMB.initialize application_key: yaml['application_key'], client_key: yaml['client_key']
11
+ NCMB.initialize(
12
+ application_key: yaml['application_key'],
13
+ client_key: yaml['client_key']
14
+ )
9
15
 
10
- f = NCMB::NFile.new('http://mb.cloud.nifty.com/assets/images/logo.png')
16
+ f = NCMB::NFile.new('https://mbaas.nifcloud.com/assets/images/logo.png')
11
17
  f.acl.public('read', true)
12
18
  f.acl.public('write', true)
13
- f.fileName = "test.png"
19
+ f.fileName = 'test.png'
14
20
  f.save()
15
- puts "Uploaded"
21
+ puts 'Uploaded'
16
22
  f.file = 'http://k.yimg.jp/images/top/sp2/cmn/logo-ns_d_131205.png'
17
23
  f.update()
18
- puts "Updated"
24
+ puts 'Updated'
19
25
  f.delete()
20
- puts "Deleted"
26
+ puts 'Deleted'
27
+
28
+ f = NCMB::NFile.new('https://mbaas.nifcloud.com/assets/images/logo.png')
29
+ f.acl.public('read', true)
30
+ f.acl.public('write', true)
31
+ f.fileName = 'test.png'
32
+ f.save()
33
+ file = NCMB::NFile.new('test.png')
34
+ fp = open('test.png', 'w')
35
+ fp.write(file.get)
36
+ fp.close
@@ -1,10 +1,16 @@
1
- $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- $:.unshift(File.dirname(__FILE__))
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+
3
6
  require 'rubygems'
4
7
  require 'ncmb'
5
8
  require 'yaml'
6
9
  yaml = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'setting.yml'))
7
- NCMB.initialize application_key: yaml['application_key'], client_key: yaml['client_key']
10
+ NCMB.initialize(
11
+ application_key: yaml['application_key'],
12
+ client_key: yaml['client_key']
13
+ )
8
14
 
9
15
  example = NCMB::DataStore.new 'Example'
10
16
 
@@ -12,13 +18,13 @@ require 'benchmark'
12
18
 
13
19
  ary = []
14
20
  Benchmark.bm 10 do |r|
15
- r.report "Save DataStore" do
21
+ r.report 'Save DataStore' do
16
22
  100.times do |i|
17
23
  item = example.new
18
24
  item.set('String', "テスト#{i}00")
19
25
  item.set('Integer', i)
20
26
  item.set('Boolean', true)
21
- item.set('Array', [i, i * 2, i * 3, "Orange", "Tomato"])
27
+ item.set('Array', [i, i * 2, i * 3, 'Orange', 'Tomato'])
22
28
  item.set('Object', {test1: 'a', test2: 'b'})
23
29
  item.set('Location', NCMB::GeoPoint.new(30, 50))
24
30
  item.set('MultipleLine', "test\ntest\n")
@@ -28,7 +34,7 @@ Benchmark.bm 10 do |r|
28
34
  ary << item.objectId
29
35
  end
30
36
  end
31
- r.report "Delete objects" do
37
+ r.report 'Delete objects' do
32
38
  ary.each do |objectId|
33
39
  item = example.new(objectId: objectId)
34
40
  item.delete
@@ -1,16 +1,22 @@
1
- $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- $:.unshift(File.dirname(__FILE__))
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+
3
6
  require 'rubygems'
4
7
  require 'ncmb'
5
8
  require 'yaml'
6
9
  yaml = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'setting.yml'))
7
- NCMB.initialize application_key: yaml['application_key'], client_key: yaml['client_key']
10
+ NCMB.initialize(
11
+ application_key: yaml['application_key'],
12
+ client_key: yaml['client_key']
13
+ )
8
14
 
9
15
  Parent = NCMB::DataStore.new 'Parent'
10
16
 
11
17
  Child = NCMB::DataStore.new 'Child'
12
- child = Child.new(name: "Taro")
13
- parent = Parent.new(name: "Oya")
18
+ child = Child.new(name: 'Taro')
19
+ parent = Parent.new(name: 'Oya')
14
20
  parent.child = child
15
21
  parent.save
16
22
 
data/examples/push.rb CHANGED
@@ -1,18 +1,24 @@
1
- $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- $:.unshift(File.dirname(__FILE__))
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+
3
6
  require 'rubygems'
4
7
  require 'ncmb'
5
8
  require 'yaml'
6
9
  yaml = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'setting.yml'))
7
- NCMB.initialize application_key: yaml['application_key'], client_key: yaml['client_key']
10
+ NCMB.initialize(
11
+ application_key: yaml['application_key'],
12
+ client_key: yaml['client_key']
13
+ )
8
14
 
9
15
  @push = NCMB::Push.new
10
16
  @push.immediateDeliveryFlag = true
11
17
  @push.target = ['ios']
12
- @push.message = "This is test message"
13
- @push.deliveryExpirationTime = "3 day"
18
+ @push.message = 'This is test message'
19
+ @push.deliveryExpirationTime = '3 day'
14
20
  if @push.save
15
- puts "Push save successful."
21
+ puts 'Push save successful.'
16
22
  else
17
- puts "Push save faild."
23
+ puts 'Push save faild.'
18
24
  end
data/examples/relation.rb CHANGED
@@ -1,18 +1,24 @@
1
- $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- $:.unshift(File.dirname(__FILE__))
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+
3
6
  require 'rubygems'
4
7
  require 'ncmb'
5
8
  require 'yaml'
6
9
  yaml = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'setting.yml'))
7
- NCMB.initialize application_key: yaml['application_key'], client_key: yaml['client_key']
10
+ NCMB.initialize(
11
+ application_key: yaml['application_key'],
12
+ client_key: yaml['client_key']
13
+ )
8
14
 
9
15
  Food = NCMB::DataStore.new 'Food'
10
16
 
11
17
  Basket = NCMB::DataStore.new('Basket')
12
18
  basket = Basket.new
13
19
  basket.foods = []
14
- basket.foods << Food.new(name: "banana", type: "fruit")
15
- basket.foods << Food.new(name: "pear", type: "fruit")
20
+ basket.foods << Food.new(name: 'banana', type: 'fruit')
21
+ basket.foods << Food.new(name: 'pear', type: 'fruit')
16
22
 
17
23
  # relation = NCMB::Relation.new
18
24
  # relation << Food.new(name: "banana", type: "fruit", objectId: "test1")
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+
6
+ require 'rubygems'
7
+ require 'ncmb'
8
+ require 'yaml'
9
+ yaml = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'setting.yml'))
10
+ NCMB.initialize(
11
+ application_key: yaml['application_key'],
12
+ client_key: yaml['client_key']
13
+ )
14
+
15
+ script = NCMB::Script.new 'helloworld.js'
16
+ results = script.get
17
+ puts results
18
+
19
+ script = NCMB::Script.new 'helloworld2.js'
20
+ results = script.get(query: {a: 'b'})
21
+ puts results
22
+
23
+ script = NCMB::Script.new 'email.js'
24
+ results = script.post(body: {email: 'atsushi@moongift.jp', option: 'Test', body: 'message'})
25
+ puts results
@@ -1,11 +1,25 @@
1
- $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- $:.unshift(File.dirname(__FILE__))
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+
3
6
  require 'rubygems'
4
7
  require 'ncmb'
5
8
  require 'yaml'
6
9
  yaml = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'setting.yml'))
7
- @client = NCMB.initialize application_key: "6145f91061916580c742f806bab67649d10f45920246ff459404c46f00ff3e56", client_key: "1343d198b510a0315db1c03f3aa0e32418b7a743f8e4b47cbff670601345cf75"
10
+ @client = NCMB.initialize(
11
+ application_key: yaml['application_key'],
12
+ client_key: yaml['client_key']
13
+ )
8
14
 
9
15
  # puts @client.application_key
10
- puts @client.generate_signature :get, "/2013-09-01/classes/TestClass", "2013-12-02T02:44:35.452Z", {where: {testKey: "testValue"}}
16
+ puts @client.generate_signature(:get,
17
+ '/2013-09-01/classes/TestClass',
18
+ '2013-12-02T02:44:35.452Z',
19
+ {
20
+ where: {
21
+ testKey: 'testValue'
22
+ }
23
+ }
24
+ )
11
25
 
@@ -1,10 +1,16 @@
1
- $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- $:.unshift(File.dirname(__FILE__))
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+
3
6
  require 'rubygems'
4
7
  require 'ncmb'
5
8
  require 'yaml'
6
9
  yaml = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'setting.yml'))
7
- NCMB.initialize application_key: yaml['application_key'], client_key: yaml['client_key']
10
+ NCMB.initialize(
11
+ application_key: yaml['application_key'],
12
+ client_key: yaml['client_key']
13
+ )
8
14
 
9
15
  if @user = NCMB::User.login('testUser2', 'testPassword2')
10
16
  puts NCMB.CurrentUser.userName
@@ -20,8 +26,8 @@ end
20
26
  @user.set('userName', 'testUser2')
21
27
  @user.set('password', 'testPassword2')
22
28
  if @user.signUp
23
- puts "User create successful."
24
- @user.set("Hello", "World")
29
+ puts 'User create successful.'
30
+ @user.set('Hello', 'World')
25
31
  @user.update
26
32
  else
27
33
  puts "User create failed. #{@user.error.message}"