lib/ncmb/client.rb in ncmb-ruby-client-0.0.9 vs lib/ncmb/client.rb in ncmb-ruby-client-0.1.0
- old
+ new
@@ -22,24 +22,24 @@
@api_version = NCMB::API_VERSION
@application_key = params[:application_key]
@client_key = params[:client_key]
end
- def get(path, params = {}, session_key = nil)
- request :get, path, params, session_key
+ def get(path, params = {})
+ request :get, path, params
end
- def post(path, params = {}, session_key = nil)
- request :post, path, params, session_key
+ def post(path, params = {})
+ request :post, path, params
end
- def put(path, params = {}, session_key = nil)
- request :put, path, params, session_key
+ def put(path, params = {})
+ request :put, path, params
end
- def delete(path, params = {}, session_key = nil)
- request :delete, path, params, session_key
+ def delete(path, params = {})
+ request :delete, path, params
end
def array2hash(ary)
new_v = {}
ary.each do |hash|
@@ -116,27 +116,26 @@
signature_base << path
signature_base << params.collect{|k,v| "#{k}=#{v}"}.join("&")
signature = Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), @client_key, signature_base.join("\n"))).strip()
end
- def request(method, path, queries = {}, session_key = nil)
+ def request(method, path, queries = {})
now = Time.now.utc.iso8601
signature = generate_signature(method, path, now, queries)
http = Net::HTTP.new(@domain, 443)
http.use_ssl=true
headers = {
"X-NCMB-Application-Key" => @application_key,
"X-NCMB-Signature" => signature,
"X-NCMB-Timestamp" => now,
"Content-Type" => 'application/json'
}
- if session_key
- headers['X-NCMB-Apps-Session-Token'] = session_key
+ if NCMB.CurrentUser
+ headers['X-NCMB-Apps-Session-Token'] = NCMB.CurrentUser.sessionToken
end
# queries = hash2query(queries)
json = nil
- begin
case method
when :get
query = encode_query(queries).map do |key, value|
"#{key}=#{value}"
end.join("&")
@@ -150,9 +149,10 @@
when :delete
response = http.delete(path, headers).body
return true if response == ""
json = JSON.parse(response, symbolize_names: true)
end
+ begin
rescue => e
@@last_error = e
raise NCMB::APIError.new(e.to_s)
end
if json[:error] != nil