parse-ruby-client 0.1.11 → 0.1.12

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.
@@ -0,0 +1,170 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.parse.com/1/files/hello_test.txt
6
+ body:
7
+ encoding: US-ASCII
8
+ string: Testing Hello World!
9
+ headers:
10
+ Content-Type:
11
+ - text/plain
12
+ Accept:
13
+ - application/json
14
+ User-Agent:
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:
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
+ VGh1LCAyNCBKYW4gMjAxMyAyMzozOTo1OSBHTVQ=
47
+ !binary "TG9jYXRpb24=":
48
+ - !binary |-
49
+ aHR0cDovL2ZpbGVzLnBhcnNlLmNvbS8zNzJmY2JiOS03ZWFlLTRiOWEtYWJj
50
+ OC02ZGE5N2ZjYWM1MGQvYWE4NzY4YTQtMTBlMS00YzAyLTkyMGQtODRmNmFk
51
+ OTAwMzBhLWhlbGxvX3Rlc3QudHh0
52
+ !binary "U2VydmVy":
53
+ - !binary |-
54
+ bmdpbngvMS4yLjI=
55
+ !binary "U2V0LUNvb2tpZQ==":
56
+ - !binary |-
57
+ X3BhcnNlX3Nlc3Npb249QkFoN0Jra2lEM05sYzNOcGIyNWZhV1FHT2daRlJp
58
+ SWxaVEJtWXpRek16azVZalZqTnpSaU9HSm1NMlUxTkRaaU5tWXdOVFkzTTJN
59
+ JTNELS01MmFjZTdkNDY3YjM1YTM5YjU0MGNjNDQ3MjFhMTI1ODlhYWE4YzBm
60
+ OyBkb21haW49LnBhcnNlLmNvbTsgcGF0aD0vOyBleHBpcmVzPVR1ZSwgMjQt
61
+ SmFuLTIwMjMgMjM6Mzk6NTkgR01UOyBzZWN1cmU7IEh0dHBPbmx5
62
+ !binary "U3RhdHVz":
63
+ - !binary |-
64
+ MjAxIENyZWF0ZWQ=
65
+ !binary "WC1SdW50aW1l":
66
+ - !binary |-
67
+ MC4yMDUxMzE=
68
+ !binary "WC1VYS1Db21wYXRpYmxl":
69
+ - !binary |-
70
+ SUU9RWRnZSxjaHJvbWU9MQ==
71
+ !binary "Q29udGVudC1MZW5ndGg=":
72
+ - !binary |-
73
+ MTgy
74
+ !binary "Q29ubmVjdGlvbg==":
75
+ - !binary |-
76
+ a2VlcC1hbGl2ZQ==
77
+ body:
78
+ encoding: ASCII-8BIT
79
+ string: !binary |-
80
+ eyJ1cmwiOiJodHRwOi8vZmlsZXMucGFyc2UuY29tLzM3MmZjYmI5LTdlYWUt
81
+ NGI5YS1hYmM4LTZkYTk3ZmNhYzUwZC9hYTg3NjhhNC0xMGUxLTRjMDItOTIw
82
+ ZC04NGY2YWQ5MDAzMGEtaGVsbG9fdGVzdC50eHQiLCJuYW1lIjoiYWE4NzY4
83
+ YTQtMTBlMS00YzAyLTkyMGQtODRmNmFkOTAwMzBhLWhlbGxvX3Rlc3QudHh0
84
+ In0=
85
+ http_version:
86
+ recorded_at: Thu, 24 Jan 2013 23:39:59 GMT
87
+ - request:
88
+ method: post
89
+ uri: https://api.parse.com/1/files/hello.txt
90
+ body:
91
+ encoding: US-ASCII
92
+ string: Hello World!
93
+ headers:
94
+ Content-Type:
95
+ - application/json
96
+ Accept:
97
+ - application/json
98
+ User-Agent:
99
+ - Parse for Ruby, 0.0
100
+ X-Parse-Master-Key:
101
+ - ''
102
+ X-Parse-Rest-Api-Key:
103
+ - D3Y8jNCQk6kpkKhpRGnWLYTrFGQ7j8dtDVnWZRnZ
104
+ X-Parse-Application-Id:
105
+ - PPVk6L5M9R1R8GVk8Ye9jT8f5SQNBIeoJUDJLmkT
106
+ X-Parse-Session-Token:
107
+ - ''
108
+ Expect:
109
+ - ''
110
+ response:
111
+ status:
112
+ code: 201
113
+ message: !binary |-
114
+ Q3JlYXRlZA==
115
+ headers:
116
+ !binary "QWNjZXNzLUNvbnRyb2wtQWxsb3ctT3JpZ2lu":
117
+ - !binary |-
118
+ Kg==
119
+ !binary "QWNjZXNzLUNvbnRyb2wtUmVxdWVzdC1NZXRob2Q=":
120
+ - !binary |-
121
+ Kg==
122
+ !binary "Q2FjaGUtQ29udHJvbA==":
123
+ - !binary |-
124
+ bm8tY2FjaGU=
125
+ !binary "Q29udGVudC1UeXBl":
126
+ - !binary |-
127
+ YXBwbGljYXRpb24vanNvbjsgY2hhcnNldD11dGYtOA==
128
+ !binary "RGF0ZQ==":
129
+ - !binary |-
130
+ VGh1LCAyNCBKYW4gMjAxMyAyMzo1MDoxMiBHTVQ=
131
+ !binary "TG9jYXRpb24=":
132
+ - !binary |-
133
+ aHR0cDovL2ZpbGVzLnBhcnNlLmNvbS8zNzJmY2JiOS03ZWFlLTRiOWEtYWJj
134
+ OC02ZGE5N2ZjYWM1MGQvYzJjMTI1YTQtMDU5Ni00ZmEwLTljYWEtZGQzYTAy
135
+ MDQ3NmVhLWhlbGxvLnR4dA==
136
+ !binary "U2VydmVy":
137
+ - !binary |-
138
+ bmdpbngvMS4yLjI=
139
+ !binary "U2V0LUNvb2tpZQ==":
140
+ - !binary |-
141
+ X3BhcnNlX3Nlc3Npb249QkFoN0Jra2lEM05sYzNOcGIyNWZhV1FHT2daRlJp
142
+ SWxabU5pT1RjeE56VTVaR1l3T0RGbE5EazJaREkwTm1ZMVl6VmpaakF5WkRr
143
+ JTNELS0zMmY3NThhZmVjMDM4OGE4ZDI1ZGJkMmMwZmFmMzIwODk0MmU1ZWQ4
144
+ OyBkb21haW49LnBhcnNlLmNvbTsgcGF0aD0vOyBleHBpcmVzPVR1ZSwgMjQt
145
+ SmFuLTIwMjMgMjM6NTA6MTIgR01UOyBzZWN1cmU7IEh0dHBPbmx5
146
+ !binary "U3RhdHVz":
147
+ - !binary |-
148
+ MjAxIENyZWF0ZWQ=
149
+ !binary "WC1SdW50aW1l":
150
+ - !binary |-
151
+ MC4xMTg5ODE=
152
+ !binary "WC1VYS1Db21wYXRpYmxl":
153
+ - !binary |-
154
+ SUU9RWRnZSxjaHJvbWU9MQ==
155
+ !binary "Q29udGVudC1MZW5ndGg=":
156
+ - !binary |-
157
+ MTcy
158
+ !binary "Q29ubmVjdGlvbg==":
159
+ - !binary |-
160
+ a2VlcC1hbGl2ZQ==
161
+ body:
162
+ encoding: ASCII-8BIT
163
+ string: !binary |-
164
+ eyJ1cmwiOiJodHRwOi8vZmlsZXMucGFyc2UuY29tLzM3MmZjYmI5LTdlYWUt
165
+ NGI5YS1hYmM4LTZkYTk3ZmNhYzUwZC9jMmMxMjVhNC0wNTk2LTRmYTAtOWNh
166
+ YS1kZDNhMDIwNDc2ZWEtaGVsbG8udHh0IiwibmFtZSI6ImMyYzEyNWE0LTA1
167
+ OTYtNGZhMC05Y2FhLWRkM2EwMjA0NzZlYS1oZWxsby50eHQifQ==
168
+ http_version:
169
+ recorded_at: Thu, 24 Jan 2013 23:50:12 GMT
170
+ recorded_with: VCR 2.0.1
data/lib/parse/client.rb CHANGED
@@ -37,12 +37,16 @@ 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)
40
+ def request(uri, method = :get, body = nil, query = nil, content_type = 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
44
44
  @session.headers[Protocol::HEADER_SESSION_TOKEN] = @session_token
45
45
 
46
+ if content_type
47
+ @session.headers["Content-Type"] = content_type
48
+ end
49
+
46
50
  options = {}
47
51
  if body
48
52
  options[:data] = body
@@ -61,6 +65,10 @@ module Parse
61
65
  raise ParseProtocolError.new(parsed)
62
66
  end
63
67
 
68
+ if content_type
69
+ @session.headers["Content-Type"] = "application/json"
70
+ end
71
+
64
72
  return parsed
65
73
  rescue Patron::TimeoutError
66
74
  retry if num_tries <= max_retries
@@ -306,15 +306,23 @@ module Parse
306
306
 
307
307
  # File
308
308
  # ------------------------------------------------------------
309
-
309
+ # tf = Parse::File.new(:body => "Hello World!", :local_filename => "hello.txt")
310
+ # tf.save
310
311
  class File
311
312
  # '{"avatar": {"__type":"File", "name":"profile.png", "url"=>"http://files.parse.com/blah/profile.png"}}'
312
- attr_accessor :name
313
+ attr_accessor :local_filename # eg "hello.txt"
314
+ attr_accessor :parse_filename # eg "12-4-532d-d-g3-3-hello.text"
315
+ attr_accessor :content_type
316
+ attr_accessor :body
313
317
  attr_accessor :url
314
318
 
315
319
  def initialize(data)
316
- @name = data["name"]
317
- @url = data["url"]
320
+ data = Hash[data.map{ |k, v| [k.to_s, v] }] # convert hash keys to strings
321
+ @local_filename = data["local_filename"] if data["local_filename"]
322
+ @parse_filename = data["parse_filename"] if data["parse_filename"]
323
+ @content_type = data["content_type"] if data["content_type"]
324
+ @url = data["url"] if data["url"]
325
+ @body = data["body"] if data["body"]
318
326
  end
319
327
 
320
328
  def eql?(other)
@@ -328,18 +336,25 @@ module Parse
328
336
  url.hash
329
337
  end
330
338
 
339
+ def save
340
+ uri = Parse::Protocol.file_uri(@local_filename)
341
+ resp = Parse.client.request(uri, :post, @body, nil, @content_type)
342
+ @parse_filename = resp["name"]
343
+ @url = resp["url"]
344
+ resp
345
+ end
346
+
331
347
  def as_json(*a)
332
348
  {
333
- Protocol::KEY_TYPE => Protocol::TYPE_FILE,
334
- "name" => @name,
335
- "url" => @url
349
+ Protocol::KEY_TYPE => Protocol::TYPE_FILE,
350
+ "name" => @parse_filename,
351
+ "url" => @url
336
352
  }
337
353
  end
338
354
 
339
355
  def to_json(*a)
340
- as_json.to_json(*a)
356
+ as_json.to_json(*a)
341
357
  end
342
358
  end
343
359
 
344
-
345
360
  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.11"
8
+ s.version = "0.1.12"
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-24"
12
+ s.date = "2013-01-29"
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 = [
@@ -36,7 +36,10 @@ Gem::Specification.new do |s|
36
36
  "fixtures/vcr_cassettes/test_created_at.yml",
37
37
  "fixtures/vcr_cassettes/test_deep_parse.yml",
38
38
  "fixtures/vcr_cassettes/test_destroy.yml",
39
+ "fixtures/vcr_cassettes/test_file_save.yml",
39
40
  "fixtures/vcr_cassettes/test_get.yml",
41
+ "fixtures/vcr_cassettes/test_image_file_associate_with_object.yml",
42
+ "fixtures/vcr_cassettes/test_image_file_save.yml",
40
43
  "fixtures/vcr_cassettes/test_include.yml",
41
44
  "fixtures/vcr_cassettes/test_new_model.yml",
42
45
  "fixtures/vcr_cassettes/test_new_object.yml",
@@ -47,6 +50,7 @@ Gem::Specification.new do |s|
47
50
  "fixtures/vcr_cassettes/test_request_batch.yml",
48
51
  "fixtures/vcr_cassettes/test_server_update.yml",
49
52
  "fixtures/vcr_cassettes/test_simple_save.yml",
53
+ "fixtures/vcr_cassettes/test_text_file_save.yml",
50
54
  "fixtures/vcr_cassettes/test_update.yml",
51
55
  "fixtures/vcr_cassettes/test_updated_at.yml",
52
56
  "fixtures/vcr_cassettes/test_user_save.yml",
@@ -67,10 +71,12 @@ Gem::Specification.new do |s|
67
71
  "test/cloud_functions/MyCloudCode/cloud/main.js",
68
72
  "test/config/global.json",
69
73
  "test/helper.rb",
74
+ "test/parsers.jpg",
70
75
  "test/test_batch.rb",
71
76
  "test/test_client.rb",
72
77
  "test/test_cloud.rb",
73
78
  "test/test_datatypes.rb",
79
+ "test/test_file.rb",
74
80
  "test/test_init.rb",
75
81
  "test/test_init_from_cloud_code.rb",
76
82
  "test/test_model.rb",
data/test/parsers.jpg ADDED
Binary file
@@ -75,16 +75,19 @@ class TestDatatypes < Test::Unit::TestCase
75
75
  assert_equal gp, q["location"]
76
76
  end
77
77
 
78
- def test_file
79
- data = {"name" => "blah.png"}
80
- file = Parse::File.new(data)
81
- assert_equal JSON.parse(file.to_json)["name"], data["name"]
82
- assert_equal JSON.parse(file.to_json)[Parse::Protocol::KEY_TYPE], Parse::Protocol::TYPE_FILE
83
78
 
84
- post = Parse::Object.new("Post")
85
- post["avatar"] = file
86
- post.save
87
- q = Parse.get("Post", post.id)
88
- assert_equal file.name, q["avatar"].name
89
- end
79
+ # deprecating - see test_file.rb for new implementation
80
+ # ----------------------------
81
+ #def test_file
82
+ # data = {"name" => "test/parsers.png"}
83
+ # file = Parse::File.new(data)
84
+ # assert_equal JSON.parse(file.to_json)["name"], data["name"]
85
+ # assert_equal JSON.parse(file.to_json)[Parse::Protocol::KEY_TYPE], Parse::Protocol::TYPE_FILE
86
+
87
+ # post = Parse::Object.new("Post")
88
+ # post["avatar"] = file
89
+ # post.save
90
+ # q = Parse.get("Post", post.id)
91
+ # assert_equal file.parse_filename, q["avatar"].parse_filename
92
+ #end
90
93
  end
data/test/test_file.rb ADDED
@@ -0,0 +1,68 @@
1
+ require 'helper'
2
+
3
+ class TestFile < Test::Unit::TestCase
4
+ def setup
5
+ Parse.init
6
+ end
7
+
8
+ def test_file_save
9
+ VCR.use_cassette('test_text_file_save', :record => :new_episodes) do
10
+ tf = Parse::File.new({
11
+ :body => "Hello World!",
12
+ :local_filename => "hello.txt",
13
+ :content_type => "text/plain"
14
+ })
15
+ tf.save
16
+
17
+ assert tf.local_filename
18
+ assert tf.url
19
+ assert tf.parse_filename
20
+ assert tf.body
21
+ assert tf.to_json
22
+ assert_equal String, tf.body.class
23
+ end
24
+ end
25
+
26
+ def test_image_save
27
+ #VCR.use_cassette('test_image_file_save', :record => :new_episodes) do
28
+ tf = Parse::File.new({
29
+ :body => IO.read("test/parsers.jpg"),
30
+ :local_filename => "parsers.jpg",
31
+ :content_type => "image/jpeg"
32
+ })
33
+ tf.save
34
+
35
+ assert tf.local_filename
36
+ assert tf.url
37
+ assert tf.parse_filename
38
+ assert tf.body
39
+ assert tf.to_json
40
+ #end
41
+ end
42
+
43
+ def test_associate_with_object
44
+ #VCR.use_cassette('test_image_file_associate_with_object', :record => :new_episodes) do
45
+ tf = Parse::File.new({
46
+ :body => IO.read("test/parsers.jpg"),
47
+ :local_filename => "parsers.jpg",
48
+ :content_type => "image/jpeg"
49
+ })
50
+ tf.save
51
+
52
+ assert tf.local_filename
53
+ assert tf.url
54
+ assert tf.parse_filename
55
+ assert tf.body
56
+ assert tf.to_json
57
+
58
+ object = Parse::Object.new("ShouldHaveFile")
59
+ object["photo"] = tf
60
+ object.save
61
+
62
+ assert object["photo"]
63
+ assert object["objectId"]
64
+ #end
65
+ end
66
+
67
+
68
+ end
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.11
4
+ version: 0.1.12
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-24 00:00:00.000000000 Z
13
+ date: 2013-01-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: patron
@@ -183,7 +183,10 @@ files:
183
183
  - fixtures/vcr_cassettes/test_created_at.yml
184
184
  - fixtures/vcr_cassettes/test_deep_parse.yml
185
185
  - fixtures/vcr_cassettes/test_destroy.yml
186
+ - fixtures/vcr_cassettes/test_file_save.yml
186
187
  - fixtures/vcr_cassettes/test_get.yml
188
+ - fixtures/vcr_cassettes/test_image_file_associate_with_object.yml
189
+ - fixtures/vcr_cassettes/test_image_file_save.yml
187
190
  - fixtures/vcr_cassettes/test_include.yml
188
191
  - fixtures/vcr_cassettes/test_new_model.yml
189
192
  - fixtures/vcr_cassettes/test_new_object.yml
@@ -194,6 +197,7 @@ files:
194
197
  - fixtures/vcr_cassettes/test_request_batch.yml
195
198
  - fixtures/vcr_cassettes/test_server_update.yml
196
199
  - fixtures/vcr_cassettes/test_simple_save.yml
200
+ - fixtures/vcr_cassettes/test_text_file_save.yml
197
201
  - fixtures/vcr_cassettes/test_update.yml
198
202
  - fixtures/vcr_cassettes/test_updated_at.yml
199
203
  - fixtures/vcr_cassettes/test_user_save.yml
@@ -214,10 +218,12 @@ files:
214
218
  - test/cloud_functions/MyCloudCode/cloud/main.js
215
219
  - test/config/global.json
216
220
  - test/helper.rb
221
+ - test/parsers.jpg
217
222
  - test/test_batch.rb
218
223
  - test/test_client.rb
219
224
  - test/test_cloud.rb
220
225
  - test/test_datatypes.rb
226
+ - test/test_file.rb
221
227
  - test/test_init.rb
222
228
  - test/test_init_from_cloud_code.rb
223
229
  - test/test_model.rb
@@ -240,7 +246,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
240
246
  version: '0'
241
247
  segments:
242
248
  - 0
243
- hash: 4089803935142513409
249
+ hash: 555133796256997664
244
250
  required_rubygems_version: !ruby/object:Gem::Requirement
245
251
  none: false
246
252
  requirements: