parsecom 0.2.0 → 0.3.0

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 CHANGED
@@ -35,6 +35,22 @@ Yet-Another Parse.com Library written in Pure Ruby
35
35
  - [Linking Users](#linking-users)
36
36
  - [Roles](#roles)
37
37
  - [Creating Roles](#creating-roles)
38
+ - [Retrieving Roles](#retrieving-roles)
39
+ - [Updating Roles](#updating-roles)
40
+ - [Deleting Roles](#deleting-roles)
41
+ - [Files](#files)
42
+ - [Uploading Files](#uploading-files)
43
+ - [Associating with Objects](#associating-with-objects)
44
+ - [Deleting Files](#deleting-files)
45
+ - [Analytics](#analytics)
46
+ - [TBD](#tbd-2)
47
+ - [Push Notifications](#push-notifications)
48
+ - [TBD](#tbd-3)
49
+ - [Installations](#installations)
50
+ - [TBD](#tbd-4)
51
+ - [Cloud Functions](#cloud-functions)
52
+ - [GeoPoints](#geopoints)
53
+ - [TBD](#tbd-5)
38
54
  - [Security](#security)
39
55
 
40
56
  ## Usage
@@ -329,7 +345,7 @@ game_scores = GameScore.find :where => proc {
329
345
 
330
346
  #### Counting Objects
331
347
 
332
- TBD
348
+ ##### TBD
333
349
 
334
350
  #### Compound Queries
335
351
 
@@ -388,7 +404,7 @@ user.delete
388
404
 
389
405
  #### Linking Users
390
406
 
391
- TBD
407
+ ##### TBD
392
408
 
393
409
  ### Roles
394
410
 
@@ -428,7 +444,7 @@ role.save
428
444
  ```ruby
429
445
  removed_role = Parse::Role.new 'objectId' => 'Ed1nuqPvc'
430
446
  role = Parse::Role.find_by_id 'mrmBZvsErB'
431
- role.roles = Parse::Op::RemoveRelation.new removed_role
447
+ role.roles = Parse::Op::RemoveRelation.new removed_role.pointer
432
448
  role.save
433
449
  ```
434
450
 
@@ -441,7 +457,56 @@ role.delete
441
457
 
442
458
  ### Files
443
459
 
444
- TBD
460
+ #### Uploading Files
461
+
462
+ ```ruby
463
+ file = Parse::File.new :name => 'hello.txt', :content => 'Hello, World!'
464
+ file.save
465
+ file.url # => "http://files.parse.com/7883...223/7480...b6d-hello.txt"
466
+ ```
467
+
468
+ ```ruby
469
+ file = Parse::File.new :name => 'myPicture.jpg', :content => './myPicture.jpg'
470
+ file.save
471
+ file.url # => "http://files.parse.com/7883...223/81c7...bdf-myPicture.jpg"
472
+ ```
473
+
474
+ #### Associating with Objects
475
+
476
+ ```ruby
477
+ file = Parse::File.new :name => 'profile.png', :content => './profile.png'
478
+ profile = PlayerProfile.new 'name' => 'Andrew', 'picture' => file
479
+ profile.save
480
+ ```
481
+
482
+ #### Deleting Files
483
+
484
+ ```ruby
485
+ file.delete!
486
+ ```
487
+
488
+ ### Analytics
489
+
490
+ #### TBD
491
+
492
+ ### Push Notifications
493
+
494
+ #### TBD
495
+
496
+ ### Installations
497
+
498
+ #### TBD
499
+
500
+ ### Cloud Functions
501
+
502
+ ```ruby
503
+ client = Parse::Client.new
504
+ client.hello
505
+ ```
506
+
507
+ ### GeoPoints
508
+
509
+ #### TBD
445
510
 
446
511
  ### Security
447
512
 
@@ -62,7 +62,7 @@ module Parse
62
62
  headers['X-Parse-REST-API-Key'] = @api_key
63
63
  end
64
64
  headers['X-Parse-Session-Token'] = @session_token if @session_token
65
- headers.update opt_headers
65
+ headers.update(opt_headers).delete_if {|k, v| v.nil?}
66
66
  end
67
67
 
68
68
  def sign_up username, password, opts={}, &block
@@ -1,17 +1,43 @@
1
1
  # encoding:utf-8
2
2
  module Parse
3
3
  class File
4
- attr_accessor :name, :url
4
+ attr_accessor :name, :url, :content, :type
5
5
 
6
6
  def initialize hash
7
- @raw_hash = hash
8
- @name = hash['name']
7
+ @name = hash['name'] || hash[:name]
8
+ raise 'name is mandatory' unless @name
9
9
  @url = hash['url']
10
+ @content = hash['content']
11
+ @type = hash['type'] || {
12
+ '.txt' => 'text/plain',
13
+ '.html' => 'text/html',
14
+ '.jpg' => 'image/jpeg',
15
+ '.jpeg' => 'image/jpeg',
16
+ '.png' => 'image/png',
17
+ '.gif' => 'image/gif'
18
+ }[::File.extname(@name).downcase]
19
+ @client = hash['parce_client'] || Parse::Client.default
20
+ end
21
+
22
+ def save
23
+ raise "Files cannot be updated." if @url
24
+ @content = ::File.read @content if @type =~ %r|^image/|
25
+ @client.call_api :post, "files/#{@name}", @content, 'Content-Type' => @type, 'Accept' => nil do |resp_body|
26
+ @name = resp_body['name']
27
+ @url = resp_body['url']
28
+ end
29
+ end
30
+
31
+ def delete!
32
+ raise "File should be fetched" unless @url
33
+ @client.use_master_key do
34
+ @client.call_api :delete, "files/#{@name}", nil, 'Content-Type' => nil, 'Accept' => nil
35
+ end
10
36
  end
11
37
 
12
38
  def load &block
13
- open @url do |data| @data = data.read end unless @data
14
- block.call @data
39
+ open @url do |content| @content = content.read end unless @content
40
+ block.call @content
15
41
  end
16
42
 
17
43
  def store filepath=nil
@@ -19,18 +45,29 @@ module Parse
19
45
  raise 'filepath is mandatory' unless filepath
20
46
 
21
47
  FileUtils.mkdir_p ::File.dirname(filepath)
22
- load do |data|
48
+ load do |content|
23
49
  open filepath, 'wb' do |file|
24
- file.write data
50
+ file.write content
25
51
  end
26
52
  end
27
53
  end
28
54
 
29
55
  def inspect
30
- data, @data = @data, '..snip..'
56
+ content, @content = @content, '..snip..'
31
57
  ret = super
32
- @data = data
58
+ @content = content
33
59
  ret
34
60
  end
61
+
62
+ def to_h
63
+ {
64
+ "__type" => "File",
65
+ "name" => @name
66
+ }
67
+ end
68
+
69
+ def to_json *args
70
+ to_h.to_json
71
+ end
35
72
  end
36
73
  end
@@ -14,8 +14,9 @@ module Parse
14
14
  client.set_debug_output $stderr if $DEBUG
15
15
  client.use_ssl = true
16
16
  client.start do
17
+ # TODO
17
18
  resp = client.request req
18
- resp_body = JSON.parse resp.body
19
+ resp_body = resp.body.empty? ? nil : JSON.parse(resp.body)
19
20
  raise StandardError.new "error calling #{endpoint}: #{
20
21
  resp_body['error']}" if resp_body.is_a?(Hash) && resp_body.has_key?('error')
21
22
  block.call resp_body if block
@@ -1,3 +1,3 @@
1
1
  module Parse
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  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.2.0
4
+ version: 0.3.0
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-18 00:00:00.000000000 Z
12
+ date: 2013-10-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec