Class: ParseUser

Inherits:
ParseResource::Base show all
Defined in:
lib/parse_resource/parse_user.rb

Constant Summary

Constants inherited from ParseResource::Base

ParseResource::Base::HashWithIndifferentAccess

Instance Attribute Summary

Attributes inherited from ParseResource::Base

#error_instances

Class Method Summary collapse

Methods inherited from ParseResource::Base

#attributes, #attributes=, #attributes_for_saving, batch_save, belongs_to, chunk, class_attributes, #clean?, create, #create, #create_getters!, #create_setters!, #create_setters_and_getters!, #created_at, delete_all, #destroy, destroy_all, #dirty?, field, fields, find, #get_attribute, #id, included, #initialize, #instance_resource, load!, load_settings, merge_all_attributes, #merge_attributes, method_missing, model_base_uri, #model_base_uri, model_name_uri, #new?, #objectId, #persisted?, #pointerize, #post_result, #reload, #resource, resource, #save, save_all, #set_attribute, settings, to_date_object, #to_pointer, #update, #update_attributes, #updated_at, upload, where

Methods included from ParseResource::QueryMethods

included

Constructor Details

This class inherits a constructor from ParseResource::Base

Class Method Details

.authenticate(username, password) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/parse_resource/parse_user.rb', line 6

def self.authenticate(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)
  
  begin
    resp = resource.get(:params => {:username => username, :password => password})
    user = model_name.constantize.new(JSON.parse(resp), false)
          
    user 
  rescue 
    false
  end
  
end

.authenticate_with_facebook(user_id, access_token, expires) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/parse_resource/parse_user.rb', line 23

def self.authenticate_with_facebook(user_id, access_token, expires)
  base_uri   = "https://api.parse.com/1/users"
  app_id     = settings['app_id']
  master_key = settings['master_key']
  resource = RestClient::Resource.new(base_uri, app_id, master_key)

  begin
    resp = resource.post(
        { "authData" =>
                          { "facebook" =>
                                {
                                    "id" => user_id,
                                    "access_token" => access_token,
                                    "expiration_date" => Time.now + expires.to_i
                                }
                          }
                    }.to_json,
                   :content_type => 'application/json', :accept => :json)
    user = model_name.constantize.new(JSON.parse(resp), false)
    user
  rescue
    false
  end
end

.reset_password(email) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/parse_resource/parse_user.rb', line 48

def self.reset_password(email)
    base_uri   = "https://api.parse.com/1/requestPasswordReset"
    app_id     = settings['app_id']
    master_key = settings['master_key']
    resource = RestClient::Resource.new(base_uri, app_id, master_key)

    begin
      resp = resource.post({:email => email}.to_json, :content_type => 'application/json')
      true
    rescue
      false
    end
end