parse-ruby-client 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +5 -1
- data/VERSION +1 -1
- data/lib/parse/object.rb +7 -6
- data/lib/parse/query.rb +22 -0
- data/parse-ruby-client.gemspec +2 -2
- data/test/test_client.rb +18 -12
- data/test/test_object.rb +5 -1
- metadata +15 -15
data/README.md
CHANGED
@@ -11,6 +11,10 @@ match the structure of the iOS and Android SDKs from Parse.
|
|
11
11
|
So far it supports simple GET, PUT, and POST operations on objects. Enough
|
12
12
|
to read & write simple data.
|
13
13
|
|
14
|
+
## New in 0.1.1
|
15
|
+
* query ordering
|
16
|
+
* reserved keys no longer deleted on update
|
17
|
+
|
14
18
|
## Dependencies
|
15
19
|
|
16
20
|
This currently depends on the gems 'json' and 'patron' for JSON support and HTTP, respectively.
|
@@ -19,7 +23,7 @@ This currently depends on the gems 'json' and 'patron' for JSON support and HTTP
|
|
19
23
|
|
20
24
|
## Installation
|
21
25
|
|
22
|
-
`gem "parse-ruby-client", "~> 0.
|
26
|
+
`gem "parse-ruby-client", "~> 0.1.1"`
|
23
27
|
|
24
28
|
---
|
25
29
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/lib/parse/object.rb
CHANGED
@@ -70,21 +70,22 @@ module Parse
|
|
70
70
|
def save
|
71
71
|
method = @parse_object_id ? :put : :post
|
72
72
|
|
73
|
-
|
74
|
-
|
73
|
+
without_reserved = self.dup
|
74
|
+
Protocol::RESERVED_KEYS.each { |k| without_reserved.delete(k) }
|
75
|
+
body = without_reserved.to_json
|
75
76
|
|
76
77
|
data = Parse.client.request(self.uri, method, body)
|
77
78
|
|
78
79
|
if data
|
79
80
|
parse data
|
80
81
|
end
|
81
|
-
|
82
|
+
|
82
83
|
if @class_name == Parse::Protocol::CLASS_USER
|
83
84
|
self.delete("password")
|
84
85
|
self.delete(:username)
|
85
86
|
self.delete(:password)
|
86
87
|
end
|
87
|
-
|
88
|
+
|
88
89
|
self
|
89
90
|
end
|
90
91
|
|
@@ -97,7 +98,7 @@ module Parse
|
|
97
98
|
parse data
|
98
99
|
end
|
99
100
|
end
|
100
|
-
|
101
|
+
|
101
102
|
self
|
102
103
|
end
|
103
104
|
|
@@ -106,7 +107,7 @@ module Parse
|
|
106
107
|
if @parse_object_id
|
107
108
|
response = Parse.client.delete self.uri
|
108
109
|
end
|
109
|
-
|
110
|
+
|
110
111
|
self.clear
|
111
112
|
self
|
112
113
|
end
|
data/lib/parse/query.rb
CHANGED
@@ -9,6 +9,7 @@ module Parse
|
|
9
9
|
attr_accessor :order
|
10
10
|
attr_accessor :limit
|
11
11
|
attr_accessor :skip
|
12
|
+
attr_accessor :count
|
12
13
|
|
13
14
|
def initialize(cls_name)
|
14
15
|
@class_name = cls_name
|
@@ -66,14 +67,35 @@ module Parse
|
|
66
67
|
self
|
67
68
|
end
|
68
69
|
|
70
|
+
def count
|
71
|
+
@count = true
|
72
|
+
self
|
73
|
+
end
|
74
|
+
|
69
75
|
def get
|
70
76
|
uri = Protocol.class_uri @class_name
|
71
77
|
query = { "where" => CGI.escape(@where.to_json) }
|
78
|
+
set_order(query)
|
79
|
+
[:count, :limit].each {|a| merge_attribute(a, query)}
|
72
80
|
|
73
81
|
response = Parse.client.request uri, :get, nil, query
|
74
82
|
Parse.parse_json class_name, response
|
75
83
|
end
|
76
84
|
|
85
|
+
private
|
86
|
+
|
87
|
+
def set_order(query)
|
88
|
+
return unless @order_by
|
89
|
+
order_string = @order_by
|
90
|
+
order_string = "-#{order_string}" if @order == :descending
|
91
|
+
query.merge!(:order => order_string)
|
92
|
+
end
|
93
|
+
|
94
|
+
def merge_attribute(attribute, query)
|
95
|
+
value = self.instance_variable_get("@#{attribute.to_s}")
|
96
|
+
return if value.nil?
|
97
|
+
query.merge!(attribute => value)
|
98
|
+
end
|
77
99
|
end
|
78
100
|
|
79
101
|
end
|
data/parse-ruby-client.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "parse-ruby-client"
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Alan deLevie", "Adam Alpern"]
|
12
|
-
s.date = "2012-
|
12
|
+
s.date = "2012-07-04"
|
13
13
|
s.description = "A simple Ruby client for the parse.com REST API"
|
14
14
|
s.email = "adelevie@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
data/test/test_client.rb
CHANGED
@@ -4,7 +4,7 @@ class TestClient < Test::Unit::TestCase
|
|
4
4
|
def setup
|
5
5
|
Parse.init
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
def test_simple_save
|
9
9
|
test_save = Parse::Object.new "TestSave"
|
10
10
|
test_save["foo"] = "bar"
|
@@ -14,42 +14,48 @@ class TestClient < Test::Unit::TestCase
|
|
14
14
|
assert_equal test_save[Parse::Protocol::KEY_CREATED_AT].class, String
|
15
15
|
assert_equal test_save[Parse::Protocol::KEY_OBJECT_ID].class, String
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def test_update
|
19
19
|
foo = Parse::Object.new "TestSave"
|
20
20
|
foo["age"] = 20
|
21
21
|
foo.save
|
22
|
-
|
22
|
+
|
23
23
|
assert_equal foo["age"], 20
|
24
24
|
assert_equal foo[Parse::Protocol::KEY_UPDATED_AT], nil
|
25
|
-
|
25
|
+
|
26
26
|
foo["age"] = 40
|
27
|
+
orig = foo.dup
|
27
28
|
foo.save
|
28
|
-
|
29
|
+
|
29
30
|
assert_equal foo["age"], 40
|
30
31
|
assert_equal foo[Parse::Protocol::KEY_UPDATED_AT].class, String
|
32
|
+
|
33
|
+
# only difference should be updatedAt
|
34
|
+
orig_assoc = orig.reject{|k,v| k == Parse::Protocol::KEY_UPDATED_AT}.to_a
|
35
|
+
foo_assoc = foo.reject{|k,v| k == Parse::Protocol::KEY_UPDATED_AT}.to_a
|
36
|
+
assert_equal foo_assoc, orig_assoc
|
31
37
|
end
|
32
|
-
|
38
|
+
|
33
39
|
def test_server_update
|
34
|
-
foo = Parse::Object.new("TestSave").save
|
40
|
+
foo = Parse::Object.new("TestSave").save
|
35
41
|
foo["name"] = 'john'
|
36
42
|
foo.save
|
37
|
-
|
43
|
+
|
38
44
|
bar = Parse.get("TestSave",foo.id) # pull it from the server
|
39
45
|
assert_equal bar["name"], 'john'
|
40
46
|
bar["name"] = 'dave'
|
41
47
|
bar.save
|
42
|
-
|
48
|
+
|
43
49
|
bat = Parse.get("TestSave",foo.id)
|
44
|
-
assert_equal
|
50
|
+
assert_equal bat["name"], 'dave'
|
45
51
|
end
|
46
|
-
|
52
|
+
|
47
53
|
def test_destroy
|
48
54
|
d = Parse::Object.new "toBeDeleted"
|
49
55
|
d["foo"] = "bar"
|
50
56
|
d.save
|
51
57
|
d.parse_delete
|
52
|
-
|
58
|
+
|
53
59
|
assert_equal d.keys.length, 0
|
54
60
|
end
|
55
61
|
end
|
data/test/test_object.rb
CHANGED
@@ -23,8 +23,12 @@ class TestObject < Test::Unit::TestCase
|
|
23
23
|
def test_pointer
|
24
24
|
post = Parse::Object.new "Post"
|
25
25
|
pointer = post.pointer
|
26
|
-
assert_equal pointer.parse_object_id, post.parse_object_id
|
27
26
|
assert_equal pointer.class_name, post.class_name
|
27
|
+
|
28
|
+
post.save
|
29
|
+
pointer = post.pointer
|
30
|
+
assert_equal pointer.class_name, post.class_name
|
31
|
+
assert_equal pointer.parse_object_id, post.parse_object_id
|
28
32
|
end
|
29
33
|
|
30
34
|
def test_created_at
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parse-ruby-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-07-04 00:00:00.000000000Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: patron
|
17
|
-
requirement: &
|
17
|
+
requirement: &70246977048500 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70246977048500
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: vcr
|
28
|
-
requirement: &
|
28
|
+
requirement: &70246977027920 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70246977027920
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: shoulda
|
39
|
-
requirement: &
|
39
|
+
requirement: &70246977025900 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70246977025900
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: bundler
|
50
|
-
requirement: &
|
50
|
+
requirement: &70246977023480 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ~>
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: 1.0.0
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *70246977023480
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: jeweler
|
61
|
-
requirement: &
|
61
|
+
requirement: &70246977022580 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ~>
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
version: 1.6.4
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *70246977022580
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: rcov
|
72
|
-
requirement: &
|
72
|
+
requirement: &70246977020640 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ! '>='
|
@@ -77,7 +77,7 @@ dependencies:
|
|
77
77
|
version: '0'
|
78
78
|
type: :development
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *70246977020640
|
81
81
|
description: A simple Ruby client for the parse.com REST API
|
82
82
|
email: adelevie@gmail.com
|
83
83
|
executables: []
|
@@ -132,7 +132,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
132
132
|
version: '0'
|
133
133
|
segments:
|
134
134
|
- 0
|
135
|
-
hash:
|
135
|
+
hash: -2755924312958518124
|
136
136
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
137
|
none: false
|
138
138
|
requirements:
|