Class: FirebaseAuthClient

Inherits:
Object
  • Object
show all
Defined in:
lib/firebase-auth/firebase_auth_client.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new(ref) ⇒ Object



3
4
5
# File 'lib/firebase-auth/firebase_auth_client.rb', line 3

def self.new(ref)
  alloc.initWithRef(ref)
end

Instance Method Details

#check(&and_then) ⇒ Object



7
8
9
# File 'lib/firebase-auth/firebase_auth_client.rb', line 7

def check(&and_then)
  checkAuthStatusWithBlock(and_then)
end

#create(credentials, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/firebase-auth/firebase_auth_client.rb', line 11

def create(credentials, &block)
  raise "email is required in #{__method__}" unless credentials.key?(:email)
  raise "password is required in #{__method__}" unless credentials.key?(:password)
  email = credentials[:email]
  password = credentials[:password]
  begin
    createUserWithEmail(email, password:password, andCompletionBlock:block)
  rescue RuntimeError => e
    block.call(e, nil)
  end
end

#login(credentials, &block) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/firebase-auth/firebase_auth_client.rb', line 31

def (credentials, &block)
  raise "email is required in #{__method__}" unless credentials.key?(:email)
  raise "password is required in #{__method__}" unless credentials.key?(:password)
  email = credentials[:email]
  password = credentials[:password]
  begin
    loginWithEmail(email, andPassword:password, withCompletionBlock:block)
  rescue RuntimeError => e
    block.call(e, nil)
  end
end

#login_to_facebook(credentials, &block) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/firebase-auth/firebase_auth_client.rb', line 53

def (credentials, &block)
  if credentials.is_a?(NSString)
    app_id = credentials
    credentials = {}
  else
    app_id = credentials[:app_id]
    raise "app_id is required in #{__method__}" unless app_id
  end
  permissions = credentials[:permissions] || ['email']
  audience = credentials[:audience] || ACFacebookAudienceOnlyMe
  loginToFacebookAppWithId(app_id, permissions:permissions, audience:audience, withCompletionBlock:block)
end

#login_to_twitter(credentials, &block) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/firebase-auth/firebase_auth_client.rb', line 66

def (credentials, &block)
  if credentials.is_a?(String)
    app_id = credentials
    credentials = {}
  else
    app_id = credentials[:app_id]
    raise "app_id is required in #{__method__}" unless app_id
  end
  on_multiple = credentials[:on_multiple] || ->(accounts) { accounts[0] }
  loginToTwitterAppWithId(app_id, multipleAccountsHandler:on_multiple, withCompletionBlock:block)
end

#remove(credentials, &block) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/firebase-auth/firebase_auth_client.rb', line 23

def remove(credentials, &block)
  raise "email is required in #{__method__}" unless credentials.key?(:email)
  raise "password is required in #{__method__}" unless credentials.key?(:password)
  email = credentials[:email]
  password = credentials[:password]
  removeUserWithEmail(email, password:password, andCompletionBlock:block)
end

#update(credentials, &block) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/firebase-auth/firebase_auth_client.rb', line 43

def update(credentials, &block)
  raise "email is required in #{__method__}" unless credentials.key?(:email)
  raise "old_password is required in #{__method__}" unless credentials.key?(:old_password)
  raise "new_password is required in #{__method__}" unless credentials.key?(:new_password)
  email = credentials[:email]
  old_password = credentials[:old_password]
  new_password = credentials[:new_password]
  changePasswordForEmail(email, oldPassword:old_password, newPassword:new_password, completionBlock:block)
end