ncmb-ruby-client 0.1.4 → 0.1.5
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 +4 -4
- data/examples/script.rb +25 -0
- data/lib/ncmb.rb +1 -0
- data/lib/ncmb/client.rb +28 -13
- data/lib/ncmb/script.rb +56 -0
- data/lib/ncmb/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48bbbbec68144fff94c2a7e1656718803453c05e
|
4
|
+
data.tar.gz: 05d7af86eb4f65285015a6f392ec2682b624d0b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15d6178f6738c97f646ebea562355c767a66440db59f8ab7ced4fd3276035dba92a82e856c7763c691e93e7d1125be6270bb389b91de4566de683d45d08df421
|
7
|
+
data.tar.gz: 801aa3ae319c262df4a975e5fd772ba7440f1b51a7d88663740e5bb32dd3e1d8cff93ef9e4469d6b09d1ae9eb5bb6c9cddcee30941bce29c242f3c76ed11b534
|
data/examples/script.rb
ADDED
@@ -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
|
data/lib/ncmb.rb
CHANGED
data/lib/ncmb/client.rb
CHANGED
@@ -9,6 +9,8 @@ end
|
|
9
9
|
|
10
10
|
module NCMB
|
11
11
|
DOMAIN = 'mbaas.api.nifcloud.com'
|
12
|
+
SCRIPT_DOMAIN = 'script.mbaas.api.nifcloud.com'
|
13
|
+
SCRIPT_API_VERSION = '2015-09-01'
|
12
14
|
API_VERSION = '2013-09-01'
|
13
15
|
@application_key = nil
|
14
16
|
@client_key = nil
|
@@ -18,28 +20,30 @@ module NCMB
|
|
18
20
|
|
19
21
|
class Client
|
20
22
|
include NCMB
|
21
|
-
attr_accessor :application_key, :client_key, :domain, :api_version
|
23
|
+
attr_accessor :application_key, :client_key, :domain, :api_version, :script_api_version
|
22
24
|
def initialize(params = {})
|
23
25
|
@domain = NCMB::DOMAIN
|
24
26
|
@api_version = NCMB::API_VERSION
|
27
|
+
@script_domain = NCMB::SCRIPT_DOMAIN
|
28
|
+
@script_api_version = NCMB::SCRIPT_API_VERSION
|
25
29
|
@application_key = params[:application_key]
|
26
30
|
@client_key = params[:client_key]
|
27
31
|
end
|
28
32
|
|
29
|
-
def get(path, params = {})
|
30
|
-
request :get, path, params
|
33
|
+
def get(path, params = {}, headers = {})
|
34
|
+
request :get, path, params, headers
|
31
35
|
end
|
32
36
|
|
33
|
-
def post(path, params = {})
|
34
|
-
request :post, path, params
|
37
|
+
def post(path, params = {}, headers = {})
|
38
|
+
request :post, path, params, headers
|
35
39
|
end
|
36
40
|
|
37
|
-
def put(path, params = {})
|
38
|
-
request :put, path, params
|
41
|
+
def put(path, params = {}, headers = {})
|
42
|
+
request :put, path, params, headers
|
39
43
|
end
|
40
44
|
|
41
|
-
def delete(path, params = {})
|
42
|
-
request :delete, path, params
|
45
|
+
def delete(path, params = {}, headers = {})
|
46
|
+
request :delete, path, params, headers
|
43
47
|
end
|
44
48
|
|
45
49
|
def array2hash(ary)
|
@@ -90,7 +94,6 @@ module NCMB
|
|
90
94
|
results[k.to_s] = v.to_s
|
91
95
|
end
|
92
96
|
end
|
93
|
-
puts results
|
94
97
|
results
|
95
98
|
end
|
96
99
|
|
@@ -114,7 +117,7 @@ module NCMB
|
|
114
117
|
end
|
115
118
|
signature_base = []
|
116
119
|
signature_base << method.upcase
|
117
|
-
signature_base <<
|
120
|
+
signature_base << get_domain(path)
|
118
121
|
signature_base << path
|
119
122
|
signature_base << params.collect{|k,v| "#{k}=#{v}"}.join("&")
|
120
123
|
Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), @client_key, signature_base.join("\n"))).strip()
|
@@ -135,10 +138,19 @@ module NCMB
|
|
135
138
|
post_body.join("\r\n")
|
136
139
|
end
|
137
140
|
|
138
|
-
def
|
141
|
+
def get_domain(path)
|
142
|
+
domain = @domain
|
143
|
+
if path.start_with?("/#{@script_api_version}/script\/")
|
144
|
+
domain = @script_domain
|
145
|
+
end
|
146
|
+
domain
|
147
|
+
end
|
148
|
+
|
149
|
+
def request(method, path, queries = {}, addHeaders = {})
|
139
150
|
now = Time.now.utc.iso8601
|
140
151
|
signature = generate_signature(method, path, now, queries)
|
141
|
-
|
152
|
+
domain = get_domain(path)
|
153
|
+
http = Net::HTTP.new(domain, 443)
|
142
154
|
http.use_ssl=true
|
143
155
|
headers = {
|
144
156
|
"X-NCMB-Application-Key" => @application_key,
|
@@ -146,6 +158,9 @@ module NCMB
|
|
146
158
|
"X-NCMB-Timestamp" => now,
|
147
159
|
"Content-Type" => 'application/json'
|
148
160
|
}
|
161
|
+
(addHeaders || {}).each do |name, value|
|
162
|
+
headers[name] = value
|
163
|
+
end
|
149
164
|
if NCMB.CurrentUser
|
150
165
|
headers['X-NCMB-Apps-Session-Token'] = NCMB.CurrentUser.sessionToken
|
151
166
|
end
|
data/lib/ncmb/script.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NCMB
|
4
|
+
class Script
|
5
|
+
include NCMB
|
6
|
+
def initialize(name)
|
7
|
+
@name = name
|
8
|
+
@params = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def get(params = {})
|
12
|
+
self.set(params).execute('get')
|
13
|
+
end
|
14
|
+
|
15
|
+
def post(params = {})
|
16
|
+
self.set(params).execute('post')
|
17
|
+
end
|
18
|
+
|
19
|
+
def put(params = {})
|
20
|
+
self.set(params).execute('put')
|
21
|
+
end
|
22
|
+
|
23
|
+
def delete(params = {})
|
24
|
+
self.set(params)
|
25
|
+
@@client.delete
|
26
|
+
end
|
27
|
+
|
28
|
+
def set(params)
|
29
|
+
params = Hash[ params.map{ |k, v| [k.to_sym, v] } ]
|
30
|
+
self
|
31
|
+
.headers(params[:headers])
|
32
|
+
.body(params[:body])
|
33
|
+
.query(params[:query])
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
def headers(params)
|
38
|
+
@params[:headers] = params
|
39
|
+
self
|
40
|
+
end
|
41
|
+
|
42
|
+
def body(params)
|
43
|
+
@params[:body] = params
|
44
|
+
self
|
45
|
+
end
|
46
|
+
|
47
|
+
def query(params)
|
48
|
+
@params[:query] = params
|
49
|
+
self
|
50
|
+
end
|
51
|
+
|
52
|
+
def execute(method)
|
53
|
+
@@client.send(method, "/#{@@client.script_api_version}/script/#{@name}", (@params[:query] || {}).merge(@params[:body] || {}), @params[:headers])
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/ncmb/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ncmb-ruby-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Atsushi Nakatsugawa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -73,6 +73,7 @@ files:
|
|
73
73
|
- examples/pointer_test.rb
|
74
74
|
- examples/push.rb
|
75
75
|
- examples/relation.rb
|
76
|
+
- examples/script.rb
|
76
77
|
- examples/signature.rb
|
77
78
|
- examples/user_test.rb
|
78
79
|
- examples/venue_search.rb
|
@@ -91,6 +92,7 @@ files:
|
|
91
92
|
- lib/ncmb/query.rb
|
92
93
|
- lib/ncmb/relation.rb
|
93
94
|
- lib/ncmb/role.rb
|
95
|
+
- lib/ncmb/script.rb
|
94
96
|
- lib/ncmb/user.rb
|
95
97
|
- lib/ncmb/version.rb
|
96
98
|
- ncmb-ruby-client.gemspec
|