parsecom 0.3.0 → 0.4.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.
- data/README.md +74 -12
- data/lib/parse/client.rb +2 -5
- data/lib/parse/file.rb +4 -1
- data/lib/parse/geo_point.rb +26 -0
- data/lib/parse/installation.rb +5 -1
- data/lib/parse/object.rb +4 -8
- data/lib/parse/query.rb +41 -0
- data/lib/parse/util.rb +11 -0
- data/lib/parse/version.rb +1 -1
- data/lib/parsecom.rb +2 -0
- data/spec/parse_query_spec.rb +20 -0
- metadata +4 -2
data/README.md
CHANGED
@@ -42,15 +42,16 @@ Yet-Another Parse.com Library written in Pure Ruby
|
|
42
42
|
- [Uploading Files](#uploading-files)
|
43
43
|
- [Associating with Objects](#associating-with-objects)
|
44
44
|
- [Deleting Files](#deleting-files)
|
45
|
-
- [Analytics](#analytics)
|
46
|
-
- [TBD](#tbd-2)
|
47
|
-
- [Push Notifications](#push-notifications)
|
48
|
-
- [TBD](#tbd-3)
|
49
45
|
- [Installations](#installations)
|
50
|
-
- [
|
46
|
+
- [Uploading Installation Data](#uploading-installation-data)
|
47
|
+
- [Retrieving Installations](#retrieving-installations)
|
48
|
+
- [Updating Installations](#updating-installations)
|
49
|
+
- [Querying Installations](#querying-installations)
|
50
|
+
- [Deleting Installations](#deleting-installations)
|
51
51
|
- [Cloud Functions](#cloud-functions)
|
52
52
|
- [GeoPoints](#geopoints)
|
53
|
-
- [
|
53
|
+
- [GeoPoint](#geopoint)
|
54
|
+
- [Geo Queries](#geo-queries)
|
54
55
|
- [Security](#security)
|
55
56
|
|
56
57
|
## Usage
|
@@ -345,7 +346,7 @@ game_scores = GameScore.find :where => proc {
|
|
345
346
|
|
346
347
|
#### Counting Objects
|
347
348
|
|
348
|
-
|
349
|
+
TBD
|
349
350
|
|
350
351
|
#### Compound Queries
|
351
352
|
|
@@ -404,7 +405,7 @@ user.delete
|
|
404
405
|
|
405
406
|
#### Linking Users
|
406
407
|
|
407
|
-
|
408
|
+
TBD
|
408
409
|
|
409
410
|
### Roles
|
410
411
|
|
@@ -487,15 +488,47 @@ file.delete!
|
|
487
488
|
|
488
489
|
### Analytics
|
489
490
|
|
490
|
-
|
491
|
+
TBD
|
491
492
|
|
492
493
|
### Push Notifications
|
493
494
|
|
494
|
-
|
495
|
+
TBD
|
495
496
|
|
496
497
|
### Installations
|
497
498
|
|
498
|
-
####
|
499
|
+
#### Uploading Installation Data
|
500
|
+
|
501
|
+
```ruby
|
502
|
+
installation = Parse::Installation.new :deviceType => 'ios', :deviceToken => '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef', :channels => ['']
|
503
|
+
installation.save
|
504
|
+
```
|
505
|
+
|
506
|
+
#### Retrieving Installations
|
507
|
+
|
508
|
+
```ruby
|
509
|
+
installation = Parse::Installation.find_by_id :mrmBZvsErB
|
510
|
+
```
|
511
|
+
|
512
|
+
#### Updating Installations
|
513
|
+
|
514
|
+
```ruby
|
515
|
+
installation = Parse::Installation.find_by_id :mrmBZvsErB
|
516
|
+
installation.channels = ['', 'foo']
|
517
|
+
installation.save
|
518
|
+
```
|
519
|
+
|
520
|
+
#### Querying Installations
|
521
|
+
|
522
|
+
```ruby
|
523
|
+
installations = Parse::Installation.find! :all
|
524
|
+
```
|
525
|
+
|
526
|
+
#### Deleting Installations
|
527
|
+
|
528
|
+
```ruby
|
529
|
+
installation = Parse::Installation.find_by_id :mrmBZvsErB
|
530
|
+
installation.delete!
|
531
|
+
```
|
499
532
|
|
500
533
|
### Cloud Functions
|
501
534
|
|
@@ -506,7 +539,36 @@ client.hello
|
|
506
539
|
|
507
540
|
### GeoPoints
|
508
541
|
|
509
|
-
####
|
542
|
+
#### GeoPoint
|
543
|
+
|
544
|
+
```ruby
|
545
|
+
geo_point = Parse::GeoPoint.new :latitude => 40.0, :longitude => -30.0
|
546
|
+
place = PlaceObject.new :location => geo_point
|
547
|
+
```
|
548
|
+
|
549
|
+
#### Geo Queries
|
550
|
+
|
551
|
+
```ruby
|
552
|
+
place = PlaceObject.find :limit => 10, :where => proc {
|
553
|
+
geo_point = Parse::GeoPoint.new :latitude => 30.0, :longitude => -20.0
|
554
|
+
column(:location).near_sphere geop_point
|
555
|
+
}
|
556
|
+
```
|
557
|
+
|
558
|
+
```ruby
|
559
|
+
places = PlaceObject.find :limit => 10, :where => proc {
|
560
|
+
geo_point = Parse::GeoPoint.new :latitude => 30.0, :longitude => -20.0
|
561
|
+
column(:location).near_sphere(geop_point).max_distance_in_miles(10.0)
|
562
|
+
}
|
563
|
+
```
|
564
|
+
|
565
|
+
```ruby
|
566
|
+
places = PizzaPlaceObject.find :limit => 10, :where => proc {
|
567
|
+
southwest = Parse::GeoPoint.new :latitude => 37.71, :longitude => -122.53
|
568
|
+
northeast = Parse::GeoPoint.new :latitude => 30.82, :longitude => -122.37
|
569
|
+
column(:location).within(southwest, northeast)
|
570
|
+
}
|
571
|
+
```
|
510
572
|
|
511
573
|
### Security
|
512
574
|
|
data/lib/parse/client.rb
CHANGED
@@ -29,11 +29,8 @@ module Parse
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def canonical_endpoint endpoint
|
32
|
-
|
33
|
-
|
34
|
-
endpoint.sub %r|/#{API_VERSION}/classes/_User|, "/#{API_VERSION}/users"
|
35
|
-
when %r|/#{API_VERSION}/classes/_Role|
|
36
|
-
endpoint.sub %r|/#{API_VERSION}/classes/_Role|, "/#{API_VERSION}/roles"
|
32
|
+
if endpoint =~ %r</#{API_VERSION}/classes/_(User|Role|Installation)>
|
33
|
+
endpoint.sub %r</#{API_VERSION}/classes/_(User|Role|Installation)>, "/#{API_VERSION}/#{$1.downcase}s"
|
37
34
|
else
|
38
35
|
endpoint
|
39
36
|
end
|
data/lib/parse/file.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
# encoding:utf-8
|
2
2
|
module Parse
|
3
3
|
class File
|
4
|
+
include Util
|
5
|
+
|
4
6
|
attr_accessor :name, :url, :content, :type
|
5
7
|
|
6
8
|
def initialize hash
|
7
|
-
|
9
|
+
hash = string_keyed_hash hash
|
10
|
+
@name = hash['name']
|
8
11
|
raise 'name is mandatory' unless @name
|
9
12
|
@url = hash['url']
|
10
13
|
@content = hash['content']
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding:utf-8
|
2
|
+
module Parse
|
3
|
+
class GeoPoint
|
4
|
+
include Util
|
5
|
+
|
6
|
+
attr_accessor :latitude, :longitude
|
7
|
+
|
8
|
+
def initialize hash={}
|
9
|
+
hash = string_keyed_hash hash
|
10
|
+
@latitude = hash['latitude']
|
11
|
+
@longitude = hash['longitude']
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_h
|
15
|
+
{
|
16
|
+
"__type" => "GeoPoint",
|
17
|
+
"latitude" => @latitude,
|
18
|
+
"longitude" => @longitude
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_json *args
|
23
|
+
to_h.to_json
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/parse/installation.rb
CHANGED
data/lib/parse/object.rb
CHANGED
@@ -7,6 +7,8 @@ module Parse
|
|
7
7
|
}
|
8
8
|
|
9
9
|
class Object
|
10
|
+
include Parse::Util
|
11
|
+
|
10
12
|
@@parse_class_vs_class_table = {}
|
11
13
|
|
12
14
|
class << self
|
@@ -97,6 +99,8 @@ module Parse
|
|
97
99
|
Parse::Pointer.new v, self
|
98
100
|
when 'Relation'
|
99
101
|
Parse::Relation.new self, k, v
|
102
|
+
when 'GeoPoint'
|
103
|
+
Parse::GeoPoint.new v
|
100
104
|
else
|
101
105
|
v
|
102
106
|
end
|
@@ -241,14 +245,6 @@ module Parse
|
|
241
245
|
|
242
246
|
private
|
243
247
|
|
244
|
-
def string_keyed_hash hash
|
245
|
-
new_hash = {}
|
246
|
-
hash.each do |k, v|
|
247
|
-
new_hash[k.to_s] = v
|
248
|
-
end
|
249
|
-
new_hash
|
250
|
-
end
|
251
|
-
|
252
248
|
def check_deleted!
|
253
249
|
raise 'This object has already been deleted.' if deleted?
|
254
250
|
end
|
data/lib/parse/query.rb
CHANGED
@@ -236,6 +236,33 @@ module Parse
|
|
236
236
|
@query.where.push or_cond
|
237
237
|
end
|
238
238
|
|
239
|
+
# conditions for GeoPoints
|
240
|
+
|
241
|
+
def near_sphere geo_point
|
242
|
+
@conditions.push ['$nearSphere', geo_point]
|
243
|
+
self
|
244
|
+
end
|
245
|
+
|
246
|
+
def max_distance_in_miles miles
|
247
|
+
@conditions.push ['$maxDistanceInMiles', miles]
|
248
|
+
self
|
249
|
+
end
|
250
|
+
|
251
|
+
def max_distance_in_kilometers kilometers
|
252
|
+
@conditions.push ['$maxDistanceInKilometers', kilometers]
|
253
|
+
self
|
254
|
+
end
|
255
|
+
|
256
|
+
def max_distance_in_radians radians
|
257
|
+
@conditions.push ['$maxDistanceInRadians', radians]
|
258
|
+
self
|
259
|
+
end
|
260
|
+
|
261
|
+
def within southwest_geo_point, northeast_geo_point
|
262
|
+
@conditions.push WithinCondition.new(southwest_geo_point, northeast_geo_point)
|
263
|
+
self
|
264
|
+
end
|
265
|
+
|
239
266
|
def to_s
|
240
267
|
if @conditions.size == 1 && !@conditions[0].is_a?(Array)
|
241
268
|
"#{@column_name.to_s.inspect}:#{condition_to_s @conditions[0]}"
|
@@ -253,8 +280,11 @@ module Parse
|
|
253
280
|
case val
|
254
281
|
when Parse::Object
|
255
282
|
%Q|{"__type":"Pointer","className":"#{val.parse_class_name}","objectId":"#{val.parse_object_id}"}|
|
283
|
+
when Parse::GeoPoint
|
284
|
+
val.to_json
|
256
285
|
else
|
257
286
|
val.inspect
|
287
|
+
#val.to_json
|
258
288
|
end
|
259
289
|
end
|
260
290
|
|
@@ -293,6 +323,17 @@ module Parse
|
|
293
323
|
%Q|"$relatedTo":{"object":#{@pointer.to_json},"key":"#{@column_name}"}|
|
294
324
|
end
|
295
325
|
end
|
326
|
+
|
327
|
+
class WithinCondition
|
328
|
+
def initialize southwest_geo_point, northeast_geo_point
|
329
|
+
@southwest_geo_point = southwest_geo_point
|
330
|
+
@northeast_geo_point = northeast_geo_point
|
331
|
+
end
|
332
|
+
|
333
|
+
def to_s
|
334
|
+
%Q|{"$within":{"$box":[#{@southwest_geo_point.to_json},#{@northeast_geo_point.to_json}]}}|
|
335
|
+
end
|
336
|
+
end
|
296
337
|
end
|
297
338
|
|
298
339
|
def Query parse_class_name=nil
|
data/lib/parse/util.rb
ADDED
data/lib/parse/version.rb
CHANGED
data/lib/parsecom.rb
CHANGED
@@ -8,6 +8,7 @@ require 'date'
|
|
8
8
|
require 'net/https'
|
9
9
|
require 'uri'
|
10
10
|
require 'parse/ext/string'
|
11
|
+
require 'parse/util'
|
11
12
|
require 'parse/http_client'
|
12
13
|
require 'parse/client'
|
13
14
|
require 'parse/query'
|
@@ -16,6 +17,7 @@ require 'parse/object'
|
|
16
17
|
require 'parse/user'
|
17
18
|
require 'parse/role'
|
18
19
|
require 'parse/installation'
|
20
|
+
require 'parse/geo_point'
|
19
21
|
require 'parse/pointer'
|
20
22
|
require 'parse/relation'
|
21
23
|
require 'parse/file'
|
data/spec/parse_query_spec.rb
CHANGED
@@ -132,6 +132,26 @@ describe Parse::Query, 'when it builds conditions' do
|
|
132
132
|
end
|
133
133
|
query.to_params.should have_params('where' => '{"$or":[{"wins":{"$gt":150}},{"wins":{"$lt":5}},{"loses":{"$lt":5}}]}')
|
134
134
|
query.where.clear
|
135
|
+
|
136
|
+
geo_point1 = Parse::GeoPoint.new :latitude => 12, :longitude => 34
|
137
|
+
geo_point2 = Parse::GeoPoint.new :latitude => 56, :longitude => 78
|
138
|
+
query.where do
|
139
|
+
column(:location).near_sphere(geo_point1)
|
140
|
+
end
|
141
|
+
query.to_params.should have_params('where' => '{"location":{"$nearSphere":{"__type":"GeoPoint","latitude":12,"longitude":34}}}')
|
142
|
+
query.where.clear
|
143
|
+
|
144
|
+
query.where do
|
145
|
+
column(:location).near_sphere(geo_point1).max_distance_in_miles(10)
|
146
|
+
end
|
147
|
+
query.to_params.should have_params('where' => '{"location":{"$nearSphere":{"__type":"GeoPoint","latitude":12,"longitude":34},"$maxDistanceInMiles":10}}')
|
148
|
+
query.where.clear
|
149
|
+
|
150
|
+
query.where do
|
151
|
+
column(:location).within(geo_point1, geo_point2)
|
152
|
+
end
|
153
|
+
query.to_params.should have_params('where' => '{"location":{"$within":{"$box":[{"__type":"GeoPoint","latitude":12,"longitude":34},{"__type":"GeoPoint","latitude":56,"longitude":78}]}}}')
|
154
|
+
query.where.clear
|
135
155
|
end
|
136
156
|
|
137
157
|
it 'should build a correct "order" parameter' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parsecom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
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-10-
|
12
|
+
date: 2013-10-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -79,6 +79,7 @@ files:
|
|
79
79
|
- lib/parse/cloud_code.rb
|
80
80
|
- lib/parse/ext/string.rb
|
81
81
|
- lib/parse/file.rb
|
82
|
+
- lib/parse/geo_point.rb
|
82
83
|
- lib/parse/http_client.rb
|
83
84
|
- lib/parse/installation.rb
|
84
85
|
- lib/parse/object.rb
|
@@ -94,6 +95,7 @@ files:
|
|
94
95
|
- lib/parse/relation.rb
|
95
96
|
- lib/parse/role.rb
|
96
97
|
- lib/parse/user.rb
|
98
|
+
- lib/parse/util.rb
|
97
99
|
- lib/parse/version.rb
|
98
100
|
- lib/parsecom.rb
|
99
101
|
- parsecom.gemspec
|