ncmb-ruby-client 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/file_test.rb +10 -0
- data/lib/ncmb/client.rb +7 -2
- data/lib/ncmb/data_store.rb +10 -2
- data/lib/ncmb/file.rb +5 -0
- data/lib/ncmb/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e65e1b5191a72496c2e4a2e9d8ab68c763c2ed8a
|
4
|
+
data.tar.gz: 68d517fcc314a76e414fd7aa7c102620c3354b0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 023b10a8a2fc0e80b599bfea180b8f702fd10ec18a6365512ff30e3f321d673494ceed1a9bb82194b8cb2a0e4273be8c428e99ca3a7e56a785979b42b89b92a3
|
7
|
+
data.tar.gz: 091f60a5952d5d34c1dfcc04bdac6cb463cf1fd08a8fde9c596c17344b72de396675dee5ad4f1e6f830e683f116f04bc7b6aa7c289f88b303b2310434dac5d11
|
data/examples/file_test.rb
CHANGED
@@ -18,3 +18,13 @@ f.update()
|
|
18
18
|
puts "Updated"
|
19
19
|
f.delete()
|
20
20
|
puts "Deleted"
|
21
|
+
|
22
|
+
f = NCMB::NFile.new('http://mb.cloud.nifty.com/assets/images/logo.png')
|
23
|
+
f.acl.public('read', true)
|
24
|
+
f.acl.public('write', true)
|
25
|
+
f.fileName = "test.png"
|
26
|
+
f.save()
|
27
|
+
file = NCMB::NFile.new("test.png")
|
28
|
+
fp = open("test.png", "w")
|
29
|
+
fp.write(file.get)
|
30
|
+
fp.close
|
data/lib/ncmb/client.rb
CHANGED
@@ -157,7 +157,12 @@ module NCMB
|
|
157
157
|
"#{key}=#{value}"
|
158
158
|
end.join("&")
|
159
159
|
path = path + (query == '' ? "" : "?"+query)
|
160
|
-
|
160
|
+
rp = Regexp.new "/#{NCMB::API_VERSION}/files/.*"
|
161
|
+
if path =~ rp
|
162
|
+
json = http.get(path, headers).body
|
163
|
+
else
|
164
|
+
json = JSON.parse(http.get(path, headers).body, symbolize_names: true)
|
165
|
+
end
|
161
166
|
when :post
|
162
167
|
req = Net::HTTP::Post.new(path)
|
163
168
|
if queries[:file].is_a?(File) || queries[:file].is_a?(StringIO)
|
@@ -195,7 +200,7 @@ module NCMB
|
|
195
200
|
@@last_error = e
|
196
201
|
raise NCMB::APIError.new(e.to_s)
|
197
202
|
end
|
198
|
-
if json[:error] != nil
|
203
|
+
if json.is_a?(Hash) && json[:error] != nil
|
199
204
|
raise NCMB::APIError.new(json[:error])
|
200
205
|
end
|
201
206
|
json
|
data/lib/ncmb/data_store.rb
CHANGED
@@ -74,11 +74,19 @@ module NCMB
|
|
74
74
|
|
75
75
|
def path
|
76
76
|
return @path if @path
|
77
|
-
|
77
|
+
if ["file", "user", "push", "installation"].include? @name
|
78
|
+
if @name == "push"
|
79
|
+
"/#{@@client.api_version}/#{@name}"
|
80
|
+
else
|
81
|
+
"/#{@@client.api_version}/#{@name}s"
|
82
|
+
end
|
83
|
+
else
|
84
|
+
"/#{@@client.api_version}/classes/#{@name}"
|
85
|
+
end
|
78
86
|
end
|
79
87
|
|
80
88
|
def get
|
81
|
-
return @items unless @items.nil?
|
89
|
+
# return @items unless @items.nil?
|
82
90
|
results = @@client.get path, @queries
|
83
91
|
return [] unless results
|
84
92
|
if results[:error] && results[:error] != ""
|
data/lib/ncmb/file.rb
CHANGED
@@ -8,6 +8,7 @@ module NCMB
|
|
8
8
|
@fields[:fileName] = File.basename(file_path)
|
9
9
|
@fields['mime-type'.to_sym] = MIME::Types.type_for(file_path)[0]
|
10
10
|
end
|
11
|
+
@content = nil
|
11
12
|
end
|
12
13
|
|
13
14
|
def save
|
@@ -16,6 +17,10 @@ module NCMB
|
|
16
17
|
end
|
17
18
|
alias :update :save
|
18
19
|
|
20
|
+
def get
|
21
|
+
@content = @@client.get path
|
22
|
+
end
|
23
|
+
|
19
24
|
def path
|
20
25
|
"#{base_path}/#{@fields[:fileName]}"
|
21
26
|
end
|
data/lib/ncmb/version.rb
CHANGED