motion-firebase 2.1.5 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +192 -64
  3. data/lib/firebase-auth/firebase_simple_login.rb +0 -76
  4. data/lib/firebase/fdata_snapshot.rb +4 -0
  5. data/lib/firebase/firebase.rb +53 -42
  6. data/lib/firebase/firebase_auth.rb +219 -0
  7. data/lib/firebase/firebase_facebook_helper.rb +24 -0
  8. data/lib/firebase/firebase_github_helper.rb +20 -0
  9. data/lib/firebase/firebase_twitter_helper.rb +169 -0
  10. data/lib/firebase/fquery.rb +16 -4
  11. data/lib/firebase/version.rb +2 -1
  12. data/lib/motion-firebase-auth.rb +3 -11
  13. data/lib/motion-firebase.rb +3 -1
  14. metadata +6 -19
  15. data/lib/vendor/Firebase.framework/Firebase +0 -0
  16. data/lib/vendor/Firebase.framework/Versions/A/Firebase +0 -0
  17. data/lib/vendor/Firebase.framework/Versions/A/Headers/FDataSnapshot.h +0 -146
  18. data/lib/vendor/Firebase.framework/Versions/A/Headers/FEventType.h +0 -43
  19. data/lib/vendor/Firebase.framework/Versions/A/Headers/FMutableData.h +0 -139
  20. data/lib/vendor/Firebase.framework/Versions/A/Headers/FQuery.h +0 -229
  21. data/lib/vendor/Firebase.framework/Versions/A/Headers/FTransactionResult.h +0 -50
  22. data/lib/vendor/Firebase.framework/Versions/A/Headers/Firebase.h +0 -707
  23. data/lib/vendor/Firebase.framework/build-MacOSX/Firebase.framework.bridgesupport +0 -582
  24. data/lib/vendor/Firebase.framework/build-iPhoneSimulator/Firebase.framework.bridgesupport +0 -582
  25. data/lib/vendor/FirebaseSimpleLogin.framework/FirebaseSimpleLogin +0 -0
  26. data/lib/vendor/FirebaseSimpleLogin.framework/Versions/A/FirebaseSimpleLogin +0 -0
  27. data/lib/vendor/FirebaseSimpleLogin.framework/Versions/A/Headers/FATypes.h +0 -52
  28. data/lib/vendor/FirebaseSimpleLogin.framework/Versions/A/Headers/FAUser.h +0 -97
  29. data/lib/vendor/FirebaseSimpleLogin.framework/Versions/A/Headers/FirebaseSimpleLogin.h +0 -221
  30. data/lib/vendor/FirebaseSimpleLogin.framework/build-MacOSX/FirebaseSimpleLogin.framework.bridgesupport +0 -230
  31. data/lib/vendor/FirebaseSimpleLogin.framework/build-iPhoneSimulator/FirebaseSimpleLogin.framework.bridgesupport +0 -230
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d26b48687a912b80502384f04a0d47a9a6904fef
4
- data.tar.gz: 9b9778de86540a6c6c71913137d48ae1e7f4a70a
3
+ metadata.gz: b20746e49429ffd9ecbea7ba992defdb3d70e4d9
4
+ data.tar.gz: b476715c9efb45dd9d6876948354c6b7c20188e9
5
5
  SHA512:
6
- metadata.gz: 63dc6b37f757172b7f30ad340288ec1d61017811321c5910599c1d70a480e3cebb12c8805a8032c9263e72441bad9e1abf9e5ccfc687cf231d21ba241f596c6b
7
- data.tar.gz: a1aa08af4823fe45f81d8449d552bc82b45915d1f13217dc1b6492f21bb1db4a31392a8c032b7734263dd53ecfc00752e4baaf9ad47cbc2fe1de3439acba7cf4
6
+ metadata.gz: 25e5edfd58e5dc43f8602f1ce879c90e56424625becd3370d4f6215432f9ec4d2e190dda858170372851188c938d1f4d753c99bebac1920a615d2f0f3fcceae4
7
+ data.tar.gz: 95b3e16250ce1670813d7d76a7581077420f1eb9edf26441e0daecbe27a982f8ebc8c0c560249a09f925ceec33e5585b5ef0c546ce62d6f63a15852fe36c1485
data/README.md CHANGED
@@ -7,21 +7,39 @@ Adds more rubyesque methods to the built-in classes.
7
7
 
8
8
  For a Ruby (MRI) Firebase wrapper, check out <https://github.com/derailed/bigbertha>.
9
9
 
10
- Versioning
11
- -------
10
+ Installation
11
+ ============
12
12
 
13
- Versioning matches Firebase's SDK major and minor version numbers, but revision
14
- numbers could be different.
13
+ The **motion-firebase** gem ships with "freeze dried" copies of the Firebase
14
+ framework. This way we can guarantee that the version of **motion-firebase** is
15
+ *definitely* compatible with the version of Firebase that is included. As new
16
+ features get announced, we update the gem.
15
17
 
16
- SDK
17
- ---
18
+ Also, it means that installation is easy! When you compile your RubyMotion
19
+ project, the Firebase SDK gets included automatically.
18
20
 
19
- # Firebase Class Reference
21
+ motion-firebase 3.0
22
+ ========
23
+
24
+ Lots of changes in this version: <3.0.md>
25
+
26
+ # SDK
20
27
 
21
28
  ##### Initializing a Firebase object
22
29
 
23
30
  ```ruby
24
31
  Firebase.new(url)
32
+
33
+ # it's common to set a global firebase URL. Set it in your app delegate,
34
+ # and calling `new` will use that default URL.
35
+ Firebase.url = 'https://your-app.firebaseio.com'
36
+ Firebase.url # => 'https://your-app.firebaseio.com'
37
+ Firebase.new
38
+
39
+ # these all work, too:
40
+ Firebase.url = 'your-app.firebaseio.com'
41
+ Firebase.url = 'your-app'
42
+ Firebase.url # => 'https://your-app.firebaseio.com'
25
43
  ```
26
44
 
27
45
  ##### Getting references to children locations
@@ -72,6 +90,16 @@ SDK
72
90
 
73
91
  ##### Attaching observers to read data
74
92
 
93
+ [Events](https://www.firebase.com/docs/web/guide/retrieving-data.html) can have the value of:
94
+
95
+ ```ruby
96
+ :child_added, :added, FEventTypeChildAdded
97
+ :child_moved, :moved, FEventTypeChildMoved
98
+ :child_changed, :changed, FEventTypeChildChanged
99
+ :child_removed, :removed, FEventTypeChildRemoved
100
+ :value, FEventTypeValue
101
+ ```
102
+
75
103
  ```ruby
76
104
  handle = firebase.on(event_type) { |snapshot| 'completion block' }
77
105
  handle = firebase.on(event_type) { |snapshot, previous_sibling_name| 'completion block' }
@@ -107,6 +135,12 @@ SDK
107
135
  firebase.start_at(priority, child: child_name)
108
136
  # => firebase.queryStartingAtPriority(priority, andChildName: child_name)
109
137
 
138
+ firebase.equal_to(priority)
139
+ # => firebase.queryEqualToPriority(priority)
140
+
141
+ firebase.equal_to(priority, child: child_name)
142
+ # => firebase.queryEqualToPriority(priority, andChildName: child_name)
143
+
110
144
  firebase.end_at(priority)
111
145
  # => firebase.queryEndingAtPriority(priority)
112
146
 
@@ -119,10 +153,26 @@ SDK
119
153
 
120
154
  ##### Managing presence
121
155
 
156
+ SOO COOL! Play with these, you can *easily* create a presence system for your
157
+ real-time app or game.
158
+
122
159
  ```ruby
123
- firebase.online!
124
- firebase.offline!
125
- firebase.connected_state # returns a Firebase ref that changes value depending on connectivity
160
+ Firebase.online!
161
+ Firebase.offline!
162
+ Firebase.connected? # returns a Firebase ref that changes value depending on connectivity
163
+
164
+ # or you can pass in a block, this block will be called with the connected
165
+ # state as a bool:
166
+ handler = Firebase.connected? do |connected|
167
+ if connected
168
+ # so awesome
169
+ end
170
+ end
171
+ # you should turn it off when you're done, otherwise you'll have a memory leak
172
+ Firebase.off(handler)
173
+
174
+ # so what you do is get a ref to the authenticated user's "presence" value.
175
+ # Then, on_disconnect, set the value to 'false'.
126
176
  firebase.on_disconnect(value) # set the ref to `value` when disconnected
127
177
  firebase.on_disconnect(value) { |error| 'completion block' }
128
178
  firebase.on_disconnect(value, priority: priority)
@@ -131,34 +181,12 @@ SDK
131
181
  firebase.on_disconnect(nil) { |error| 'completion block' }
132
182
  firebase.on_disconnect({ child: values })
133
183
  firebase.on_disconnect({ child: values }) { |error| 'completion block' }
184
+
185
+ # sometimes you need to cancel these 'on_disconnect' operations
134
186
  firebase.cancel_disconnect
135
187
  firebase.cancel_disconnect { |error| 'completion block' }
136
188
  ```
137
189
 
138
- ##### Authenticating
139
-
140
- ```ruby
141
- firebase.auth(secret_key)
142
- firebase.auth(secret_key) { |error, data| 'completion block' }
143
- firebase.auth(secret_key,
144
- completion: proc { |error, data| 'completion block' },
145
- disconnect: proc { |error| 'completion block', },
146
- )
147
- # calls `unauth`, or if you pass a block calls `unauthWithCompletionBlock`
148
- firebase.unauth
149
- firebase.unauth do |error|
150
- # ...
151
- end
152
- # when using FirebaseSimpleLogin to authenticate, this child node should be
153
- # monitored for changes
154
- firebase.auth_state
155
- # usually you'll want to monitor its value, so this is a helper for that:
156
- handle = firebase.on_auth do |snapshot|
157
- end
158
- # be a good citizen and turn off the listener later!
159
- firebase.off(handle)
160
- ```
161
-
162
190
  ##### Transactions
163
191
 
164
192
  ```ruby
@@ -204,72 +232,172 @@ SDK
204
232
  ```ruby
205
233
  Firebase.dispatch_queue=(queue)
206
234
  Firebase.sdkVersion
235
+ Motion::Firebase::SdkVersion # this string is more human readable than sdkVersion
207
236
  ```
208
237
 
209
- # FirebaseSimpleLogin Class Reference
210
238
 
211
- require 'motion-firebase-auth'
239
+ # Firebase Authentication Reference
240
+
241
+ Most of the authentication methods can be called statically as long as you have
242
+ set a default `Firebase.url`
212
243
 
213
- ##### Initializing a FirebaseSimpleLogin instance
244
+ ##### Checking current authentication status
214
245
 
215
246
  ```ruby
216
- ref = Firebase.new(url)
217
- auth = FirebaseSimpleLogin.new(ref)
247
+ Firebase.authenticated? # => true/false
248
+ # you pretty much always need to hold a reference to the "handler"
249
+ auth_handler = Firebase.authenticated? do |auth_data|
250
+ if auth_data
251
+ # authenticated!
252
+ else
253
+ # not so much
254
+ end
255
+ end
256
+ # turn off the handler, otherwise, yeah, memory leaks.
257
+ Firebase.off_auth(auth_handler)
218
258
  ```
219
259
 
220
- ##### Checking current authentication status
260
+ ##### Authenticate with previous token
221
261
 
222
262
  ```ruby
223
- auth.check { |error, user| }
263
+ Firebase.auth(token) do |error, auth_data|
264
+ end
224
265
  ```
225
266
 
226
267
  ##### Removing any existing authentication
227
268
 
228
269
  ```ruby
229
- auth.logout
270
+ Firebase.logout
230
271
  ```
231
272
 
232
- ##### Email/password authentication methods
273
+ ## Email/password authentication methods
233
274
 
234
- `credentials` for `create,remove,login` should include `:email` and `:password`.
235
- For `update`, `credentials` should include `:email`, `:old_password` and
236
- `:new_password`.
275
+ This is the most common way to login. It allows Firebase to create users and
276
+ tokens.
237
277
 
238
278
  ```ruby
239
- auth.create(email: 'hello@example.com', password: '12345') { |error, user| }
240
- auth.remove(email: 'hello@example.com', password: '12345') { |error, user| }
241
- auth.login(email: 'hello@example.com', password: '12345') { |error, user| }
242
- auth.update(email: 'hello@example.com', old_password: '12345', new_password: '54321') { |error, success| }
279
+ Firebase.create_user(email: 'hello@example.com', password: '12345') { |error, auth_data| }
280
+ Firebase.remove_user(email: 'hello@example.com', password: '12345') { |error, auth_data| }
281
+ Firebase.login(email: 'hello@example.com', password: '12345') { |error, auth_data| }
282
+ Firebase.login_anonymously { |error, auth_data| }
283
+ Firebase.update_user(email: 'hello@example.com', old_password: '12345', new_password: '54321') { |error, success| }
284
+
285
+ auth_data.uid # is a globally unique user identifier
286
+ auth_data.token # can be stored (in a keychain!) to authenticate the same user again later
243
287
  ```
244
288
 
245
- ##### Facebook authentication methods
289
+ See <https://www.firebase.com/docs/ios/api/#fauthdata_properties> for other
290
+ `auth_data` properties.
291
+
292
+
293
+ ## Other authentication providers
294
+
295
+ ##### Facebook authentication
246
296
 
247
- `credentials` must include `:app_id`. `:permissions` defaults to `['email']` and
248
- `:audience` defaults to `ACFacebookAudienceOnlyMe`.
297
+ This Facebook helper is a port of the Objective-C code from
298
+ <https://www.firebase.com/docs/ios/guide/login/facebook.html>.
249
299
 
250
300
  ```ruby
251
- auth.login_to_facebook(app_id: '123abc') { |error, user| }
301
+ Firebase.open_facebook_session(
302
+ permissions: ['public_profile'], # these are the default values. if
303
+ allow_login_ui: true, # you're OK with them, they are
304
+ ) do |error, auth_data| # optional, so just provide a block.
305
+ end
252
306
  ```
253
307
 
254
- ##### Twitter authentication methods
308
+ ##### Twitter authentication
255
309
 
256
- `credentials` should include `:app_id` and `:on_multiple` block. The
257
- `:on_multiple` block is called when more than one account is found. It is
258
- passed an array of usernames and should return an index or `NSNotFound`.
310
+ This Twitter helper is a port of the Objective-C code from
311
+ <https://www.firebase.com/docs/ios/guide/login/twitter.html>. You should read
312
+ that page to see how Firebase recommends handling multiple accounts. It's a
313
+ little streamlined here, since `open_twitter_session` returns a block that you
314
+ can call with the chosen account.
259
315
 
260
316
  ```ruby
261
- auth.login_to_twitter(app_id: '123abc', on_multiple: ->(usernames) { return 0 }) { |error, user| }
317
+ # it's nice to be able to set-and-forget the twitter_api_key (in your
318
+ # application delegate, for example)
319
+ Firebase.twitter_api_key = 'your key!'
320
+
321
+ # You must set Firebase.url=, or call open_twitter_session on an existing
322
+ # Firebase ref. The first step is to get the Twitter accounts on this
323
+ # device. Even if there is just one, you need to "choose" it here. Also,
324
+ # you can pass the twitter api_key as an option, otherwise this method will
325
+ # use Firebase.twitter_api_key
326
+ Firebase.open_twitter_session(api_key: 'your key!') do |error, accounts, next_step|
327
+ # next_step is a block you call with the chosen twitter account and a
328
+ # firebase handler for the authentication success or failure
329
+ if error
330
+ # obviously do some stuff here
331
+ else
332
+ present_twitter_chooser(accounts, next_step) do |error, auth_data|
333
+ # this block is passed to next_step in present_twitter_chooser
334
+ if error
335
+ # bummer
336
+ else
337
+ # awesome!
338
+ end
339
+ end
340
+ else
341
+ end
342
+
343
+ def present_twitter_chooser(accounts, next_step, &firebase_handler)
344
+ if accounts.length == 1
345
+ next_step.call(accounts[0], &firebase_handler)
346
+ else
347
+ # present a controller or action sheet or something like that
348
+ ... awesome twitter account chooser code ...
349
+ next_step.call(account, &firebase_handler)
350
+ end
351
+ end
262
352
  ```
263
353
 
264
- ##### Global configuration and settings
354
+ ##### Github authentication
355
+
356
+ Firebase doesn't provide much help on this one. I'm not even sure *how* to get
357
+ a github access token from the user... but anyway here's the `motion-firebase`
358
+ code based on <https://www.firebase.com/docs/ios/guide/login/github.html>.
265
359
 
266
360
  ```ruby
267
- FirebaseSimpleLogin.sdkVersion
361
+ Firebase.github_token = 'github oauth token'
362
+ Firebase.open_github_session do |error, auth_data|
363
+ end
268
364
  ```
269
365
 
270
- ##### Retrieving String Representation
366
+ ##### Google authentication
367
+
368
+ This process is more involved, and relies on the GooglePlus framework. I didn't
369
+ take the time to port the code this time, but I hope someone does someday! 😄
370
+
371
+ You can read Firebase's instructions here: <https://www.firebase.com/docs/ios/guide/login/google.html>
271
372
 
272
373
  ```ruby
273
- firebase.to_s
274
- firebase.inspect
374
+ Firebase.google_token = 'google oauth token'
375
+ Firebase.open_google_session do |error, auth_data|
376
+ end
377
+ ```
378
+
379
+ ##### Generic OAuth Authentication
380
+
381
+ Usually you will use the helpers from above, but here are some lower level
382
+ methods:
383
+
384
+ ```ruby
385
+ # using a token
386
+ firebase_ref.login_to_oauth(provider, token: token) do |error, auth_data| .. end
387
+ firebase_ref.login_to_oauth(provider, token) do |error, auth_data| .. end
388
+
389
+ # using parameters
390
+ firebase_ref.login_to_oauth(provider, oauth_token: token, oauth_token_secret: secret) do |error, auth_data| .. end
391
+ params = { ... }
392
+ firebase_ref.login_to_oauth(provider, params) do |error, auth_data| .. end
393
+
394
+ # which is a wrapper for these SDK methods:
395
+ firebase_ref.authWithOAuthProvider(provider, token: token, withCompletionBlock: block)
396
+ firebase_ref.authWithOAuthProvider(provider, parameters: params, withCompletionBlock: block)
397
+
398
+ # Again, the `open_*_session` methods are even more convenient.
399
+ firebase_ref.login_to_facebook(facebook_access_token, &block)
400
+ firebase_ref.login_to_twitter(token: token, secret: secret, &block)
401
+ firebase_ref.login_to_github(github_oauth_token, &block)
402
+ firebase_ref.login_to_google(google_oauth_token, &block)
275
403
  ```
@@ -12,38 +12,6 @@ class FirebaseSimpleLogin
12
12
  checkAuthStatusWithBlock(and_then)
13
13
  end
14
14
 
15
- def create(credentials, &block)
16
- raise "email is required in #{__method__}" unless credentials.key?(:email)
17
- raise "password is required in #{__method__}" unless credentials.key?(:password)
18
- email = credentials[:email]
19
- password = credentials[:password]
20
- begin
21
- createUserWithEmail(email, password: password, andCompletionBlock: block)
22
- rescue RuntimeError => e
23
- block.call(e, nil)
24
- end
25
- end
26
-
27
- def remove(credentials, &block)
28
- raise "email is required in #{__method__}" unless credentials.key?(:email)
29
- raise "password is required in #{__method__}" unless credentials.key?(:password)
30
- email = credentials[:email]
31
- password = credentials[:password]
32
- removeUserWithEmail(email, password: password, andCompletionBlock: block)
33
- end
34
-
35
- def login(credentials, &block)
36
- raise "email is required in #{__method__}" unless credentials.key?(:email)
37
- raise "password is required in #{__method__}" unless credentials.key?(:password)
38
- email = credentials[:email]
39
- password = credentials[:password]
40
- begin
41
- loginWithEmail(email, andPassword: password, withCompletionBlock: block)
42
- rescue RuntimeError => e
43
- block.call(e, nil)
44
- end
45
- end
46
-
47
15
  def update(credentials, &block)
48
16
  raise "email is required in #{__method__}" unless credentials.key?(:email)
49
17
  raise "old_password is required in #{__method__}" unless credentials.key?(:old_password)
@@ -54,48 +22,4 @@ class FirebaseSimpleLogin
54
22
  changePasswordForEmail(email, oldPassword: old_password, newPassword: new_password, completionBlock: block)
55
23
  end
56
24
 
57
- def send_password_reset(email, &block)
58
- sendPasswordResetForEmail(email, andCompletionBlock: block)
59
- end
60
-
61
- def login_to_facebook(credentials, &block)
62
- if credentials.is_a?(NSString)
63
- app_id = credentials
64
- credentials = {}
65
- else
66
- app_id = credentials[:app_id]
67
- raise "app_id is required in #{__method__}" unless app_id
68
- end
69
- permissions = credentials[:permissions] || ['email']
70
- audience = credentials[:audience] || ACFacebookAudienceOnlyMe
71
- loginToFacebookAppWithId(app_id, permissions: permissions, audience: audience, withCompletionBlock: block)
72
- end
73
-
74
- def login_to_twitter(credentials, &block)
75
- if credentials.is_a?(NSString)
76
- app_id = credentials
77
- credentials = {}
78
- else
79
- app_id = credentials[:app_id]
80
- raise "app_id is required in #{__method__}" unless app_id
81
- end
82
- on_multiple = credentials[:on_multiple] || ->(accounts) { 0 }
83
- loginToTwitterAppWithId(app_id, multipleAccountsHandler: on_multiple, withCompletionBlock: block)
84
- end
85
-
86
- def login_to_google(credentials, &block)
87
- if credentials.is_a?(NSString)
88
- app_id = credentials
89
- credentials = {}
90
- else
91
- app_id = credentials[:app_id]
92
- raise "app_id is required in #{__method__}" unless app_id
93
- end
94
- loginToGoogleWithAccessToken(app_id, withCompletionBlock: block)
95
- end
96
-
97
- def login_anonymously(&block)
98
- loginAnonymouslywithCompletionBlock(block)
99
- end
100
-
101
25
  end
@@ -16,4 +16,8 @@ class FDataSnapshot
16
16
  end
17
17
  end
18
18
 
19
+ def value?
20
+ to_bool
21
+ end
22
+
19
23
  end