lib/ncmb/client.rb in ncmb-ruby-client-0.1.6 vs lib/ncmb/client.rb in ncmb-ruby-client-0.1.7
- old
+ new
@@ -62,11 +62,11 @@
def encode_query(queries = {})
results = {}
queries.each do |k, v|
v = array2hash(v) if v.is_a? Array
- value = URI.encode(v.is_a?(Hash) ? v.to_json : v.to_s).gsub("[", "%5B").gsub(":", "%3A").gsub("]", "%5D")
+ value = URI.encode_www_form_component(v.is_a?(Hash) ? v.to_json : v.to_s).gsub("[", "%5B").gsub(":", "%3A").gsub("]", "%5D")
results[k.to_s] = value
end
results
end
@@ -156,15 +156,15 @@
"X-NCMB-Application-Key" => @application_key,
"X-NCMB-Signature" => signature,
"X-NCMB-Timestamp" => now,
"Content-Type" => 'application/json'
}
- (addHeaders || {}).each do |name, value|
+ Array(addHeaders || {}).each do |name, value|
headers[name] = value
end
if NCMB.CurrentUser
- headers['X-NCMB-Apps-Session-Token'] = NCMB.CurrentUser.sessionToken
+ headers['X-NCMB-Apps-Session-Token'] = NCMB.CurrentUser[:sessionToken]
end
# queries = hash2query(queries)
json = nil
begin
case method
@@ -179,10 +179,10 @@
else
json = JSON.parse(http.get(path, headers).body, symbolize_names: true)
end
when :post
req = Net::HTTP::Post.new(path)
- if queries[:file].is_a?(File) || queries[:file].is_a?(StringIO)
+ if path.include? "/2013-09-01/files"
boundary = SecureRandom.uuid
req.body = make_boundary(boundary, queries)
headers["Content-Type"] = "multipart/form-data; boundary=#{boundary}"
else
queries = change_query(queries)