motion-firebase 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ nbproject
15
15
  .sass-cache
16
16
  .idea
17
17
  *.gem
18
+ /.dat*
data/README.md CHANGED
@@ -3,7 +3,7 @@ motion-firebase
3
3
 
4
4
  A RubyMotion wrapper for the Firebase SDK.
5
5
 
6
- Just the main class `Firebase` is wrapped.
6
+ Adds more rubyesque methods to the built-in classes.
7
7
 
8
8
  Versioning
9
9
  -------
@@ -16,17 +16,6 @@ SDK
16
16
 
17
17
  # Firebase Class Reference
18
18
 
19
- ## Overview
20
-
21
- A `Firebase` reference represents a particular location in your Firebase and can
22
- be used for reading or writing data to that Firebase location.
23
-
24
- This class is the starting point for all Firebase operations. After you’ve
25
- initialized it with `Firebase.new` you can use it to read data (ie. `on() {}`),
26
- write data (ie. `[key]=`), and to create new Firebase references (ie. `[]`).
27
-
28
- ## Tasks
29
-
30
19
  ##### Initializing a Firebase object
31
20
 
32
21
  Firebase.new(url)
@@ -133,6 +122,7 @@ write data (ie. `[key]=`), and to create new Firebase references (ie. `[]`).
133
122
  ##### Retrieving String Representation
134
123
 
135
124
  firebase.to_s
125
+ firebase.inspect
136
126
 
137
127
  ##### Properties
138
128
 
@@ -146,366 +136,51 @@ write data (ie. `[key]=`), and to create new Firebase references (ie. `[]`).
146
136
  Firebase.sdkVersion
147
137
 
148
138
 
149
- ## Properties
150
-
151
- #### name
152
-
153
- Gets last token in a Firebase location (e.g. ‘fred’ in https://SampleChat.firebaseIO-demo.com/users/fred))
154
-
155
- ###### Return Value
156
-
157
- The name of the location this reference points to.
158
-
159
-
160
- #### parent
161
-
162
- Get a Firebase reference for the parent location. If this instance refers to the
163
- root of your Firebase, it has no parent, and therefore parent( ) will return `nil`.
164
-
165
- ###### Return Value
166
-
167
- A Firebase reference for the parent location.
168
-
169
-
170
- #### root
171
-
172
- Get a Firebase reference for the root location
173
-
174
- ###### Return Value
175
-
176
- A new Firebase reference to root location.
177
-
178
-
179
- ## Class Methods
180
-
181
- #### sdkVersion
182
-
183
- Retrieve the Firebase SDK version.
184
-
185
-
186
- #### dispatch_queue=(queue)
187
-
188
- Set the default dispatch queue for event blocks.
189
-
190
- ###### Parameters
191
-
192
- queue
193
- *The queue to set as the default for running blocks for all Firebase event
194
- types.*
195
-
196
- ## Instance Methods
197
-
198
-
199
- #### auth(credential, options={}, &and_then) { |error| }
200
-
201
- ###### Parameters
202
-
203
- Authenticate access to this Firebase using the provided credentials. The
204
- completion block will be called with the results of the authenticated attempt,
205
- and the disconnect block will be called if the credentials become invalid at
206
- some point after authentication has succeeded.
207
-
208
- credential
209
- *The Firebase authentication JWT generated by a secure code on a remote server.*
210
-
211
- and_then || options[:completion]
212
- *This block will be called with the results of the authentication attempt*
213
-
214
- options[:disconnect]
215
- *This block will be called if at any time in the future the credentials become
216
- invalid*
217
-
218
-
219
- #### cancel_disconnect(&and_then)
220
-
221
- Cancel any operations that are set to run on disconnect. If you previously
222
- called `on_disconnect`, and no longer want the values updated when the
223
- connection is lost, call `cancel_disconnect`
224
-
225
- ###### Parameters
226
-
227
- and_then
228
- *A block that will be triggered once the Firebase servers have acknowledged the
229
- cancel request.*
230
-
231
-
232
- #### [](*children)
233
-
234
- Get a Firebase reference for the location at the specified relative path. The
235
- relative path can either be a simple child name (e.g. ‘fred’) or a deeper
236
- slash-separated path (e.g. ‘fred/name/first’).
237
-
238
- firebase['fred']
239
- firebase['fred/name/first']
240
- firebase['fred', 'name', 'first']
241
-
242
- ###### Parameters
243
-
244
- children
245
- *A relative path from this location to the desired child location(s).*
246
-
247
- ###### Return Value
248
-
249
- A Firebase reference for the specified relative path.
250
-
251
-
252
- #### []
253
-
254
- `firebase[]` generates a new child location using a unique name and returns a
255
- Firebase reference to it. This is useful when the children of a Firebase
256
- location represent a list of items.
257
-
258
- The unique name generated by `firebase[]` is prefixed with a client-generated
259
- timestamp so that the resulting list will be chronologically-sorted.
260
-
261
- ###### Return Value
262
-
263
- A Firebase reference for the generated location.
264
-
265
-
266
- #### to_s
267
-
268
- Gets the absolute URL of this Firebase location.
269
-
270
-
271
- #### Firebase.new(url)
272
-
273
- Initialize this Firebase reference with an absolute URL.
274
-
275
- ###### Parameters
139
+ # FirebaseAuthClient Class Reference
276
140
 
277
- url
278
- *The Firebase URL (ie: https://SampleChat.firebaseIO-demo.com)*
141
+ ##### Initializing a FirebaseAuthClient instance
279
142
 
143
+ ref = Firebase.new(url)
144
+ auth = FirebaseAuthClient.new(ref)
280
145
 
281
- #### on(event_type, options, &and_then) { |snapshot| }
282
- #### on(event_type, options, &and_then) { |snapshot, previous_sibling_name| }
146
+ ##### Checking current authentication status
283
147
 
284
- `on()` is used to listen for data changes at a particular location. This is the
285
- primary way to read data from Firebase. Your block will be triggered for the
286
- initial data and again whenever the data changes.
148
+ auth.check { |error, user| }
287
149
 
288
- If the block accepts two arguments, events of type `:added`, `:moved`, and
289
- `:changed` will be passed the name of the previous node by priority order.
150
+ ##### Removing any existing authentication
290
151
 
291
- Use `off(handle)` to stop receiving updates.
152
+ auth.logout
292
153
 
293
- Supported events types for all realtime observers are specified as:
154
+ ##### Email/password authentication methods
294
155
 
295
- :added # fired when a new child node is added to a location
296
- :removed # fired when a child node is removed from a location
297
- :changed # fired when a child node at a location changes
298
- :moved # fired when a child node moves relative to the other child nodes at a location
299
- :value # fired when any data changes at a location and, recursively, any children
156
+ `credentials` for `create,remove,login` should include `:email` and `:password`.
157
+ For `update`, `credentials` should include `:email`, `:old_password` and
158
+ `:new_password`.
300
159
 
301
- ###### Parameters
160
+ auth.create(email: 'hello@example.com', password: '12345') { |error, user| }
161
+ auth.remove(email: 'hello@example.com', password: '12345') { |error, user| }
162
+ auth.login(email: 'hello@example.com', password: '12345') { |error, user| }
163
+ auth.update(email: 'hello@example.com', old_password: '12345', new_password: '54321') { |error, success| }
302
164
 
303
- event_type
304
- *The type of event to listen for.*
165
+ ##### Facebook authentication methods
305
166
 
306
- and_then || options[:completion]
307
- *The block that should be called with initial data and updates as a
308
- `FDataSnapshot`, and optionally the previous child’s name.*
167
+ `credentials` should include `:app_id` and `:permissions`
309
168
 
310
- options[:disconnect]
311
- *The block that should be called if this client no longer has permission to
312
- receive these events*
169
+ auth.login_facebook(app_id: '123abc', permissions: ['email']) { |error, user| }
313
170
 
314
- ###### Return Value
171
+ ##### Twitter authentication methdos
315
172
 
316
- A handle used to unregister this block later using `off(handle)`
173
+ `credentials` should include `:app_id` and `:on_multiple` block. The
174
+ `:on_multiple` block is called when more than one account is found. It is
175
+ passed an array of usernames and should return an index or `NSNotFound`.
317
176
 
177
+ auth.login_to_twitter(app_id: '123abc', on_multiple: ->(usernames) { return 0 }) { |error, user| }
318
178
 
319
- #### once(event_type, options, &and_then) { |snapshot| }
320
- #### once(event_type, options, &and_then) { |snapshot, previous_sibling_name| }
321
-
322
- #### observeSingleEventOfType:andPreviousSiblingNameWithBlock:
323
-
324
- This is equivalent to `on()`, except the block is immediately canceled after the
325
- initial data is returned.
326
-
327
- If the block accepts two arguments, events of type `:added`, `:moved`, and
328
- `:changed` will be passed the name of the previous node by priority order.
329
-
330
- ###### Parameters
331
-
332
- event_type
333
- *The type of event to listen for.*
334
-
335
- and_then || options[:completion]
336
- *The block that should be called with initial data and updates as a
337
- `FDataSnapshot`, and optionally the previous child’s name.*
338
-
339
- options[:disconnect]
340
- *The block that should be called if this client no longer has permission to
341
- receive these events*
342
-
343
-
344
- #### on_disconnect(nil, &and_then) { |error| }
345
- #### on_disconnect(value, &and_then) { |error| }
346
- #### on_disconnect(values, &and_then) { |error| }
347
- #### on_disconnect(value, priority:priority, &and_then) { |error| }
348
-
349
- Ensure the data at this location is removed when the client is disconnected (due
350
- to closing the app, navigating to a new page, or network issues).
351
-
352
- `on_disconnect` is especially useful for implementing “presence” systems.
353
-
354
- ###### Parameters
355
- value
356
- *The value to be set after the connection is lost. Special value `nil` will
357
- remove the value, and a dictionary can be sent to update multiple child node
358
- names and the values to set them to.*
359
-
360
- priority
361
- *The priority to be set after the connection is lost.*
362
-
363
- and_then
364
- *Block to be triggered when the operation has been queued up on the Firebase
365
- servers*
366
-
367
-
368
- #### off
369
- #### off(handle)
370
-
371
- Detach a block previously attached with `on()`, or remove all observer events.
372
-
373
- ###### Parameters
374
- handle
375
- The handle returned by the call to observeEventType:withBlock: which we are
376
- trying to remove. If no handle is passed, all ovservers are removed.
377
-
378
-
379
- #### clear!(&and_then) { |error| }
380
-
381
- Remove the data at this Firebase location. Any data at child locations will also
382
- be deleted.
383
-
384
- The effect of the delete will be visible immediately and the corresponding
385
- events will be triggered. Synchronization of the delete to the Firebase servers
386
- will also be started.
387
-
388
- `clear!` is equivalent to calling `value(nil)`
389
-
390
- ###### Parameters
391
- and_then
392
- *The block to be called after the remove has been committed to the Firebase
393
- servers.*
394
-
395
- #### run(options={}, &transaction) { |data| }
396
-
397
- Performs an optimistic-concurrency transactional update to the data at this
398
- location. Your block will be called with an FMutableData instance that contains
399
- the current data at this location. Your block should update this data to the
400
- value you wish to write to this location, and then return an instance of
401
- FTransactionResult with the new data.
402
-
403
- If, when the operation reaches the server, it turns out that this client had
404
- stale data, your block will be run again with the latest data from the server.
405
-
406
- When your block is run, you may decide to abort the transaction by return
407
- `FTransactionResult.abort`.
408
-
409
- Since your block may be run multiple times, this client could see several
410
- immediate states that don’t exist on the server. You can suppress those
411
- immediate states until the server confirms the final state of the transaction.
412
-
413
- ###### Parameters
414
- transaction || options[:transaction]
415
- *This block receives the current data at this location and must return an
416
- instance of FTransactionResult*
417
-
418
- options[:completion]
419
- *This block will be triggered once the transaction is complete, whether it was
420
- successful or not. It will indicate if there was an error, whether or not the
421
- data was committed, and what the current value of the data at this location is.*
422
-
423
- options[:local]
424
- *Set this to `false` to suppress events raised for intermediate states, and only
425
- get events based on the final state of the transaction.*
426
-
427
-
428
- #### priority=(priority)
429
- #### priority(priority, &and_then) { |error| }
430
-
431
- Set a priority for the data at this Firebase location. Priorities can be used to
432
- provide a custom ordering for the children at a location (if no priorities are
433
- specified, the children are ordered by name).
434
-
435
- You cannot set a priority on an empty location. For this reason
436
- `value(priority:)` should be used when setting initial data with a specific
437
- priority and `priority()` should be used when updating the priority of existing
438
- data.
439
-
440
- Children are sorted based on this priority using the following rules:
441
-
442
- Children with no priority (a `nil` priority) come first. They are ordered
443
- lexicographically by name. Children with a priority that is parsable as a number
444
- come next. They are sorted numerically by priority first (small to large) and
445
- lexicographically by name second (A to z). Children with non-numeric priorities
446
- come last. They are sorted lexicographically by priority first and
447
- lexicographically by name second. Setting the priority to `nil` removes any
448
- existing priority. Note that priorities are parsed and ordered as IEEE 754
449
- double-precision floating-point numbers.
450
-
451
- ###### Parameters
452
- priority
453
- *The priority to set at the specified location.*
454
-
455
- and_then
456
- *The block that is triggered after the priority has been written on the
457
- servers.*
458
-
459
-
460
- #### value=(value)
461
- #### value(value)
462
-
463
- Write data to this Firebase location.
464
-
465
- This will overwrite any data at this location and all child locations.
466
-
467
- Data types that can be set are:
468
-
469
- String, 'Hello World'
470
- Numeric, Boolean — true, 43, 4.333
471
- Hash, {'key' => 'value', 'nested' => {'another': 'value' => }
472
- Array, []
473
-
474
- The effect of the write will be visible immediately and the corresponding events
475
- will be triggered. Synchronization of the data to the Firebase servers will also
476
- be started.
477
-
478
- Passing `nil` for the new value is equivalent to calling `clear!` all data at
479
- this location or any child location will be deleted.
480
-
481
- Note that `value` will remove any priority stored at this location, so if
482
- priority is meant to be preserved, you should use `value(priority:)` instead.
483
-
484
- Priorities are used to order items.
485
-
486
- ###### Parameters
487
- value
488
- *The value to be written.*
489
-
490
- priority
491
- *The priority to be attached to that data.*
492
-
493
-
494
- #### unauth
495
-
496
- Removes any credentials associated with this Firebase
497
-
498
-
499
- #### update(values)
500
- #### update(values, &and_then) { |error| }
501
-
502
- Update changes the values of the keys specified in the dictionary without
503
- overwriting other keys at this location.
179
+ ##### Global configuration and settings
504
180
 
505
- ###### Parameters
506
- values
507
- *A dictionary of the keys to change and their new values*
181
+ FirebaseAuthClient.sdkVersion
508
182
 
509
- and_then
510
- *The block that is triggered after the update has been written on the Firebase servers*
183
+ ##### Retrieving String Representation
511
184
 
185
+ firebase.to_s
186
+ firebase.inspect
data/app/app_delegate.rb CHANGED
@@ -54,7 +54,7 @@ class MyController < UIViewController
54
54
  self.chat = []
55
55
 
56
56
  # Initialize the root of our Firebase namespace.
57
- self.firebase = Firebase.alloc.initWithUrl(FirechatNS)
57
+ self.firebase = Firebase.new(FirechatNS)
58
58
 
59
59
  # Pick a random number between 1-1000 for our username.
60
60
  self.title = "Guest0x#{(rand * 1000).round.to_s(16).upcase}"
@@ -76,7 +76,7 @@ class MyController < UIViewController
76
76
 
77
77
  # This will also add the message to our local array self.chat because
78
78
  # the FEventTypeChildAdded event will be immediately fired.
79
- self.firebase[].setValue({'name' => self.title, 'text' => text_field.text})
79
+ self.firebase << {'name' => self.title, 'text' => text_field.text}
80
80
 
81
81
  text_field.text = ''
82
82
  false
@@ -1,5 +1,23 @@
1
1
  class Firebase
2
2
 
3
+ def self.convert_event_type(event_type)
4
+ case event_type
5
+ when :child_added, :added
6
+ return FEventTypeChildAdded
7
+ when :child_moved, :moved
8
+ FEventTypeChildMoved
9
+ when :child_changed, :changed
10
+ return FEventTypeChildChanged
11
+ when :child_removed, :removed
12
+ return FEventTypeChildRemoved
13
+ when :value
14
+ return FEventTypeValue
15
+ else
16
+ NSLog("Unknown event type #{event_type.inspect}")
17
+ end
18
+ return event_type
19
+ end
20
+
3
21
  def self.new(url)
4
22
  alloc.initWithUrl(url)
5
23
  end
@@ -120,63 +138,6 @@ class Firebase
120
138
  return self
121
139
  end
122
140
 
123
- def on(event_type, options={}, &and_then)
124
- and_then = and_then || options[:completion]
125
- raise "event handler is required" unless and_then
126
- raise "event handler must accept one or two arguments" unless and_then.arity == 1 || and_then.arity == 2
127
-
128
- event_type = Firebase._convert_event_type(event_type)
129
- disconnect_block = options[:disconnect]
130
- raise ":disconnect handler must not accept any arguments" if disconnect_block && disconnect_block.arity > 0
131
-
132
- if and_then.arity == 1
133
- if disconnect_block
134
- observeEventType(event_type, withBlock:and_then, withCancelBlock:disconnect_block)
135
- else
136
- observeEventType(event_type, withBlock:and_then)
137
- end
138
- else
139
- if disconnect_block
140
- observeEventType(event_type, andPreviousSiblingNameWithBlock:and_then, withCancelBlock:disconnect_block)
141
- else
142
- observeEventType(event_type, andPreviousSiblingNameWithBlock:and_then)
143
- end
144
- end
145
- end
146
-
147
- def once(event_type, options={}, &and_then)
148
- and_then = and_then || options[:completion]
149
- raise "event handler is required" unless and_then
150
- raise "event handler must accept one or two arguments" unless and_then.arity == 1 || and_then.arity == 2
151
-
152
- event_type = Firebase._convert_event_type(event_type)
153
- disconnect_block = options[:disconnect]
154
- raise ":disconnect handler must not accept any arguments" if disconnect_block && disconnect_block.arity > 0
155
-
156
- if and_then.arity == 1
157
- if disconnect_block
158
- observeSingleEventOfType(event_type, withBlock:and_then, withCancelBlock:disconnect_block)
159
- else
160
- observeSingleEventOfType(event_type, withBlock:and_then)
161
- end
162
- else
163
- if disconnect_block
164
- observeSingleEventOfType(event_type, andPreviousSiblingNameWithBlock:and_then, withCancelBlock:disconnect_block)
165
- else
166
- observeSingleEventOfType(event_type, andPreviousSiblingNameWithBlock:and_then)
167
- end
168
- end
169
- end
170
-
171
- def off(handle=nil)
172
- if handle
173
- removeObserverWithHandle(handle)
174
- else
175
- removeAllObservers
176
- end
177
- return self
178
- end
179
-
180
141
  def cancel_disconnect(&and_then)
181
142
  if and_then
182
143
  cancelDisconnectOperationsWithCompletionBlock(and_then)
@@ -220,23 +181,4 @@ class Firebase
220
181
  "#<#{self.class}:0x#{self.object_id.to_s(16)}>"
221
182
  end
222
183
 
223
- private
224
- def self._convert_event_type(event_type)
225
- case event_type
226
- when :child_added, :added
227
- return FEventTypeChildAdded
228
- when :child_moved, :moved
229
- FEventTypeChildMoved
230
- when :child_changed, :changed
231
- return FEventTypeChildChanged
232
- when :child_removed, :removed
233
- return FEventTypeChildRemoved
234
- when :value
235
- return FEventTypeValue
236
- else
237
- NSLog("Unknown event type #{event_type.inspect}")
238
- end
239
- return event_type
240
- end
241
-
242
184
  end
@@ -0,0 +1,76 @@
1
+ class FQuery
2
+
3
+ def on(event_type, options={}, &and_then)
4
+ and_then = and_then || options[:completion]
5
+ raise "event handler is required" unless and_then
6
+ raise "event handler must accept one or two arguments" unless and_then.arity == 1 || and_then.arity == 2
7
+
8
+ event_type = Firebase.convert_event_type(event_type)
9
+ disconnect_block = options[:disconnect]
10
+ raise ":disconnect handler must not accept any arguments" if disconnect_block && disconnect_block.arity > 0
11
+
12
+ if and_then.arity == 1
13
+ if disconnect_block
14
+ return observeEventType(event_type, withBlock:and_then, withCancelBlock:disconnect_block)
15
+ else
16
+ return observeEventType(event_type, withBlock:and_then)
17
+ end
18
+ else
19
+ if disconnect_block
20
+ return observeEventType(event_type, andPreviousSiblingNameWithBlock:and_then, withCancelBlock:disconnect_block)
21
+ else
22
+ return observeEventType(event_type, andPreviousSiblingNameWithBlock:and_then)
23
+ end
24
+ end
25
+ end
26
+
27
+ def once(event_type, options={}, &and_then)
28
+ and_then = and_then || options[:completion]
29
+ raise "event handler is required" unless and_then
30
+ raise "event handler must accept one or two arguments" unless and_then.arity == 1 || and_then.arity == 2
31
+
32
+ event_type = Firebase.convert_event_type(event_type)
33
+ disconnect_block = options[:disconnect]
34
+ raise ":disconnect handler must not accept any arguments" if disconnect_block && disconnect_block.arity > 0
35
+
36
+ if and_then.arity == 1
37
+ if disconnect_block
38
+ return observeSingleEventOfType(event_type, withBlock:and_then, withCancelBlock:disconnect_block)
39
+ else
40
+ return observeSingleEventOfType(event_type, withBlock:and_then)
41
+ end
42
+ else
43
+ if disconnect_block
44
+ return observeSingleEventOfType(event_type, andPreviousSiblingNameWithBlock:and_then, withCancelBlock:disconnect_block)
45
+ else
46
+ return observeSingleEventOfType(event_type, andPreviousSiblingNameWithBlock:and_then)
47
+ end
48
+ end
49
+ end
50
+
51
+ def off(handle=nil)
52
+ if handle
53
+ removeObserverWithHandle(handle)
54
+ else
55
+ removeAllObservers
56
+ end
57
+ return self
58
+ end
59
+
60
+ def start_at(priority)
61
+ queryStartingAtPriority(priority)
62
+ end
63
+
64
+ def start_at(priority, child:child)
65
+ queryStartingAtPriority(priority, andChildName:child)
66
+ end
67
+
68
+ def end_at(priority)
69
+ queryEndingAtPriority(priority)
70
+ end
71
+
72
+ def end_at(priority, child:child)
73
+ queryEndingAtPriority(priority, andChildName:child)
74
+ end
75
+
76
+ end
@@ -1,5 +1,5 @@
1
1
  module Motion
2
2
  module Firebase
3
- Version = '1.0.5'
3
+ Version = '1.0.6'
4
4
  end
5
5
  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.5
4
+ version: 1.0.6
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-17 00:00:00.000000000 Z
12
+ date: 2013-04-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -45,6 +45,7 @@ files:
45
45
  - app/app_delegate.rb
46
46
  - lib/firebase/firebase.rb
47
47
  - lib/firebase/firebase_auth_client.rb
48
+ - lib/firebase/fquery.rb
48
49
  - lib/firebase/version.rb
49
50
  - lib/motion-firebase-auth.rb
50
51
  - lib/motion-firebase-facebook.rb