parsecom 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ todo.txt
1
2
  .parse_credentials
2
3
  *.swp
3
4
  *.gem
data/README.md CHANGED
@@ -21,6 +21,13 @@ Parse.credentials :application_id => 'YOUR APPID', :api_key => 'YOUR APIKEY',
21
21
  :master_key => 'YOUR MASTER KEY'
22
22
  ```
23
23
 
24
+ If you do not want to write your credentials on your code directly,
25
+ please set environment variables:
26
+
27
+ export PARSE_APPLICATION_ID="<YOUR_APPLICATION_ID>"
28
+ export PARSE_API_KEY="<YOUR_API_KEY>"
29
+ export PARSE_MASTER_KEY="<YOUR_MASTER_KEY>"
30
+
24
31
  ### Declaring Parse Classes
25
32
 
26
33
  There are three ways to declare a parse class.
@@ -54,7 +61,7 @@ class.
54
61
  Parse::Object.create :GameScore
55
62
  ```
56
63
 
57
- It may suitable for writing code in declarative style.
64
+ It may be suitable for writing code in declarative style.
58
65
 
59
66
  ### Creating Objects
60
67
 
@@ -68,7 +75,7 @@ game_score.cheatMode = false
68
75
  game_score.new? # => true
69
76
  game_score.save
70
77
  game_score.new? # => false
71
- game_score.obj_id # => 'Ed1nuqPvcm'
78
+ game_score.parse_object_id # => 'Ed1nuqPvcm'
72
79
  ```
73
80
 
74
81
  ### Retrieving Objects
data/lib/parse/client.rb CHANGED
@@ -16,7 +16,7 @@ module Parse
16
16
  @api_key = api_key || Parse.api_key
17
17
  @master_key = master_key || Parse.master_key
18
18
  if @application_id.nil? || @api_key.nil?
19
- raise ArgumentError.new <<-EOS.gsub(/^ +/)
19
+ raise ArgumentError.new <<-EOS.gsub(/^ +/, '')
20
20
  Both Application ID and API Key must be set.
21
21
  ex. Parse.credentials application_id: APPLICATION_ID, api_key: API_KEY
22
22
  EOS
@@ -36,7 +36,9 @@ module Parse
36
36
  def build_headers opt_headers={}
37
37
  headers = {
38
38
  'X-Parse-Application-Id' => @application_id,
39
- 'Content-Type' => 'application/json'
39
+ 'Content-Type' => 'application/json',
40
+ 'Accept' => 'application/json',
41
+ 'User-Agent' => 'A parse.com client for ruby'
40
42
  }
41
43
  if @use_master_key
42
44
  headers['X-Parse-Master-Key'] = @master_key
@@ -61,27 +63,35 @@ module Parse
61
63
  end
62
64
 
63
65
  def find parse_class, object_id_or_conditions, opts={}
64
- if object_id_or_conditions.is_a? String
66
+ case object_id_or_conditions
67
+ when :all
68
+ find_by_query parse_class, opts
69
+ when String, Symbol
65
70
  find_by_id parse_class, object_id_or_conditions, opts
66
- elsif object_id_or_conditions.is_a? Hash
71
+ when Hash
67
72
  find_by_query parse_class, object_id_or_conditions
73
+ else
74
+ raise ArgumentError.new('the first argument should be a string, a symbol, or a hash.')
68
75
  end
69
76
  end
70
77
 
71
78
  def find_by_id parse_class, object_id, opts={}
72
- call_api :get, "classes/#{parse_class.parse_class_name}/#{object_id}" do |resp_body|
73
- convert parse_class, resp_body
74
-
79
+ parse_class_name = parse_class.is_a?(Parse::Object) \
80
+ ? parse_class.parse_class_name : parse_class
81
+ call_api :get, "classes/#{parse_class_name}/#{object_id}" do |resp_body|
75
82
  if opts.has_key? :include
76
- included_keys = opts[:include]
77
- included_keys = [included_keys] unless included_keys.is_a? Enumerable
83
+ included_keys = [opts[:include]].flatten
78
84
  included_keys.each do |included_key|
79
- pointer = resp_body[included_key]
80
- pointer.load
85
+ resp_body[included_key].tap do |pointer|
86
+ if pointer['__type'] == 'Pointer'
87
+ pointer['body'] = self.find_by_id pointer['className'], pointer['objectId']
88
+ else
89
+ raise ArgumentError.new('included column should be a pointer.')
90
+ end
91
+ end
81
92
  end
82
93
  end
83
-
84
- parse_class.new resp_body
94
+ resp_body
85
95
  end
86
96
  end
87
97
 
@@ -125,13 +135,13 @@ module Parse
125
135
  end
126
136
 
127
137
  def update parse_object, values
128
- call_api :put, "classes/#{parse_object.parse_class_name}/#{parse_object.obj_id}", values.to_json do |resp_body|
138
+ call_api :put, "classes/#{parse_object.parse_class_name}/#{parse_object.parse_object_id}", values.to_json do |resp_body|
129
139
  resp_body
130
140
  end
131
141
  end
132
142
 
133
143
  def delete parse_object
134
- call_api :delete, "classes/#{parse_object.parse_class_name}/#{parse_object.obj_id}" do |resp_body|
144
+ call_api :delete, "classes/#{parse_object.parse_class_name}/#{parse_object.parse_object_id}" do |resp_body|
135
145
  resp_body
136
146
  end
137
147
  end
@@ -178,25 +188,5 @@ module Parse
178
188
  def method_missing name, *args, &block
179
189
  call_function name, args.first
180
190
  end
181
-
182
- private
183
-
184
- def convert parse_class, resp_body
185
- resp_body.each do |k, v|
186
- if v.is_a?(Hash) && v.has_key?('__type')
187
- resp_body[k] = case v['__type']
188
- when 'Date'
189
- Date.parse v['iso']
190
- when 'File'
191
- Parse::File.new v
192
- when 'Pointer'
193
- # TODO: too many arguments
194
- Parse::Pointer.new self, parse_class, resp_body, k, v
195
- else
196
- v
197
- end
198
- end
199
- end
200
- end
201
191
  end
202
192
  end
@@ -9,7 +9,7 @@ module Parse
9
9
  req = eval("Net::HTTP::#{method.to_s.capitalize}").new endpoint, headers
10
10
  req.body = body if body
11
11
  client = Net::HTTP.new @host, 443
12
- #client.set_debug_output $stderr
12
+ client.set_debug_output $stderr if $DEBUG
13
13
  client.use_ssl = true
14
14
  client.start do
15
15
  resp = client.request req
data/lib/parse/object.rb CHANGED
@@ -5,10 +5,15 @@ module Parse
5
5
  }
6
6
 
7
7
  class Object
8
+ @@parse_class_vs_class_table = {}
8
9
 
9
10
  class << self
10
11
  attr_accessor :parse_class_name, :parse_client, :auto_camel_case
11
12
 
13
+ def register_parse_class parse_class
14
+ @@parse_class_vs_class_table[parse_class.parse_class_name] = parse_class
15
+ end
16
+
12
17
  def create parse_class_name, mod=::Object
13
18
  raise 'already defined' if mod.const_defined? parse_class_name
14
19
 
@@ -19,11 +24,12 @@ module Parse
19
24
  klass.parse_class_name = parse_class_name.to_sym
20
25
  klass.auto_camel_case = true
21
26
  mod.const_set parse_class_name, klass
27
+ register_parse_class klass
22
28
  end
23
29
  end
24
30
 
25
31
  def parse_class_name
26
- @parse_class_name || name.split('::').last
32
+ @parse_class_name ||= name.split('::').last
27
33
  end
28
34
 
29
35
  def parse_client
@@ -31,27 +37,65 @@ module Parse
31
37
  end
32
38
 
33
39
  def find object_id_or_conditions, opts={}
34
- parse_client.find self, object_id_or_conditions, opts
40
+ results = [parse_client.find(self, object_id_or_conditions, opts)].flatten
41
+ results.map! {|hash| self.new hash}
42
+ end
43
+
44
+ def find_by_id object_id, opts={}
45
+ find(object_id, opts).first
35
46
  end
36
47
 
48
+ # TODO: need refactoring
37
49
  def find! object_id_or_conditions, opts={}
38
- parse_client.find! self, object_id_or_conditions, opts
50
+ results = [parse_client.find!(self, object_id_or_conditions, opts)].flatten
51
+ results.map! {|hash| self.new hash}
52
+ end
53
+
54
+ def find_by_id! object_id, opts={}
55
+ find!(object_id, opts).first
56
+ end
57
+
58
+ def find_all opts={}
59
+ find :all, opts
60
+ end
61
+
62
+ def find_all! opts={}
63
+ find! :all, opts
39
64
  end
40
65
  end
41
66
 
42
- attr_accessor :obj_id, :created_at, :updated_at, :acl
67
+ attr_accessor :parse_object_id, :created_at, :updated_at, :acl
43
68
 
44
69
  def initialize hash={}
70
+ body_hash = nil
45
71
  hash = string_keyed_hash hash
46
72
  if hash.has_key? 'objectId'
47
- @obj_id = hash['objectId']
73
+ @parse_object_id = hash['objectId']
48
74
  @raw_hash = hash
49
75
  @updated_hash = {}
76
+ body_hash = @raw_hash
50
77
  else
51
78
  @raw_hash = {}
52
79
  @updated_hash = hash
80
+ body_hash = @updated_hash
53
81
  end
54
82
  @deleted = false
83
+
84
+ hash.each do |k, v|
85
+ if v.is_a? Hash
86
+ body_hash[k] =
87
+ case v['__type']
88
+ when 'Date'
89
+ Date.parse v['iso']
90
+ when 'File'
91
+ Parse::File.new v
92
+ when 'Pointer'
93
+ Parse::Pointer.new self, v
94
+ else
95
+ v
96
+ end
97
+ end
98
+ end
55
99
  end
56
100
 
57
101
  def new?
@@ -100,7 +144,7 @@ module Parse
100
144
  #parse_client.create(self, @updated_hash).tap do |response|
101
145
  method = use_master_key ? :create! : :create
102
146
  parse_client.send(method, self, @updated_hash).tap do |response|
103
- @obj_id = response['objectId']
147
+ @parse_object_id = response['objectId']
104
148
  @created_at = Date.parse response['createdAt']
105
149
  @updated_at = @created_at
106
150
  @raw_hash.update @updated_hash
@@ -143,10 +187,13 @@ module Parse
143
187
  delete true
144
188
  end
145
189
 
146
- def obj_id
147
- @obj_id || @raw_hash['objectId']
190
+ def parse_object_id
191
+ @parse_object_id || @raw_hash['objectId']
148
192
  end
149
193
 
194
+ alias obj_id parse_object_id
195
+ alias obj_id= parse_object_id=
196
+
150
197
  def get_column name
151
198
  name = name.to_s
152
199
  ret = @updated_hash[name]
data/lib/parse/pointer.rb CHANGED
@@ -1,25 +1,31 @@
1
1
  # coding:utf-8
2
2
  module Parse
3
3
  class Pointer
4
- def initialize parse_client, parent_parse_class, parent_hash, parent_key, hash
5
- @parse_client = parse_client
6
- @parent_parse_class = parent_parse_class
7
- @parent_hash = parent_hash
8
- @parent_key = parent_key
4
+ attr_reader :object
5
+
6
+ def initialize parent, hash
7
+ @parent_object = parent
9
8
  @raw_hash = hash
9
+
10
+ if @raw_hash.has_key? 'body'
11
+ @object = pointed_parse_class.new @raw_hash['body']
12
+ end
10
13
  end
11
14
 
12
- def load &block
13
- included_parse_class_name = @raw_hash['className']
14
- mod = @parent_parse_class.name.include?('::') ? \
15
- eval(@perent_parse_class.name.split('::')[0..-2]) : ::Object
16
- included_parse_class = Parse::Object included_parse_class_name, mod
17
- @parent_hash[@parent_key] = @parse_client.find(
18
- included_parse_class, @raw_hash['objectId']).tap do |real_value|
19
- if block
20
- block.call real_value
21
- end
15
+ def load
16
+ unless @object
17
+ @object = pointed_parse_class.find_by_id @raw_hash['objectId']
22
18
  end
19
+ @object
20
+ end
21
+
22
+ private
23
+
24
+ def pointed_parse_class
25
+ included_parse_class_name = @raw_hash['className']
26
+ mod = @parent_object.class.name.include?('::') ? \
27
+ eval(@perent_object.class.name.split('::')[0..-2]) : ::Object
28
+ Parse::Object included_parse_class_name, mod
23
29
  end
24
30
  end
25
31
  end
data/lib/parse/query.rb CHANGED
@@ -4,11 +4,15 @@ module Parse
4
4
  attr_accessor :parse_class_name, :parse_client
5
5
 
6
6
  def initialize parse_class_or_name=nil
7
- @parse_class, @parse_class_name, @parse_client =
8
- parse_class_or_name === Parse::Object \
9
- ? [parse_class_or_name, parse_class_or_name.parse_class_name,
10
- parse_class_or_name.parse_client]
11
- : [nil, parse_class_or_name.to_s, Parse::Client.default_client]
7
+ if parse_class_or_name.is_a?(Class) && parse_class_or_name < Parse::Object
8
+ @parse_class = parse_class_or_name
9
+ @parse_class_name = parse_class_or_name.parse_class_name
10
+ @parse_client = parse_class_or_name.parse_client
11
+ else
12
+ @parse_class = nil
13
+ @parse_class_name = parse_class_or_name.to_s
14
+ @parse_client = Parse::Client.default_client
15
+ end
12
16
  @limit = nil
13
17
  @skip = nil
14
18
  @count = false
@@ -249,7 +253,7 @@ module Parse
249
253
  def condition_value_to_s val
250
254
  case val
251
255
  when Parse::Object
252
- %Q|{"__type":"Pointer","className":"#{val.parse_class_name}","objectId":"#{val.obj_id}"}|
256
+ %Q|{"__type":"Pointer","className":"#{val.parse_class_name}","objectId":"#{val.parse_object_id}"}|
253
257
  else
254
258
  val.inspect
255
259
  end
data/lib/parse/user.rb CHANGED
@@ -28,7 +28,7 @@ module Parse
28
28
 
29
29
  def sign_up
30
30
  parse_client.sign_up @username, @password, opts do |resp_body|
31
- @obj_id = resp_body['objectId']
31
+ @parse_object_id = resp_body['objectId']
32
32
  @created_at = resp_body['createdAt']
33
33
  @raw_hash.update(@updated_hash).update resp_body
34
34
  @updated_hash.clear
@@ -39,7 +39,7 @@ module Parse
39
39
 
40
40
  def log_in
41
41
  parse_client.log_in @username, @password do |resp_body|
42
- @obj_id = resp_body['objectId']
42
+ @parse_object_id = resp_body['objectId']
43
43
  @created_at = resp_body['createdAt']
44
44
  @updated_at = resp_body['updatedAt']
45
45
  @raw_hash.update(@updated_hash).update resp_body
data/lib/parse/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Parse
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/parsecom.rb CHANGED
@@ -17,9 +17,9 @@ require 'parse/pointer'
17
17
  require 'parse/file'
18
18
 
19
19
  module Parse
20
- @@application_id = nil
21
- @@api_key = nil
22
- @@master_key = nil
20
+ @@application_id = ENV['PARSE_APPLICATION_ID']
21
+ @@api_key = ENV['PARSE_API_KEY']
22
+ @@master_key = ENV['PARSE_MASTER_KEY']
23
23
  @@auto_snake_case = false
24
24
 
25
25
  module_function
data/parsecom.gemspec CHANGED
@@ -19,4 +19,6 @@ Gem::Specification.new do |gem|
19
19
  gem.require_paths = ["lib"]
20
20
 
21
21
  gem.add_development_dependency "rspec"
22
+ gem.add_development_dependency "webmock"
23
+ gem.add_development_dependency "vcr"
22
24
  end
@@ -0,0 +1,168 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.parse.com/1/classes/ClassA/vI8RdTV68d
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ X-Parse-Application-Id:
11
+ - <X-Parse-Application-Id>
12
+ Content-Type:
13
+ - application/json
14
+ Accept:
15
+ - application/json
16
+ User-Agent:
17
+ - A parse.com client for ruby
18
+ X-Parse-Rest-Api-Key:
19
+ - <X-Parse-REST-API-Key>
20
+ User-Agent:
21
+ - Ruby
22
+ response:
23
+ status:
24
+ code: 200
25
+ message: OK
26
+ headers:
27
+ Access-Control-Allow-Origin:
28
+ - ! '*'
29
+ Access-Control-Request-Method:
30
+ - ! '*'
31
+ Cache-Control:
32
+ - max-age=0, private, must-revalidate
33
+ Content-Type:
34
+ - application/json; charset=utf-8
35
+ Date:
36
+ - Tue, 08 Oct 2013 13:18:30 GMT
37
+ Etag:
38
+ - ! '"5016c685bf75aea12be4bdc0726b8abb"'
39
+ Server:
40
+ - nginx/1.4.2
41
+ Set-Cookie:
42
+ - <COOKIE-KEY>
43
+ Status:
44
+ - 200 OK
45
+ X-Runtime:
46
+ - '0.190291'
47
+ X-Ua-Compatible:
48
+ - IE=Edge,chrome=1
49
+ Content-Length:
50
+ - '132'
51
+ Connection:
52
+ - keep-alive
53
+ body:
54
+ encoding: US-ASCII
55
+ string: ! '{"columnA":"Hello, parse.com","createdAt":"2013-10-08T13:18:28.749Z","updatedAt":"2013-10-08T13:18:28.749Z","objectId":"vI8RdTV68d"}'
56
+ http_version:
57
+ recorded_at: Tue, 08 Oct 2013 13:18:29 GMT
58
+ - request:
59
+ method: get
60
+ uri: https://api.parse.com/1/classes/ClassA?keys=columnB&limit=3&order=createdAt&where=%7B%22columnB%22:%7B%22$gt%22:5%7D%7D
61
+ body:
62
+ encoding: US-ASCII
63
+ string: ''
64
+ headers:
65
+ X-Parse-Application-Id:
66
+ - <X-Parse-Application-Id>
67
+ Content-Type:
68
+ - application/json
69
+ Accept:
70
+ - application/json
71
+ User-Agent:
72
+ - A parse.com client for ruby
73
+ X-Parse-Rest-Api-Key:
74
+ - <X-Parse-REST-API-Key>
75
+ User-Agent:
76
+ - Ruby
77
+ response:
78
+ status:
79
+ code: 200
80
+ message: OK
81
+ headers:
82
+ Access-Control-Allow-Origin:
83
+ - ! '*'
84
+ Access-Control-Request-Method:
85
+ - ! '*'
86
+ Cache-Control:
87
+ - max-age=0, private, must-revalidate
88
+ Content-Type:
89
+ - application/json; charset=utf-8
90
+ Date:
91
+ - Tue, 08 Oct 2013 13:18:31 GMT
92
+ Etag:
93
+ - ! '"b35ed59f2d61b8185524fd55b7570ed1"'
94
+ Server:
95
+ - nginx/1.4.2
96
+ Set-Cookie:
97
+ - <COOKIE-KEY>
98
+ Status:
99
+ - 200 OK
100
+ X-Runtime:
101
+ - '0.199730'
102
+ X-Ua-Compatible:
103
+ - IE=Edge,chrome=1
104
+ Content-Length:
105
+ - '367'
106
+ Connection:
107
+ - keep-alive
108
+ body:
109
+ encoding: US-ASCII
110
+ string: ! '{"results":[{"columnB":100,"createdAt":"2013-10-03T08:52:06.000Z","updatedAt":"2013-10-03T09:14:45.177Z","objectId":"UUqhbnuTYx"},{"columnB":100,"createdAt":"2013-10-03T09:13:55.850Z","updatedAt":"2013-10-03T09:14:42.814Z","objectId":"ZvYdVUQ6bM"},{"columnB":100,"createdAt":"2013-10-03T09:14:26.327Z","updatedAt":"2013-10-03T09:14:40.863Z","objectId":"gAU5Soepva"}]}'
111
+ http_version:
112
+ recorded_at: Tue, 08 Oct 2013 13:18:31 GMT
113
+ - request:
114
+ method: get
115
+ uri: https://api.parse.com/1/classes/ClassA?keys=columnB&limit=3&order=createdAt&where=%7B%22objectId%22:%22UUqhbnuTYx%22%7D
116
+ body:
117
+ encoding: US-ASCII
118
+ string: ''
119
+ headers:
120
+ X-Parse-Application-Id:
121
+ - <X-Parse-Application-Id>
122
+ Content-Type:
123
+ - application/json
124
+ Accept:
125
+ - application/json
126
+ User-Agent:
127
+ - A parse.com client for ruby
128
+ X-Parse-Rest-Api-Key:
129
+ - <X-Parse-REST-API-Key>
130
+ User-Agent:
131
+ - Ruby
132
+ response:
133
+ status:
134
+ code: 200
135
+ message: OK
136
+ headers:
137
+ Access-Control-Allow-Origin:
138
+ - ! '*'
139
+ Access-Control-Request-Method:
140
+ - ! '*'
141
+ Cache-Control:
142
+ - max-age=0, private, must-revalidate
143
+ Content-Type:
144
+ - application/json; charset=utf-8
145
+ Date:
146
+ - Tue, 08 Oct 2013 13:18:32 GMT
147
+ Etag:
148
+ - ! '"25e49608238780e90afc7e4a8342ce9c"'
149
+ Server:
150
+ - nginx/1.4.2
151
+ Set-Cookie:
152
+ - <COOKIE-KEY>
153
+ Status:
154
+ - 200 OK
155
+ X-Runtime:
156
+ - '0.091277'
157
+ X-Ua-Compatible:
158
+ - IE=Edge,chrome=1
159
+ Content-Length:
160
+ - '131'
161
+ Connection:
162
+ - keep-alive
163
+ body:
164
+ encoding: US-ASCII
165
+ string: ! '{"results":[{"columnB":100,"createdAt":"2013-10-03T08:52:06.000Z","updatedAt":"2013-10-03T09:14:45.177Z","objectId":"UUqhbnuTYx"}]}'
166
+ http_version:
167
+ recorded_at: Tue, 08 Oct 2013 13:18:32 GMT
168
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,58 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.parse.com/1/classes/ClassA
6
+ body:
7
+ encoding: UTF-8
8
+ string: ! '{"columnA":"Hello, parse.com"}'
9
+ headers:
10
+ X-Parse-Application-Id:
11
+ - <X-Parse-Application-Id>
12
+ Content-Type:
13
+ - application/json
14
+ Accept:
15
+ - application/json
16
+ User-Agent:
17
+ - A parse.com client for ruby
18
+ X-Parse-Rest-Api-Key:
19
+ - <X-Parse-REST-API-Key>
20
+ User-Agent:
21
+ - Ruby
22
+ response:
23
+ status:
24
+ code: 201
25
+ message: Created
26
+ headers:
27
+ Access-Control-Allow-Origin:
28
+ - ! '*'
29
+ Access-Control-Request-Method:
30
+ - ! '*'
31
+ Cache-Control:
32
+ - no-cache
33
+ Content-Type:
34
+ - application/json; charset=utf-8
35
+ Date:
36
+ - Tue, 08 Oct 2013 13:18:28 GMT
37
+ Location:
38
+ - https://api.parse.com/1/classes/ClassA/vI8RdTV68d
39
+ Server:
40
+ - nginx/1.4.2
41
+ Set-Cookie:
42
+ - <COOKIE-KEY>
43
+ Status:
44
+ - 201 Created
45
+ X-Runtime:
46
+ - '0.098102'
47
+ X-Ua-Compatible:
48
+ - IE=Edge,chrome=1
49
+ Content-Length:
50
+ - '64'
51
+ Connection:
52
+ - keep-alive
53
+ body:
54
+ encoding: US-ASCII
55
+ string: ! '{"createdAt":"2013-10-08T13:18:28.749Z","objectId":"vI8RdTV68d"}'
56
+ http_version:
57
+ recorded_at: Tue, 08 Oct 2013 13:18:28 GMT
58
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,117 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.parse.com/1/classes/ClassA/UUqhbnuTYx
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ X-Parse-Application-Id:
11
+ - <X-Parse-Application-Id>
12
+ Content-Type:
13
+ - application/json
14
+ Accept:
15
+ - application/json
16
+ User-Agent:
17
+ - A parse.com client for ruby
18
+ X-Parse-Rest-Api-Key:
19
+ - <X-Parse-REST-API-Key>
20
+ X-Parse-Session-Token:
21
+ - <X-Parse-Session-Token>
22
+ User-Agent:
23
+ - Ruby
24
+ response:
25
+ status:
26
+ code: 200
27
+ message: OK
28
+ headers:
29
+ Access-Control-Allow-Origin:
30
+ - ! '*'
31
+ Access-Control-Request-Method:
32
+ - ! '*'
33
+ Cache-Control:
34
+ - max-age=0, private, must-revalidate
35
+ Content-Type:
36
+ - application/json; charset=utf-8
37
+ Date:
38
+ - Tue, 08 Oct 2013 13:18:37 GMT
39
+ Etag:
40
+ - ! '"ae50cb0dce7ead5e1d206e7d1e658ceb"'
41
+ Server:
42
+ - nginx/1.4.2
43
+ Set-Cookie:
44
+ - <COOKIE-KEY>
45
+ Status:
46
+ - 200 OK
47
+ X-Runtime:
48
+ - '0.156641'
49
+ X-Ua-Compatible:
50
+ - IE=Edge,chrome=1
51
+ Content-Length:
52
+ - '207'
53
+ Connection:
54
+ - keep-alive
55
+ body:
56
+ encoding: US-ASCII
57
+ string: ! '{"columnA":"hello","columnB":100,"user":{"__type":"Pointer","className":"_User","objectId":"5VuUwoEe0j"},"createdAt":"2013-10-03T08:52:06.000Z","updatedAt":"2013-10-03T09:14:45.177Z","objectId":"UUqhbnuTYx"}'
58
+ http_version:
59
+ recorded_at: Tue, 08 Oct 2013 13:18:37 GMT
60
+ - request:
61
+ method: get
62
+ uri: https://api.parse.com/1/classes/_User/5VuUwoEe0j
63
+ body:
64
+ encoding: US-ASCII
65
+ string: ''
66
+ headers:
67
+ X-Parse-Application-Id:
68
+ - <X-Parse-Application-Id>
69
+ Content-Type:
70
+ - application/json
71
+ Accept:
72
+ - application/json
73
+ User-Agent:
74
+ - A parse.com client for ruby
75
+ X-Parse-Rest-Api-Key:
76
+ - <X-Parse-REST-API-Key>
77
+ X-Parse-Session-Token:
78
+ - <X-Parse-Session-Token>
79
+ User-Agent:
80
+ - Ruby
81
+ response:
82
+ status:
83
+ code: 200
84
+ message: OK
85
+ headers:
86
+ Access-Control-Allow-Origin:
87
+ - ! '*'
88
+ Access-Control-Request-Method:
89
+ - ! '*'
90
+ Cache-Control:
91
+ - max-age=0, private, must-revalidate
92
+ Content-Type:
93
+ - application/json; charset=utf-8
94
+ Date:
95
+ - Tue, 08 Oct 2013 13:18:40 GMT
96
+ Etag:
97
+ - ! '"7e3887e73da29bf2f8e12e5602a55e79"'
98
+ Server:
99
+ - nginx/1.4.2
100
+ Set-Cookie:
101
+ - <COOKIE-KEY>
102
+ Status:
103
+ - 200 OK
104
+ X-Runtime:
105
+ - '0.102107'
106
+ X-Ua-Compatible:
107
+ - IE=Edge,chrome=1
108
+ Content-Length:
109
+ - '128'
110
+ Connection:
111
+ - keep-alive
112
+ body:
113
+ encoding: US-ASCII
114
+ string: ! '{"username":"username149","createdAt":"2013-10-01T14:19:56.846Z","updatedAt":"2013-10-01T14:19:56.846Z","objectId":"5VuUwoEe0j"}'
115
+ http_version:
116
+ recorded_at: Tue, 08 Oct 2013 13:18:40 GMT
117
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,60 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.parse.com/1/login?password=password&username=username
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ X-Parse-Application-Id:
11
+ - <X-Parse-Application-Id>
12
+ Content-Type:
13
+ - application/json
14
+ Accept:
15
+ - application/json
16
+ User-Agent:
17
+ - A parse.com client for ruby
18
+ X-Parse-Rest-Api-Key:
19
+ - <X-Parse-REST-API-Key>
20
+ X-Parse-Session-Token:
21
+ - <X-Parse-Session-Token>
22
+ User-Agent:
23
+ - Ruby
24
+ response:
25
+ status:
26
+ code: 200
27
+ message: OK
28
+ headers:
29
+ Access-Control-Allow-Origin:
30
+ - ! '*'
31
+ Access-Control-Request-Method:
32
+ - ! '*'
33
+ Cache-Control:
34
+ - max-age=0, private, must-revalidate
35
+ Content-Type:
36
+ - application/json; charset=utf-8
37
+ Date:
38
+ - Tue, 08 Oct 2013 13:18:35 GMT
39
+ Etag:
40
+ - ! '"3b897a446e909397ccb9ea1b65668d01"'
41
+ Server:
42
+ - nginx/1.4.2
43
+ Set-Cookie:
44
+ - <COOKIE-KEY>
45
+ Status:
46
+ - 200 OK
47
+ X-Runtime:
48
+ - '0.145767'
49
+ X-Ua-Compatible:
50
+ - IE=Edge,chrome=1
51
+ Content-Length:
52
+ - '168'
53
+ Connection:
54
+ - keep-alive
55
+ body:
56
+ encoding: US-ASCII
57
+ string: ! '{"username":"username","createdAt":"2013-09-30T16:12:49.307Z","updatedAt":"2013-09-30T16:12:49.307Z","objectId":"HzHwHJpoRH","sessionToken":"cng37qr6lc33tmrvpf6jrnk00"}'
58
+ http_version:
59
+ recorded_at: Tue, 08 Oct 2013 13:18:35 GMT
60
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,58 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.parse.com/1/users
6
+ body:
7
+ encoding: UTF-8
8
+ string: ! '{"username":"username94","password":"password"}'
9
+ headers:
10
+ X-Parse-Application-Id:
11
+ - <X-Parse-Application-Id>
12
+ Content-Type:
13
+ - application/json
14
+ Accept:
15
+ - application/json
16
+ User-Agent:
17
+ - A parse.com client for ruby
18
+ X-Parse-Rest-Api-Key:
19
+ - <X-Parse-REST-API-Key>
20
+ User-Agent:
21
+ - Ruby
22
+ response:
23
+ status:
24
+ code: 201
25
+ message: Created
26
+ headers:
27
+ Access-Control-Allow-Origin:
28
+ - ! '*'
29
+ Access-Control-Request-Method:
30
+ - ! '*'
31
+ Cache-Control:
32
+ - no-cache
33
+ Content-Type:
34
+ - application/json; charset=utf-8
35
+ Date:
36
+ - Tue, 08 Oct 2013 13:18:33 GMT
37
+ Location:
38
+ - https://api.parse.com/1/users/xxT4YXUSyx
39
+ Server:
40
+ - nginx/1.4.2
41
+ Set-Cookie:
42
+ - <COOKIE-KEY>
43
+ Status:
44
+ - 201 Created
45
+ X-Runtime:
46
+ - '0.157749'
47
+ X-Ua-Compatible:
48
+ - IE=Edge,chrome=1
49
+ Content-Length:
50
+ - '107'
51
+ Connection:
52
+ - keep-alive
53
+ body:
54
+ encoding: US-ASCII
55
+ string: ! '{"createdAt":"2013-10-08T13:18:33.991Z","objectId":"xxT4YXUSyx","sessionToken":"ahgd26pwyt3b683iys74ye7fo"}'
56
+ http_version:
57
+ recorded_at: Tue, 08 Oct 2013 13:18:33 GMT
58
+ recorded_with: VCR 2.4.0
@@ -4,20 +4,20 @@ require 'parsecom'
4
4
 
5
5
  describe Parse::Client, 'when using master_key' do
6
6
  it 'should use api key' do
7
- client = Parse::Client.new# 'appid', 'apikey'
7
+ client = Parse::Client.new
8
8
  client.build_headers.keys.should be_include('X-Parse-REST-API-Key')
9
9
  client.build_headers.keys.should_not be_include('X-Parse-Master-Key')
10
10
  end
11
11
 
12
12
  it 'should use master key' do
13
- client = Parse::Client.new# 'appid', 'apikey', 'masterkey'
13
+ client = Parse::Client.new
14
14
  client.use_master_key!
15
15
  client.build_headers.keys.should_not be_include('X-Parse-REST-API-Key')
16
16
  client.build_headers.keys.should be_include('X-Parse-Master-Key')
17
17
  end
18
18
 
19
19
  it 'should raise an error when master_key is not set' do
20
- client = Parse::Client.new# 'appid', 'apikey'
20
+ client = Parse::Client.new
21
21
  client.master_key = nil
22
22
  expect {
23
23
  client.use_master_key!
@@ -32,23 +32,31 @@ describe Parse::Object, 'when it defines a parse class' do
32
32
  end
33
33
 
34
34
  describe Parse::Object, 'when it creates a new parse object' do
35
+ a_obj_id = nil
35
36
  it 'should create a parse object' do
36
- class_a = ClassA.new
37
- class_a.columnA = 'Hello, parse.com'
38
- class_a.new?.should be_true
39
- class_a.save
40
- class_a.new?.should be_false
41
-
42
- class_a2 = ClassA.find class_a.obj_id
43
- class_a2.columnA.should eql('Hello, parse.com')
44
-
45
- class_as = ClassA.find :where => proc{column(:columnB).gt 5},
46
- :order => 'createdAt', :keys => 'columnB', :limit => 3
47
- class_as.size.should == 3
48
-
49
- class_a = ClassA.find :where => {'objectId' => 'UUqhbnuTYx'},
50
- :order => 'createdAt', :keys => 'columnB', :limit => 3
51
- class_a.size.should == 1
37
+ VCR.use_cassette 'object_new' do
38
+ class_a = ClassA.new
39
+ class_a.columnA = 'Hello, parse.com'
40
+ class_a.new?.should be_true
41
+ class_a.save
42
+ class_a.new?.should be_false
43
+ a_obj_id = class_a.parse_object_id
44
+ end
45
+ end
46
+
47
+ it 'should create a parse object' do
48
+ VCR.use_cassette 'object_find' do
49
+ class_a2 = ClassA.find_by_id a_obj_id
50
+ class_a2.columnA.should eql('Hello, parse.com')
51
+
52
+ class_as = ClassA.find :where => proc{column(:columnB).gt 5},
53
+ :order => 'createdAt', :keys => 'columnB', :limit => 3
54
+ class_as.size.should == 3
55
+
56
+ class_a = ClassA.find :where => {'objectId' => 'UUqhbnuTYx'},
57
+ :order => 'createdAt', :keys => 'columnB', :limit => 3
58
+ class_a.size.should == 1
59
+ end
52
60
  end
53
61
  end
54
62
 
@@ -3,17 +3,21 @@ require 'spec_helper'
3
3
 
4
4
  describe Parse::User, 'when it signs up' do
5
5
  it 'should create new user' do
6
- user = Parse::User.sign_up "username#{rand 1000}", 'password'
7
- user.obj_id.should be_an_instance_of String
8
- user.parse_client.session_token.should be_an_instance_of String
6
+ VCR.use_cassette 'user_sign_up' do
7
+ user = Parse::User.sign_up "username#{rand 1000}", 'password'
8
+ user.parse_object_id.should be_an_instance_of String
9
+ user.parse_client.session_token.should be_an_instance_of String
10
+ end
9
11
  end
10
12
  end
11
13
 
12
14
  describe Parse::User, 'when it logs in' do
13
15
  it 'should get the session token' do
14
- user = Parse::User.log_in 'username', 'password'
15
- user.obj_id.should be_an_instance_of String
16
- user.parse_client.session_token.should be_an_instance_of String
16
+ VCR.use_cassette 'user_log_in' do
17
+ user = Parse::User.log_in 'username', 'password'
18
+ user.parse_object_id.should be_an_instance_of String
19
+ user.parse_client.session_token.should be_an_instance_of String
20
+ end
17
21
  end
18
22
  end
19
23
 
@@ -24,9 +28,13 @@ end
24
28
 
25
29
  describe Parse::User, 'when it is included in other query' do
26
30
  it 'should return a valid User object' do
27
- class_a = ClassA.find 'UUqhbnuTYx', :include => 'user'
28
- user = class_a.user
29
- user.should be_an_instance_of Parse::User
30
- user.obj_id.should == '5VuUwoEe0j'
31
+ VCR.use_cassette 'user_find' do
32
+ class_a = ClassA.find_by_id 'UUqhbnuTYx', :include => 'user'
33
+ user_pointer = class_a.user
34
+ user_pointer.should be_an_instance_of Parse::Pointer
35
+ user = user_pointer.object
36
+ user.should be_an_instance_of Parse::User
37
+ user.parse_object_id.should == '5VuUwoEe0j'
38
+ end
31
39
  end
32
40
  end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'rubygems'
2
+ require 'vcr'
2
3
 
3
4
  RSpec::Matchers.define :have_params do |expected|
4
5
  match do |actual|
@@ -8,7 +9,25 @@ RSpec::Matchers.define :have_params do |expected|
8
9
  end
9
10
  end
10
11
 
12
+ VCR.configure do |c|
13
+ c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
14
+ c.hook_into :webmock
15
+ c.allow_http_connections_when_no_cassette = true
16
+ c.filter_sensitive_data("<COOKIE-KEY>") { |i| [i.response.headers['Set-Cookie']].flatten.compact.first }
17
+
18
+ def filter_sensitive_header(c, header)
19
+ c.filter_sensitive_data("<#{header}>") do |interaction|
20
+ if v = interaction.request.headers.detect{|k,_| k.casecmp(header) == 0}
21
+ v.last.first
22
+ end
23
+ end
24
+ end
25
+
26
+ filter_sensitive_header(c, 'X-Parse-Application-Id')
27
+ filter_sensitive_header(c, 'X-Parse-Rest-Api-Key')
28
+ filter_sensitive_header(c, 'X-Parse-REST-API-Key')
29
+ filter_sensitive_header(c, 'X-Parse-Master-Key')
30
+ filter_sensitive_header(c, 'X-Parse-Session-Token')
31
+ end
32
+
11
33
  require 'parsecom'
12
- # setup Parse object
13
- Parse.credentials application_id: ENV['APPLICATION_ID'], api_key: ENV['API_KEY'], master_key: ENV['MASTER_KEY']
14
- #puts('set your credentials in spec/spec_helper.rb and remove this line') || exit
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.0.4
4
+ version: 0.0.5
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-04 00:00:00.000000000 Z
12
+ date: 2013-10-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -27,6 +27,38 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: webmock
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: vcr
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
30
62
  description: Pure Ruby version of parse.com client. This library allows you to access
31
63
  straightforwardly to parse.com REST API.
32
64
  email:
@@ -52,6 +84,11 @@ files:
52
84
  - lib/parse/version.rb
53
85
  - lib/parsecom.rb
54
86
  - parsecom.gemspec
87
+ - spec/fixtures/vcr_cassettes/object_find.yml
88
+ - spec/fixtures/vcr_cassettes/object_new.yml
89
+ - spec/fixtures/vcr_cassettes/user_find.yml
90
+ - spec/fixtures/vcr_cassettes/user_log_in.yml
91
+ - spec/fixtures/vcr_cassettes/user_sign_up.yml
55
92
  - spec/parse_client_spec.rb
56
93
  - spec/parse_object_spec.rb
57
94
  - spec/parse_query_spec.rb
@@ -83,6 +120,11 @@ signing_key:
83
120
  specification_version: 3
84
121
  summary: Pure Ruby version of parse.com client
85
122
  test_files:
123
+ - spec/fixtures/vcr_cassettes/object_find.yml
124
+ - spec/fixtures/vcr_cassettes/object_new.yml
125
+ - spec/fixtures/vcr_cassettes/user_find.yml
126
+ - spec/fixtures/vcr_cassettes/user_log_in.yml
127
+ - spec/fixtures/vcr_cassettes/user_sign_up.yml
86
128
  - spec/parse_client_spec.rb
87
129
  - spec/parse_object_spec.rb
88
130
  - spec/parse_query_spec.rb