parse-ruby-client 0.0.3 → 0.0.4
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 +1 -1
- data/VERSION +1 -1
- data/lib/parse-ruby-client.rb +1 -0
- data/lib/parse/client.rb +1 -0
- data/lib/parse/datatypes.rb +36 -12
- data/lib/parse/object.rb +29 -11
- data/lib/parse/protocol.rb +5 -1
- data/lib/parse/user.rb +39 -0
- data/parse-ruby-client.gemspec +6 -3
- data/test/test_client.rb +9 -0
- data/test/test_object.rb +56 -0
- data/test/test_query.rb +12 -0
- data/test/test_user.rb +41 -0
- metadata +16 -13
data/README.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/lib/parse-ruby-client.rb
CHANGED
data/lib/parse/client.rb
CHANGED
data/lib/parse/datatypes.rb
CHANGED
@@ -14,12 +14,16 @@ module Parse
|
|
14
14
|
@parse_object_id = data[Protocol::KEY_OBJECT_ID]
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
17
|
+
def as_json(*a)
|
18
18
|
{
|
19
19
|
Protocol::KEY_TYPE => Protocol::TYPE_POINTER,
|
20
20
|
Protocol::KEY_CLASS_NAME => @class_name,
|
21
21
|
Protocol::KEY_OBJECT_ID => @parse_object_id
|
22
|
-
}
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_json(*a)
|
26
|
+
as_json.to_json(*a)
|
23
27
|
end
|
24
28
|
|
25
29
|
# Retrieve the Parse object referenced by this pointer.
|
@@ -44,11 +48,15 @@ module Parse
|
|
44
48
|
end
|
45
49
|
end
|
46
50
|
|
47
|
-
def
|
51
|
+
def as_json(*a)
|
48
52
|
{
|
49
53
|
Protocol::KEY_TYPE => Protocol::TYPE_DATE,
|
50
54
|
"iso" => value.iso8601
|
51
|
-
}
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
def to_json(*a)
|
59
|
+
as_json.to_json(*a)
|
52
60
|
end
|
53
61
|
end
|
54
62
|
|
@@ -63,11 +71,15 @@ module Parse
|
|
63
71
|
@value = Base64.decode64(bytes)
|
64
72
|
end
|
65
73
|
|
66
|
-
def
|
74
|
+
def as_json(*a)
|
67
75
|
{
|
68
76
|
Protocol::KEY_TYPE => Protocol::TYPE_BYTES,
|
69
77
|
"base64" => Base64.encode64(@value)
|
70
|
-
}
|
78
|
+
}
|
79
|
+
end
|
80
|
+
|
81
|
+
def to_json(*a)
|
82
|
+
as_json.to_json(*a)
|
71
83
|
end
|
72
84
|
end
|
73
85
|
|
@@ -82,11 +94,15 @@ module Parse
|
|
82
94
|
@amount = amount
|
83
95
|
end
|
84
96
|
|
85
|
-
def
|
97
|
+
def as_json(*a)
|
86
98
|
{
|
87
99
|
Protocol::KEY_OP => Protocol::KEY_INCREMENT,
|
88
100
|
Protocol::KEY_AMOUNT => @amount
|
89
|
-
}
|
101
|
+
}
|
102
|
+
end
|
103
|
+
|
104
|
+
def to_json(*a)
|
105
|
+
as_json.to_json(*a)
|
90
106
|
end
|
91
107
|
end
|
92
108
|
|
@@ -98,11 +114,15 @@ module Parse
|
|
98
114
|
@amount = amount
|
99
115
|
end
|
100
116
|
|
101
|
-
def
|
117
|
+
def as_json(*a)
|
102
118
|
{
|
103
119
|
Protocol::KEY_OP => Protocol::KEY_DECREMENT,
|
104
120
|
Protocol::KEY_AMOUNT => @amount
|
105
|
-
}
|
121
|
+
}
|
122
|
+
end
|
123
|
+
|
124
|
+
def to_json(*a)
|
125
|
+
as_json.to_json(*a)
|
106
126
|
end
|
107
127
|
end
|
108
128
|
|
@@ -123,12 +143,16 @@ module Parse
|
|
123
143
|
end
|
124
144
|
end
|
125
145
|
|
126
|
-
def
|
146
|
+
def as_json(*a)
|
127
147
|
{
|
128
148
|
Protocol::KEY_TYPE => Protocol::TYPE_GEOPOINT,
|
129
149
|
"latitude" => @latitude,
|
130
150
|
"longitude" => @longitude
|
131
|
-
}
|
151
|
+
}
|
152
|
+
end
|
153
|
+
|
154
|
+
def to_json(*a)
|
155
|
+
as_json.to_json(*a)
|
132
156
|
end
|
133
157
|
end
|
134
158
|
|
data/lib/parse/object.rb
CHANGED
@@ -5,11 +5,12 @@ require 'parse/error'
|
|
5
5
|
module Parse
|
6
6
|
|
7
7
|
# Represents an individual Parse API object.
|
8
|
-
class Object
|
8
|
+
class Object < Hash
|
9
9
|
attr_reader :parse_object_id
|
10
10
|
attr_reader :class_name
|
11
11
|
attr_reader :created_at
|
12
12
|
attr_reader :updated_at
|
13
|
+
alias :id :parse_object_id
|
13
14
|
|
14
15
|
def initialize(class_name, data = nil)
|
15
16
|
@class_name = class_name
|
@@ -45,17 +46,22 @@ module Parse
|
|
45
46
|
@updated_at = DateTime.parse data[Protocol::KEY_UPDATED_AT]
|
46
47
|
end
|
47
48
|
|
48
|
-
|
49
|
+
data.each do |k,v|
|
50
|
+
if k.is_a? Symbol
|
51
|
+
k = k.to_s
|
52
|
+
end
|
53
|
+
#if Protocol::RESERVED_KEYS.include? k
|
54
|
+
self[k] = v
|
55
|
+
#end
|
56
|
+
end
|
57
|
+
|
58
|
+
self
|
59
|
+
end
|
49
60
|
|
50
|
-
|
51
|
-
|
52
|
-
# k = k.to_s
|
53
|
-
# end
|
54
|
-
# if !Protocol::RESERVED_KEYS.include? k
|
55
|
-
# self[k] = v
|
56
|
-
# end
|
57
|
-
#}
|
61
|
+
def new?
|
62
|
+
self["objectId"].nil?
|
58
63
|
end
|
64
|
+
|
59
65
|
private :parse
|
60
66
|
|
61
67
|
# Write the current state of the local object to the API.
|
@@ -63,13 +69,22 @@ module Parse
|
|
63
69
|
# a new object, otherwise it will update the existing stored object.
|
64
70
|
def save
|
65
71
|
method = @parse_object_id ? :put : :post
|
72
|
+
|
66
73
|
Protocol::RESERVED_KEYS.each { |k| self.delete(k) }
|
67
74
|
body = self.to_json
|
68
75
|
|
69
76
|
data = Parse.client.request(self.uri, method, body)
|
77
|
+
|
70
78
|
if data
|
71
79
|
parse data
|
72
80
|
end
|
81
|
+
|
82
|
+
if @class_name == Parse::Protocol::CLASS_USER
|
83
|
+
self.delete("password")
|
84
|
+
self.delete(:username)
|
85
|
+
self.delete(:password)
|
86
|
+
end
|
87
|
+
|
73
88
|
self
|
74
89
|
end
|
75
90
|
|
@@ -82,6 +97,7 @@ module Parse
|
|
82
97
|
parse data
|
83
98
|
end
|
84
99
|
end
|
100
|
+
|
85
101
|
self
|
86
102
|
end
|
87
103
|
|
@@ -90,7 +106,9 @@ module Parse
|
|
90
106
|
if @parse_object_id
|
91
107
|
response = Parse.client.delete self.uri
|
92
108
|
end
|
93
|
-
|
109
|
+
|
110
|
+
self.clear
|
111
|
+
self
|
94
112
|
end
|
95
113
|
|
96
114
|
# Increment the given field by an amount, which defaults to 1.
|
data/lib/parse/protocol.rb
CHANGED
@@ -59,7 +59,7 @@ module Parse
|
|
59
59
|
# increment/decrement API call.
|
60
60
|
KEY_AMOUNT = "amount"
|
61
61
|
|
62
|
-
|
62
|
+
RESERVED_KEYS = [ KEY_CLASS_NAME, KEY_CREATED_AT, KEY_OBJECT_ID ]
|
63
63
|
|
64
64
|
# Other Constants
|
65
65
|
# ----------------------------------------
|
@@ -92,6 +92,9 @@ module Parse
|
|
92
92
|
|
93
93
|
# The class name for User objects, when referenced by a Pointer.
|
94
94
|
CLASS_USER = "_User"
|
95
|
+
USER_LOGIN_URI = "/#{VERSION}/login"
|
96
|
+
|
97
|
+
KEY_USER_SESSION_TOKEN = "sessionToken"
|
95
98
|
|
96
99
|
# URI Helpers
|
97
100
|
# ----------------------------------------
|
@@ -105,6 +108,7 @@ module Parse
|
|
105
108
|
"/#{VERSION}/classes/#{class_name}"
|
106
109
|
end
|
107
110
|
end
|
111
|
+
|
108
112
|
|
109
113
|
# Construct a uri referencing a given Parse user
|
110
114
|
# instance or the users category.
|
data/lib/parse/user.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'parse/protocol'
|
2
|
+
require 'parse/client'
|
3
|
+
require 'parse/error'
|
4
|
+
require 'parse/object'
|
5
|
+
|
6
|
+
module Parse
|
7
|
+
class User < Parse::Object
|
8
|
+
|
9
|
+
def self.authenticate(username, password)
|
10
|
+
body = {
|
11
|
+
"username" => username,
|
12
|
+
"password" => password
|
13
|
+
}
|
14
|
+
|
15
|
+
response = Parse.client.request(Parse::Protocol::USER_LOGIN_URI, :get, nil, body)
|
16
|
+
|
17
|
+
new(response)
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(data = nil)
|
21
|
+
@class_name = Parse::Protocol::CLASS_USER
|
22
|
+
|
23
|
+
#stringify symbol keys
|
24
|
+
data["username"] = data[:username] if data[:username]
|
25
|
+
data["password"] = data[:password] if data[:password]
|
26
|
+
|
27
|
+
if data
|
28
|
+
parse data
|
29
|
+
end
|
30
|
+
|
31
|
+
self
|
32
|
+
end
|
33
|
+
|
34
|
+
def uri
|
35
|
+
Protocol.user_uri @parse_object_id
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
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.0.
|
8
|
+
s.version = "0.0.4"
|
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-04-06"
|
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 = [
|
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
|
|
32
32
|
"lib/parse/object.rb",
|
33
33
|
"lib/parse/protocol.rb",
|
34
34
|
"lib/parse/query.rb",
|
35
|
+
"lib/parse/user.rb",
|
35
36
|
"lib/parse/util.rb",
|
36
37
|
"parse-ruby-client.gemspec",
|
37
38
|
"pkg/parse-ruby-client-0.0.1.gem",
|
@@ -42,7 +43,9 @@ Gem::Specification.new do |s|
|
|
42
43
|
"test/test_client.rb",
|
43
44
|
"test/test_datatypes.rb",
|
44
45
|
"test/test_init.rb",
|
45
|
-
"test/
|
46
|
+
"test/test_object.rb",
|
47
|
+
"test/test_query.rb",
|
48
|
+
"test/test_user.rb"
|
46
49
|
]
|
47
50
|
s.homepage = "http://github.com/adelevie/parse-ruby-client"
|
48
51
|
s.licenses = ["MIT"]
|
data/test/test_client.rb
CHANGED
@@ -29,4 +29,13 @@ class TestClient < Test::Unit::TestCase
|
|
29
29
|
assert_equal foo["age"], 40
|
30
30
|
assert_equal foo[Parse::Protocol::KEY_UPDATED_AT].class, String
|
31
31
|
end
|
32
|
+
|
33
|
+
def test_destroy
|
34
|
+
d = Parse::Object.new "toBeDeleted"
|
35
|
+
d["foo"] = "bar"
|
36
|
+
d.save
|
37
|
+
d.parse_delete
|
38
|
+
|
39
|
+
assert_equal d.keys.length, 0
|
40
|
+
end
|
32
41
|
end
|
data/test/test_object.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestObject < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
Parse.init
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_new?
|
9
|
+
post = Parse::Object.new "Post"
|
10
|
+
assert_equal post.new?, true
|
11
|
+
post.save
|
12
|
+
assert_equal post.new?, false
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_id
|
16
|
+
post = Parse::Object.new "Post"
|
17
|
+
assert_equal post.id, nil
|
18
|
+
post["title"] = "hello world"
|
19
|
+
post.save
|
20
|
+
assert_equal post.id.class, String
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_created_at
|
24
|
+
post = Parse::Object.new "Post"
|
25
|
+
assert_equal post.created_at, nil
|
26
|
+
post.save
|
27
|
+
assert_equal post.created_at.class, DateTime
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_updated_at
|
31
|
+
post = Parse::Object.new "Post"
|
32
|
+
assert_equal post.updated_at, nil
|
33
|
+
post["title"] = "hello"
|
34
|
+
post.save
|
35
|
+
assert_equal post.updated_at, nil
|
36
|
+
post["title"] = "hello 2"
|
37
|
+
post.save
|
38
|
+
assert_equal post.updated_at.class, DateTime
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_parse_delete
|
42
|
+
post = Parse::Object.new "Post"
|
43
|
+
post.save
|
44
|
+
assert_equal post.id.class, String
|
45
|
+
|
46
|
+
q = Parse.get("Post", post.id)
|
47
|
+
assert_equal q.id, post.id
|
48
|
+
|
49
|
+
post.parse_delete
|
50
|
+
|
51
|
+
assert_raise Parse::ParseError do
|
52
|
+
q = Parse.get("Post", post.id)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
data/test/test_query.rb
CHANGED
@@ -3,6 +3,18 @@ require 'helper'
|
|
3
3
|
Parse.init
|
4
4
|
|
5
5
|
class TestQuery < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_get
|
8
|
+
post = Parse::Object.new "Post"
|
9
|
+
post["title"] = "foo"
|
10
|
+
post.save
|
11
|
+
|
12
|
+
q = Parse.get("Post", post.id)
|
13
|
+
|
14
|
+
assert_equal q.id, post.id
|
15
|
+
assert_equal q["title"], post["title"]
|
16
|
+
end
|
17
|
+
|
6
18
|
def test_add_contraint
|
7
19
|
# I know this method *should* be private.
|
8
20
|
# But then it would be a PITA to test.
|
data/test/test_user.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestUser < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
Parse.init
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_save
|
10
|
+
username = rand.to_s
|
11
|
+
data = {
|
12
|
+
:username => username,
|
13
|
+
:password => "topsecret"
|
14
|
+
}
|
15
|
+
user = Parse::User.new data
|
16
|
+
user.save
|
17
|
+
assert_equal user[Parse::Protocol::KEY_OBJECT_ID].class, String
|
18
|
+
assert_equal user[Parse::Protocol::KEY_CREATED_AT].class, String
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_login
|
22
|
+
u = "alan" + rand(10000000000000).to_s
|
23
|
+
data = {
|
24
|
+
:username => u,
|
25
|
+
:password => "secret"
|
26
|
+
}
|
27
|
+
|
28
|
+
user = Parse::User.new(data)
|
29
|
+
|
30
|
+
user.save
|
31
|
+
|
32
|
+
assert_equal user["username"], u
|
33
|
+
assert_equal user[Parse::Protocol::KEY_USER_SESSION_TOKEN].class, String
|
34
|
+
|
35
|
+
login = Parse::User.authenticate(u, "secret")
|
36
|
+
|
37
|
+
assert_equal login["username"], user["username"]
|
38
|
+
assert_equal login["sessionToken"].class, String
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
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.0.
|
4
|
+
version: 0.0.4
|
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-04-06 00:00:00.000000000Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: patron
|
17
|
-
requirement: &
|
17
|
+
requirement: &70183947794580 !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: *70183947794580
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: shoulda
|
28
|
-
requirement: &
|
28
|
+
requirement: &70183947794100 !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: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70183947794100
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: bundler
|
39
|
-
requirement: &
|
39
|
+
requirement: &70183947793620 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: 1.0.0
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70183947793620
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: jeweler
|
50
|
-
requirement: &
|
50
|
+
requirement: &70183947793140 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ~>
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: 1.6.4
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *70183947793140
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: rcov
|
61
|
-
requirement: &
|
61
|
+
requirement: &70183947792660 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ! '>='
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
version: '0'
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *70183947792660
|
70
70
|
description: A simple Ruby client for the parse.com REST API
|
71
71
|
email: adelevie@gmail.com
|
72
72
|
executables: []
|
@@ -90,6 +90,7 @@ files:
|
|
90
90
|
- lib/parse/object.rb
|
91
91
|
- lib/parse/protocol.rb
|
92
92
|
- lib/parse/query.rb
|
93
|
+
- lib/parse/user.rb
|
93
94
|
- lib/parse/util.rb
|
94
95
|
- parse-ruby-client.gemspec
|
95
96
|
- pkg/parse-ruby-client-0.0.1.gem
|
@@ -100,7 +101,9 @@ files:
|
|
100
101
|
- test/test_client.rb
|
101
102
|
- test/test_datatypes.rb
|
102
103
|
- test/test_init.rb
|
104
|
+
- test/test_object.rb
|
103
105
|
- test/test_query.rb
|
106
|
+
- test/test_user.rb
|
104
107
|
homepage: http://github.com/adelevie/parse-ruby-client
|
105
108
|
licenses:
|
106
109
|
- MIT
|
@@ -116,7 +119,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
116
119
|
version: '0'
|
117
120
|
segments:
|
118
121
|
- 0
|
119
|
-
hash:
|
122
|
+
hash: 4137621541877558226
|
120
123
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
124
|
none: false
|
122
125
|
requirements:
|