parsecom 0.5.3 → 0.5.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/lib/parse/client.rb CHANGED
@@ -5,7 +5,7 @@ module Parse
5
5
  API_VERSION = 1
6
6
  @@default_client = nil
7
7
 
8
- attr_accessor :http_client, :session_token, :master_key
8
+ attr_accessor :http_client, :session_token, :application_id, :api_key, :master_key
9
9
 
10
10
  def self.default
11
11
  @@default_client ||= new
@@ -28,7 +28,7 @@ module Parse
28
28
  @http_client = http_client || Parse::HttpClient.new(API_SERVER)
29
29
  end
30
30
 
31
- def canonical_endpoint endpoint
31
+ def canonicalize_endpoint endpoint
32
32
  if endpoint =~ %r</#{API_VERSION}/classes/_(User|Role|Installation)>
33
33
  endpoint.sub %r</#{API_VERSION}/classes/_(User|Role|Installation)>, "/#{API_VERSION}/#{$1.downcase}s"
34
34
  else
@@ -38,7 +38,7 @@ module Parse
38
38
 
39
39
  def call_api method, endpoint, body=nil, opt_headers={}, &block
40
40
  endpoint = "/#{API_VERSION}/#{endpoint}" unless endpoint[0] == '/'
41
- endpoint = canonical_endpoint endpoint
41
+ endpoint = canonicalize_endpoint endpoint
42
42
  headers = build_headers opt_headers
43
43
  if body.is_a?(Hash)
44
44
  body = Hash[*(body.to_a.map{|k, v| [k, URI.encode(v.to_s)]}.flatten)].to_json
data/lib/parse/object.rb CHANGED
@@ -237,8 +237,38 @@ module Parse
237
237
  Pointer.new 'className' => parse_class_name, 'objectId' => parse_object_id
238
238
  end
239
239
 
240
+ def to_h
241
+ {"__type" => self.class.name}.update(@raw_hash).update(@updated_hash)
242
+ ret = {}
243
+ {"__type" => self.class.name}.update(@raw_hash).update(@updated_hash).each do |k, v|
244
+ ret[k] =
245
+ case v
246
+ when Parse::Pointer
247
+ v.to_h
248
+ when Parse::Object
249
+ v.to_h
250
+ when Parse::Relation
251
+ '<Ralations>'
252
+ else
253
+ v.to_s
254
+ end
255
+ end
256
+ ret
257
+ =begin
258
+ Hash[
259
+ *({"__type" => self.class.name}.update(@raw_hash.dup).update(@updated_hash.dup).to_a.map do |a|
260
+ [a[0], a[1].to_h]
261
+ end.flatten(1))
262
+ ]
263
+ =end
264
+ end
265
+
266
+ def to_json *args
267
+ to_h.to_json
268
+ end
269
+
240
270
  def to_s
241
- "<#{parse_class_name}: #{{}.update(@raw_hash).update(@updated_hash).to_s}>"
271
+ to_h.to_s
242
272
  end
243
273
 
244
274
  def method_missing name, *args, &block
data/lib/parse/pointer.rb CHANGED
@@ -17,6 +17,11 @@ module Parse
17
17
  @object ||= pointed_parse_class.find_by_id @raw_hash['objectId']
18
18
  end
19
19
 
20
+ # TODO: should be refactored
21
+ def load!
22
+ @object ||= pointed_parse_class.find_by_id! @raw_hash['objectId']
23
+ end
24
+
20
25
  def to_h
21
26
  {
22
27
  "__type" => "Pointer",
@@ -37,6 +37,19 @@ module Parse
37
37
  @objects
38
38
  end
39
39
 
40
+ # TODO should be refactored
41
+ def load! parse_client=Parse::Client.default
42
+ unless @objects
43
+ pointer = @parent_object.pointer
44
+ key = @column_name
45
+ related_class = Parse::Object @raw_hash['className']
46
+ @objects = related_class.find! :where => proc {
47
+ related_to key, pointer
48
+ }
49
+ end
50
+ @objects
51
+ end
52
+
40
53
  def changed?
41
54
  (@added_pointers.size + @removed_pointers.size) != 0
42
55
  end
@@ -61,7 +74,6 @@ module Parse
61
74
  end
62
75
 
63
76
  def to_json *args
64
- p to_h
65
77
  to_h.to_json
66
78
  end
67
79
  end
data/lib/parse/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Parse
2
- VERSION = "0.5.3"
2
+ VERSION = "0.5.4"
3
3
  end
data/lib/parsecom.rb CHANGED
@@ -84,4 +84,8 @@ module Parse
84
84
  def auto_snake_case= auto_snake_case
85
85
  @@auto_snake_case = auto_snake_case
86
86
  end
87
+
88
+ def use_master_key!
89
+ Parse::Client.default.use_master_key!
90
+ end
87
91
  end
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.5.3
4
+ version: 0.5.4
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-11-14 00:00:00.000000000 Z
12
+ date: 2013-11-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec