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 +3 -3
 - data/lib/parse/object.rb +31 -1
 - data/lib/parse/pointer.rb +5 -0
 - data/lib/parse/relation.rb +13 -1
 - data/lib/parse/version.rb +1 -1
 - data/lib/parsecom.rb +4 -0
 - metadata +2 -2
 
    
        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  
     | 
| 
      
 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 =  
     | 
| 
      
 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 
     | 
    
         
            -
                   
     | 
| 
      
 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",
         
     | 
    
        data/lib/parse/relation.rb
    CHANGED
    
    | 
         @@ -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
    
    
    
        data/lib/parsecom.rb
    CHANGED
    
    
    
        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. 
     | 
| 
      
 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- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2013-11-17 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       14 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       15 
15 
     | 
    
         
             
              name: rspec
         
     |