Permalink
Browse files

ParseUser superclass for User objects

usage:
class User < ParseUser; end
u1 = User.create(:username => "Alan", :password => "foo")
u2 = User.login(:username => "Alan", :password => "foo")
u1.id == u2.id #=> true
  • Loading branch information...
adelevie committed Dec 16, 2011
1 parent 6d7fdb8 commit 72c6b26053cdd9e5bba295a2ded63d5d6c1d692c
Showing with 16 additions and 0 deletions.
  1. +1 −0 lib/parse_resource.rb
  2. +15 −0 lib/parse_user.rb
View
@@ -1,5 +1,6 @@
require 'base'
require 'query'
+require 'parse_user'
module ParseResource
end
View
@@ -0,0 +1,15 @@
+class ParseUser < ParseResource::Base
+ fields :username, :password
+
+ def self.login(username, password)
+ base_uri = "https://api.parse.com/1/login"
+ app_id = settings['app_id']
+ master_key = settings['master_key']
+ resource = RestClient::Resource.new(base_uri, app_id, master_key)
+
+ resp = resource.get(:params => {:username => username, :password => password})
+ user = model_name.constantize.new(JSON.parse(resp), false)
+
+ user
+ end
+end

0 comments on commit 72c6b26

Please sign in to comment.