parse-ruby-client 0.1.9 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -19,7 +19,7 @@ This currently depends on the gems 'json' and 'patron' for JSON support and HTTP
19
19
 
20
20
  ## Installation
21
21
 
22
- `gem "parse-ruby-client", "~> 0.1.9"`
22
+ `gem "parse-ruby-client", "~> 0.1.10"`
23
23
 
24
24
  ---
25
25
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.9
1
+ 0.1.10
@@ -1,83 +1,62 @@
1
- ---
2
- http_interactions:
3
- - request:
1
+ ---
2
+ http_interactions:
3
+ - request:
4
4
  method: post
5
5
  uri: https://api.parse.com/1/users
6
- body:
6
+ body:
7
7
  encoding: UTF-8
8
- string: ! '{"username":"0.71975770632902","password":"topsecret"}'
9
- headers:
10
- Content-Type:
8
+ string: "{\"username\":\"0.40493766445323776\",\"password\":\"topsecret\"}"
9
+ headers:
10
+ Content-Type:
11
11
  - application/json
12
- Accept:
12
+ Accept:
13
13
  - application/json
14
- User-Agent:
14
+ User-Agent:
15
15
  - Parse for Ruby, 0.0
16
- X-Parse-Master-Key:
17
- - ''
18
- X-Parse-Rest-Api-Key:
19
- - D3Y8jNCQk6kpkKhpRGnWLYTrFGQ7j8dtDVnWZRnZ
20
- X-Parse-Application-Id:
21
- - PPVk6L5M9R1R8GVk8Ye9jT8f5SQNBIeoJUDJLmkT
22
- X-Parse-Session-Token:
23
- - ''
24
- Expect:
25
- - ''
26
- response:
27
- status:
16
+ X-Parse-Master-Key:
17
+ - ""
18
+ X-Parse-Rest-Api-Key:
19
+ - jYdptjS76YHikuIFfJEgHD8UMIjH6cp2rWz4fo2C
20
+ X-Parse-Application-Id:
21
+ - hnJRtntbYPvWfjqcqLZsdFaOKT0F3SfNU7Kc7woN
22
+ X-Parse-Session-Token:
23
+ - ""
24
+ Expect:
25
+ - ""
26
+ response:
27
+ status:
28
28
  code: 201
29
- message: !binary |-
30
- Q3JlYXRlZA==
31
- headers:
32
- !binary "QWNjZXNzLUNvbnRyb2wtQWxsb3ctT3JpZ2lu":
33
- - !binary |-
34
- Kg==
35
- !binary "QWNjZXNzLUNvbnRyb2wtUmVxdWVzdC1NZXRob2Q=":
36
- - !binary |-
37
- Kg==
38
- !binary "Q2FjaGUtQ29udHJvbA==":
39
- - !binary |-
40
- bm8tY2FjaGU=
41
- !binary "Q29udGVudC1UeXBl":
42
- - !binary |-
43
- YXBwbGljYXRpb24vanNvbjsgY2hhcnNldD11dGYtOA==
44
- !binary "RGF0ZQ==":
45
- - !binary |-
46
- VHVlLCAwOSBPY3QgMjAxMiAyMTo0NTozNCBHTVQ=
47
- !binary "TG9jYXRpb24=":
48
- - !binary |-
49
- aHR0cHM6Ly9hcGkucGFyc2UuY29tLzEvdXNlcnMvTDlnWm1FVkZFSA==
50
- !binary "U2VydmVy":
51
- - !binary |-
52
- bmdpbngvMS4yLjI=
53
- !binary "U2V0LUNvb2tpZQ==":
54
- - !binary |-
55
- X3BhcnNlX3Nlc3Npb249QkFoN0Jra2lEM05sYzNOcGIyNWZhV1FHT2daRlJp
56
- SWxORE5pWXpWaFpUSTRNVE00TWprd016YzBPRFk0TXpSaFpHSTRZamsxTXpr
57
- JTNELS00MWE4YTBmMzNjZGQ3NjU5MDIyNmNhZWNiMjY0Y2FlNjFlOTM4N2Zj
58
- OyBkb21haW49LnBhcnNlLmNvbTsgcGF0aD0vOyBleHBpcmVzPVN1biwgMDkt
59
- T2N0LTIwMjIgMjE6NDU6MzQgR01UOyBzZWN1cmU7IEh0dHBPbmx5
60
- !binary "U3RhdHVz":
61
- - !binary |-
62
- MjAxIENyZWF0ZWQ=
63
- !binary "WC1SdW50aW1l":
64
- - !binary |-
65
- MC4yNDczNTA=
66
- !binary "WC1VYS1Db21wYXRpYmxl":
67
- - !binary |-
68
- SUU9RWRnZSxjaHJvbWU9MQ==
69
- !binary "Q29udGVudC1MZW5ndGg=":
70
- - !binary |-
71
- MTA3
72
- !binary "Q29ubmVjdGlvbg==":
73
- - !binary |-
74
- a2VlcC1hbGl2ZQ==
75
- body:
29
+ message: Created
30
+ headers:
31
+ Access-Control-Allow-Origin:
32
+ - "*"
33
+ Access-Control-Request-Method:
34
+ - "*"
35
+ Cache-Control:
36
+ - no-cache
37
+ Content-Type:
38
+ - application/json; charset=utf-8
39
+ Date:
40
+ - Thu, 10 Jan 2013 17:13:29 GMT
41
+ Location:
42
+ - https://api.parse.com/1/users/TjN5LVdT83
43
+ Server:
44
+ - nginx/1.2.2
45
+ Set-Cookie:
46
+ - _parse_session=BAh7BkkiD3Nlc3Npb25faWQGOgZFRiIlNDhiYjExOGE4MzY1ZmEzNGVjN2NmYjUxMzk2YjFjNzk%3D--242cb8875ea6f8b5c353b05bf1b9dcc351e5197e; domain=.parse.com; path=/; expires=Tue, 10-Jan-2023 17:13:29 GMT; secure; HttpOnly
47
+ Status:
48
+ - 201 Created
49
+ X-Runtime:
50
+ - "0.312384"
51
+ X-Ua-Compatible:
52
+ - IE=Edge,chrome=1
53
+ Content-Length:
54
+ - "107"
55
+ Connection:
56
+ - keep-alive
57
+ body:
76
58
  encoding: ASCII-8BIT
77
- string: !binary |-
78
- eyJjcmVhdGVkQXQiOiIyMDEyLTEwLTA5VDIxOjQ1OjM0LjI4N1oiLCJvYmpl
79
- Y3RJZCI6Ikw5Z1ptRVZGRUgiLCJzZXNzaW9uVG9rZW4iOiJjejU0YmtmMm8w
80
- eXg4dDF5cnpvMndjMHE4In0=
59
+ string: "{\"createdAt\":\"2013-01-10T17:13:29.400Z\",\"objectId\":\"TjN5LVdT83\",\"sessionToken\":\"ltj1s0ms3rft92u1avdnys7vn\"}"
81
60
  http_version:
82
- recorded_at: Tue, 09 Oct 2012 21:45:34 GMT
61
+ recorded_at: Thu, 10 Jan 2013 17:13:29 GMT
83
62
  recorded_with: VCR 2.0.1
data/lib/parse/client.rb CHANGED
@@ -8,14 +8,13 @@ module Parse
8
8
  # API server. Currently uses the Patron library for low-level HTTP
9
9
  # communication.
10
10
  class Client
11
- DEFAULT_RETRIES = 2
12
-
13
11
  attr_accessor :host
14
12
  attr_accessor :application_id
15
13
  attr_accessor :api_key
16
14
  attr_accessor :master_key
17
15
  attr_accessor :session_token
18
16
  attr_accessor :session
17
+ attr_accessor :max_retries
19
18
 
20
19
  def initialize(data = {})
21
20
  @host = data[:host] || Protocol::HOST
@@ -23,6 +22,7 @@ module Parse
23
22
  @api_key = data[:api_key]
24
23
  @master_key = data[:master_key]
25
24
  @session_token = data[:session_token]
25
+ @max_retries = data[:max_retries] || 3
26
26
  @session = Patron::Session.new
27
27
  @session.timeout = 30
28
28
  @session.connect_timeout = 30
@@ -37,7 +37,7 @@ module Parse
37
37
  # with common basic response handling. Will raise a
38
38
  # ParseProtocolError if the response has an error status code,
39
39
  # and will return the parsed JSON body on success, if there is one.
40
- def request(uri, method = :get, body = nil, query = nil, max_retries = DEFAULT_RETRIES)
40
+ def request(uri, method = :get, body = nil, query = nil)
41
41
  @session.headers[Protocol::HEADER_MASTER_KEY] = @master_key
42
42
  @session.headers[Protocol::HEADER_API_KEY] = @api_key
43
43
  @session.headers[Protocol::HEADER_APP_ID] = @application_id
@@ -48,6 +48,8 @@ module Parse
48
48
  # of Parse objects in their JSON representation.
49
49
  KEY_UPDATED_AT = "updatedAt"
50
50
 
51
+ KEY_USER_SESSION_TOKEN = "sessionToken"
52
+
51
53
  # The JSON key used in the top-level response object
52
54
  # to indicate that the response contains an array of objects.
53
55
  RESPONSE_KEY_RESULTS = "results"
@@ -71,11 +73,13 @@ module Parse
71
73
  # The JSON key used to identify the datatype of a special value.
72
74
  KEY_TYPE = "__type"
73
75
 
76
+ TYPE_OBJECT = "Object"
77
+
74
78
  # The JSON key used to specify the numerical value in the
75
79
  # increment/decrement API call.
76
80
  KEY_AMOUNT = "amount"
77
81
 
78
- RESERVED_KEYS = [ KEY_CLASS_NAME, KEY_CREATED_AT, KEY_OBJECT_ID, KEY_UPDATED_AT]
82
+ RESERVED_KEYS = [ KEY_CLASS_NAME, KEY_CREATED_AT, KEY_OBJECT_ID, KEY_UPDATED_AT, KEY_USER_SESSION_TOKEN]
79
83
 
80
84
  # Other Constants
81
85
  # ----------------------------------------
@@ -118,8 +122,6 @@ module Parse
118
122
  USER_LOGIN_URI = "/#{VERSION}/login"
119
123
  PASSWORD_RESET_URI = "/#{VERSION}/requestPasswordReset"
120
124
 
121
- KEY_USER_SESSION_TOKEN = "sessionToken"
122
-
123
125
  CLOUD_FUNCTIONS_PATH = "functions"
124
126
 
125
127
  BATCH_REQUEST_URI = "batch"
data/lib/parse/query.rb CHANGED
@@ -10,6 +10,7 @@ module Parse
10
10
  attr_accessor :limit
11
11
  attr_accessor :skip
12
12
  attr_accessor :count
13
+ attr_accessor :include
13
14
 
14
15
  def initialize(cls_name)
15
16
  @class_name = cls_name
@@ -29,6 +30,11 @@ module Parse
29
30
  end
30
31
  #private :add_constraint
31
32
 
33
+ def includes(class_name)
34
+ @includes = class_name
35
+ self
36
+ end
37
+
32
38
  def or(query)
33
39
  raise ArgumentError, "you must pass an entire #{self.class} to \#or" unless query.is_a?(self.class)
34
40
  @ors << query
@@ -85,22 +91,11 @@ module Parse
85
91
  self
86
92
  end
87
93
 
88
- def in_query(field, query)
94
+ def in_query(field, query=nil)
89
95
  query_hash = {Parse::Protocol::KEY_CLASS_NAME => query.class_name, "where" => query.where}
90
96
  add_constraint(field, "$inQuery" => query_hash)
91
97
  self
92
98
  end
93
-
94
- def set_limit(num)
95
- @limit = num
96
- self
97
- end
98
-
99
- def set_order(field, order = :ascending)
100
- @order_by = field
101
- @order = order
102
- self
103
- end
104
99
 
105
100
  def count
106
101
  @count = true
@@ -120,12 +115,9 @@ module Parse
120
115
  if @class_name == Parse::Protocol::CLASS_USER
121
116
  uri = Protocol.user_uri
122
117
  end
123
-
124
-
125
118
  query = { "where" => CGI.escape(where_as_json.to_json) }
126
119
  set_order(query)
127
- [:count, :limit, :skip].each {|a| merge_attribute(a, query)}
128
-
120
+ [:count, :limit, :skip, :include].each {|a| merge_attribute(a, query)}
129
121
  response = Parse.client.request uri, :get, nil, query
130
122
  Parse.parse_json class_name, response
131
123
  end
data/lib/parse/user.rb CHANGED
@@ -5,7 +5,7 @@ require 'parse/object'
5
5
 
6
6
  module Parse
7
7
  class User < Parse::Object
8
-
8
+
9
9
  def self.authenticate(username, password)
10
10
  body = {
11
11
  "username" => username,
@@ -13,7 +13,8 @@ module Parse
13
13
  }
14
14
 
15
15
  response = Parse.client.request(Parse::Protocol::USER_LOGIN_URI, :get, nil, body)
16
-
16
+ Parse.client.session_token = response[Parse::Protocol::KEY_USER_SESSION_TOKEN]
17
+
17
18
  new(response)
18
19
  end
19
20
 
@@ -27,10 +28,10 @@ module Parse
27
28
  data["password"] = data[:password] if data[:password]
28
29
  super(Parse::Protocol::CLASS_USER, data)
29
30
  end
30
-
31
+
31
32
  def uri
32
33
  Protocol.user_uri @parse_object_id
33
34
  end
34
-
35
+
35
36
  end
36
37
  end
data/lib/parse/util.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'pp'
1
2
  module Parse
2
3
 
3
4
  # Parse a JSON representation into a fully instantiated
@@ -46,6 +47,8 @@ module Parse
46
47
  Parse::GeoPoint.new obj
47
48
  when Protocol::TYPE_FILE
48
49
  Parse::File.new obj
50
+ when Protocol::TYPE_OBJECT # used for relation queries, e.g. "?include=post"
51
+ Parse::Object.new(obj[Parse::Protocol::KEY_CLASS_NAME], obj)
49
52
  end
50
53
  end
51
54
  end
@@ -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.9"
8
+ s.version = "0.1.10"
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 = "2013-01-10"
12
+ s.date = "2013-01-12"
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
@@ -10,7 +10,7 @@ class TestClient < Test::Unit::TestCase
10
10
  response = mock()
11
11
  response.stubs(:body).returns({'code' => Parse::Protocol::ERROR_TIMEOUT}.to_json)
12
12
  response.stubs(:status).returns(400)
13
- @client.session.expects(:request).times(Parse::Client::DEFAULT_RETRIES + 1).returns(response)
13
+ @client.session.expects(:request).times(@client.max_retries + 1).returns(response)
14
14
  assert_raise do
15
15
  @client.request(nil)
16
16
  end
data/test/test_user.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'helper'
2
2
 
3
3
  class TestUser < Test::Unit::TestCase
4
-
4
+
5
5
  def setup
6
6
  Parse.init
7
7
  end
@@ -19,42 +19,45 @@ class TestUser < Test::Unit::TestCase
19
19
  assert_equal user[Parse::Protocol::KEY_CREATED_AT].class, String
20
20
  end
21
21
  end
22
-
22
+
23
23
  def test_user_login
24
24
  #VCR.use_cassette('test_user_login', :record => :new_episodes) do
25
25
  u = "alan" + rand(10000000000000).to_s
26
26
  data = {
27
- :username => u,
27
+ :username => u,
28
28
  :password => "secret"
29
29
  }
30
30
 
31
31
  user = Parse::User.new(data)
32
32
 
33
33
  user.save
34
-
34
+
35
35
  assert_equal user["username"], u
36
36
  assert_equal user[Parse::Protocol::KEY_USER_SESSION_TOKEN].class, String
37
-
37
+
38
38
  login = Parse::User.authenticate(u, "secret")
39
-
39
+
40
40
  assert_equal login["username"], user["username"]
41
41
  assert_equal login["sessionToken"].class, String
42
+
43
+ user = user.pointer.get
44
+ user.save
42
45
  #end
43
46
  end
44
47
 
45
48
  def test_reset_password
46
- u = "alan" + rand(10000000000000).to_s + "@gmail.com"
49
+ u = "alan" + rand(10000000000000).to_s + "@gmail.com"
47
50
  data = {
48
- :username => u,
51
+ :username => u,
49
52
  :password => "secret"
50
53
  }
51
54
 
52
55
  user = Parse::User.new(data)
53
56
 
54
57
  user.save
55
-
58
+
56
59
  reset_password = Parse::User.reset_password(u)
57
-
60
+
58
61
  assert true
59
62
  end
60
63
 
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.9
4
+ version: 0.1.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-01-10 00:00:00.000000000 Z
13
+ date: 2013-01-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: patron
@@ -237,7 +237,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
237
237
  version: '0'
238
238
  segments:
239
239
  - 0
240
- hash: -4088256364268233622
240
+ hash: 1980852008607816263
241
241
  required_rubygems_version: !ruby/object:Gem::Requirement
242
242
  none: false
243
243
  requirements: