lib/ncmb/object.rb in ncmb-ruby-client-0.0.8 vs lib/ncmb/object.rb in ncmb-ruby-client-0.0.9

- old
+ new

@@ -5,22 +5,26 @@ def initialize(name, fields = {}, alc = "") @name = name @alc = alc @fields = fields end - + + def fields + @fields + end + def method_missing(name) sym = name.to_sym if @fields.has_key?(sym) return @fields[sym] else raise NoMethodError, "#{name} is not found" end end def set(name, value) - @fields[name] = value + @fields[name.to_sym] = value end def call(name) @fields[name.to_sym] || NoMethodError end @@ -30,13 +34,12 @@ end def post path = "/#{@@client.api_version}/classes/#{@name}" result = @@client.post path, @fields - alc = result[:acl] - result.delete(:acl) - NCMB::Object.new(@name, result, alc) + @fields.merge!(result) + self end alias :save :post def put path = "/#{@@client.api_version}/classes/#{@name}/#{@fields[:objectId]}" @@ -44,14 +47,25 @@ params.delete :objectId params.delete :createDate params.delete :updateDate result = @@client.put path, params @fields[:updateDate] = result[:updateDate] + self end alias :update :put def delete path = "/#{@@client.api_version}/classes/#{@name}/#{@fields[:objectId]}" - @@client.delete path, {} + response = @@client.delete path, {} + if response == true + return true + else + @@last_error = response + return false + end + end + + def error + @@last_error end end end