motion-firebase 1.0.8 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -105,6 +105,14 @@ SDK
105
105
  disconnect: proc { |error| 'completion block', },
106
106
  )
107
107
  firebase.unauth
108
+ # when using FirebaseAuthClient to authenticate, this child node should be
109
+ # monitored for changes
110
+ firebase.auth_state
111
+ # usually you'll want to monitor its value, so this is a helper for that:
112
+ handle = firebase.on_auth do |snapshot|
113
+ end
114
+ # be a good citizen and turn off the listener later!
115
+ firebase.off(handle)
108
116
 
109
117
  ##### Transactions
110
118
 
@@ -166,7 +174,7 @@ For `update`, `credentials` should include `:email`, `:old_password` and
166
174
 
167
175
  `credentials` should include `:app_id` and `:permissions`
168
176
 
169
- auth.login_facebook(app_id: '123abc', permissions: ['email']) { |error, user| }
177
+ auth.login_to_facebook(app_id: '123abc', permissions: ['email']) { |error, user| }
170
178
 
171
179
  ##### Twitter authentication methdos
172
180
 
@@ -147,6 +147,10 @@ class Firebase
147
147
  return self
148
148
  end
149
149
 
150
+ def on_auth(options={}, &block)
151
+ auth_state.on(:value, options, &block)
152
+ end
153
+
150
154
  def on_disconnect(value, &and_then)
151
155
  if and_then
152
156
  if value.nil?
@@ -1,5 +1,5 @@
1
1
  module Motion
2
2
  module Firebase
3
- Version = '1.0.8'
3
+ Version = '1.0.9'
4
4
  end
5
5
  end
@@ -9,57 +9,74 @@ class FirebaseAuthClient
9
9
  end
10
10
 
11
11
  def create(credentials, &block)
12
+ raise "email is required in #{__method__}" unless credentials.key?(:email)
13
+ raise "password is required in #{__method__}" unless credentials.key?(:password)
12
14
  email = credentials[:email]
13
- raise "email is required in #{__method__}" unless email
14
15
  password = credentials[:password]
15
- raise "password is required in #{__method__}" unless password
16
- createUserWithEmail(email, password:password, andCompletionBlock:block)
16
+ begin
17
+ createUserWithEmail(email, password:password, andCompletionBlock:block)
18
+ rescue RuntimeError => e
19
+ block.call(e, nil)
20
+ end
17
21
  end
18
22
 
19
23
  def remove(credentials, &block)
24
+ raise "email is required in #{__method__}" unless credentials.key?(:email)
25
+ raise "password is required in #{__method__}" unless credentials.key?(:password)
20
26
  email = credentials[:email]
21
- raise "email is required in #{__method__}" unless email
22
27
  password = credentials[:password]
23
- raise "password is required in #{__method__}" unless password
24
28
  removeUserWithEmail(email, password:password, andCompletionBlock:block)
25
29
  end
26
30
 
27
31
  def login(credentials, &block)
32
+ raise "email is required in #{__method__}" unless credentials.key?(:email)
33
+ raise "password is required in #{__method__}" unless credentials.key?(:password)
28
34
  email = credentials[:email]
29
- raise "email is required in #{__method__}" unless email
30
35
  password = credentials[:password]
31
- raise "password is required in #{__method__}" unless password
32
- loginWithEmail(email, andPassword:password, withCompletionBlock:block)
36
+ begin
37
+ loginWithEmail(email, andPassword:password, withCompletionBlock:block)
38
+ rescue RuntimeError => e
39
+ block.call(e, nil)
40
+ end
33
41
  end
34
42
 
35
43
  def update(credentials, &block)
44
+ raise "email is required in #{__method__}" unless credentials.key?(:email)
45
+ raise "old_password is required in #{__method__}" unless credentials.key?(:old_password)
46
+ raise "new_password is required in #{__method__}" unless credentials.key?(:new_password)
36
47
  email = credentials[:email]
37
- raise "email is required in #{__method__}" unless email
38
48
  old_password = credentials[:old_password]
39
- raise "old_password is required in #{__method__}" unless old_password
40
49
  new_password = credentials[:new_password]
41
- raise "new_password is required in #{__method__}" unless new_password
42
50
  changePasswordForEmail(email, oldPassword:old_password, newPassword:new_password, completionBlock:block)
43
51
  end
44
52
 
45
- def login_facebook(credentials, &block)
46
- app_id = credentials[:app_id]
47
- raise "app_id is required in #{__method__}" unless app_id
48
- permissions = credentials[:permissions]
49
- raise "permissions is required in #{__method__}" unless permissions
50
- loginToFacebookAppWithId(app_id, permissions:permissions, withCompletionBlock:block)
53
+ def login_to_facebook(credentials, &block)
54
+ if credentials.is_a?(NSString)
55
+ app_id = credentials
56
+ credentials = {}
57
+ else
58
+ app_id = credentials[:app_id]
59
+ raise "app_id is required in #{__method__}" unless app_id
60
+ end
61
+ permissions = credentials[:permissions] || ['email']
62
+ audience = credentials[:audience] || ACFacebookAudienceOnlyMe
63
+ loginToFacebookAppWithId(app_id, permissions:permissions, audience:audience, withCompletionBlock:block)
51
64
  end
52
65
 
53
66
  def login_to_twitter(credentials, &block)
54
- app_id = credentials[:app_id]
55
- raise "app_id is required in #{__method__}" unless app_id
56
- on_multiple = credentials[:on_multiple]
57
- raise "on_multiple is required in #{__method__}" unless on_multiple
67
+ if credentials.is_a?(String)
68
+ app_id = credentials
69
+ credentials = {}
70
+ else
71
+ app_id = credentials[:app_id]
72
+ raise "app_id is required in #{__method__}" unless app_id
73
+ end
74
+ on_multiple = credentials[:on_multiple] || ->(accounts) { accounts[0] }
58
75
  loginToTwitterAppWithId(app_id, multipleAccountsHandler:on_multiple, withCompletionBlock:block)
59
76
  end
60
77
 
61
- def inspect
62
- "#<#{self.class}:0x#{self.object_id.to_s(16)}>"
63
- end
78
+ # def inspect
79
+ # "#<#{self.class}:0x#{self.object_id.to_s(16)}>"
80
+ # end
64
81
 
65
82
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion-firebase
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-19 00:00:00.000000000 Z
12
+ date: 2013-04-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec