leancloud-ruby-client 0.1.1 → 0.2.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/test/helper.rb CHANGED
@@ -27,7 +27,6 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
27
27
  $LOAD_PATH.unshift(File.dirname(__FILE__))
28
28
  require 'leancloud-ruby-client'
29
29
 
30
- YAML::ENGINE.yamler='syck' # get ascii strings as strings in fixtures
31
30
 
32
31
  VCR.configure do |c|
33
32
  c.cassette_library_dir = 'fixtures/vcr_cassettes'
@@ -43,15 +42,14 @@ VCR.configure do |c|
43
42
  end
44
43
  end
45
44
 
46
- filter_sensitive_header(c, AV::Protocol::HEADER_APP_ID)
47
- filter_sensitive_header(c, AV::Protocol::HEADER_API_KEY)
48
- filter_sensitive_header(c, AV::Protocol::HEADER_MASTER_KEY)
49
- filter_sensitive_header(c, AV::Protocol::HEADER_SESSION_TOKEN)
45
+ filter_sensitive_header(c, LC::Protocol::HEADER_APP_ID)
46
+ filter_sensitive_header(c, LC::Protocol::HEADER_API_KEY)
47
+ filter_sensitive_header(c, LC::Protocol::HEADER_SESSION_TOKEN)
50
48
  end
51
49
 
52
- class AVTestCase < Test::Unit::TestCase
50
+ class LCTestCase < Test::Unit::TestCase
53
51
  def setup
54
- @client = AV.init(:logger => Logger.new(STDERR).tap{|l| l.level = Logger::ERROR})
52
+ @client = LC.init(:logger => Logger.new(STDERR).tap{|l| l.level = Logger::ERROR})
55
53
  end
56
54
  end
57
55
 
data/test/test_batch.rb CHANGED
@@ -1,19 +1,19 @@
1
1
  require 'helper'
2
2
 
3
- class TestBatch < AVTestCase
3
+ class TestBatch < LCTestCase
4
4
 
5
5
  def test_initialize
6
- batch = AV::Batch.new
7
- assert_equal batch.class, AV::Batch
8
- assert_equal AV.client, batch.client
6
+ batch = LC::Batch.new
7
+ assert_equal batch.class, LC::Batch
8
+ assert_equal LC.client, batch.client
9
9
 
10
- batch = AV::Batch.new(AV::Client.new)
11
- assert_equal batch.class, AV::Batch
12
- assert_not_equal AV.client, batch.client
10
+ batch = LC::Batch.new(LC::Client.new)
11
+ assert_equal batch.class, LC::Batch
12
+ assert_not_equal LC.client, batch.client
13
13
  end
14
14
 
15
15
  def test_add_request
16
- batch = AV::Batch.new
16
+ batch = LC::Batch.new
17
17
  batch.add_request({
18
18
  :method => "POST",
19
19
  :path => "/1/classes/GameScore",
@@ -36,13 +36,13 @@ class TestBatch < AVTestCase
36
36
  end
37
37
 
38
38
  def test_protocol_uri
39
- uri = AV::Protocol.batch_request_uri
39
+ uri = LC::Protocol.batch_request_uri
40
40
  assert_equal uri, "/1.1/batch"
41
41
  end
42
42
 
43
43
  def test_run
44
44
  VCR.use_cassette('test_batch_run', :record => :new_episodes) do
45
- batch = AV::Batch.new
45
+ batch = LC::Batch.new
46
46
  batch.add_request({
47
47
  "method" => "POST",
48
48
  "path" => "/1/classes/GameScore",
@@ -61,11 +61,11 @@ class TestBatch < AVTestCase
61
61
  def test_create_object
62
62
  VCR.use_cassette('test_batch_create_object', :record => :new_episodes) do
63
63
  objects = [1, 2, 3, 4, 5].map do |i|
64
- p = AV::Object.new("BatchTestObject")
64
+ p = LC::Object.new("BatchTestObject")
65
65
  p["foo"] = "#{i}"
66
66
  p
67
67
  end
68
- batch = AV::Batch.new
68
+ batch = LC::Batch.new
69
69
  objects.each do |obj|
70
70
  batch.create_object(obj)
71
71
  end
@@ -78,7 +78,7 @@ class TestBatch < AVTestCase
78
78
  def test_update_object
79
79
  VCR.use_cassette('test_batch_update_object', :record => :new_episodes) do
80
80
  objects = [1, 2, 3, 4, 5].map do |i|
81
- p = AV::Object.new("BatchTestObject")
81
+ p = LC::Object.new("BatchTestObject")
82
82
  p["foo"] = "#{i}"
83
83
  p.save
84
84
  p
@@ -86,7 +86,7 @@ class TestBatch < AVTestCase
86
86
  objects.map do |obj|
87
87
  obj["foo"] = "updated"
88
88
  end
89
- batch = AV::Batch.new
89
+ batch = LC::Batch.new
90
90
  objects.each do |obj|
91
91
  batch.update_object(obj)
92
92
  end
@@ -98,12 +98,12 @@ class TestBatch < AVTestCase
98
98
 
99
99
  def test_update_nils_delete_keys
100
100
  VCR.use_cassette('test_batch_update_nils_delete_keys', :record => :new_episodes) do
101
- post = AV::Object.new("BatchTestObject")
101
+ post = LC::Object.new("BatchTestObject")
102
102
  post["foo"] = "1"
103
103
  post.save
104
104
 
105
105
  post["foo"] = nil
106
- batch = AV::Batch.new
106
+ batch = LC::Batch.new
107
107
  batch.update_object(post)
108
108
  batch.run!
109
109
 
@@ -114,12 +114,12 @@ class TestBatch < AVTestCase
114
114
  def test_delete_object
115
115
  VCR.use_cassette('test_batch_delete_object', :record => :new_episodes) do
116
116
  objects = [1, 2, 3, 4, 5].map do |i|
117
- p = AV::Object.new("BatchTestObject")
117
+ p = LC::Object.new("BatchTestObject")
118
118
  p["foo"] = "#{i}"
119
119
  p.save
120
120
  p
121
121
  end
122
- batch = AV::Batch.new
122
+ batch = LC::Batch.new
123
123
  objects.each do |obj|
124
124
  batch.delete_object(obj)
125
125
  end
data/test/test_client.rb CHANGED
@@ -1,13 +1,13 @@
1
1
  require 'helper'
2
2
 
3
- class TestClient < AVTestCase
3
+ class TestClient < LCTestCase
4
4
 
5
5
  def stubbed_client(&block)
6
6
  stubs = Faraday::Adapter::Test::Stubs.new do |stub|
7
7
  yield(stub)
8
8
  end
9
9
 
10
- client = AV.init(
10
+ client = LC.init(
11
11
  :logger => Logger.new(STDERR).tap {
12
12
  |l| l.level = Logger::ERROR
13
13
  }
@@ -24,7 +24,7 @@ class TestClient < AVTestCase
24
24
  stubs, client = stubbed_client do |stub|
25
25
  (@client.max_retries + 1).times do
26
26
  stub.get('/') {[ 500, {}, {
27
- 'code' => AV::Protocol::ERROR_TIMEOUT}.to_json
27
+ 'code' => LC::Protocol::ERROR_TIMEOUT}.to_json
28
28
  ]}
29
29
  end
30
30
  end
@@ -104,7 +104,7 @@ class TestClient < AVTestCase
104
104
  begin
105
105
  client.request('/')
106
106
  raise "client error response should have raised"
107
- rescue AV::AVProtocolError => e
107
+ rescue LC::LCProtocolError => e
108
108
  assert_equal "HTTP Status 403 Body nonparseable", e.error
109
109
  end
110
110
 
@@ -114,58 +114,58 @@ class TestClient < AVTestCase
114
114
 
115
115
  def test_simple_save
116
116
  VCR.use_cassette('test_simple_save', :record => :new_episodes) do
117
- test_save = AV::Object.new "TestSave"
117
+ test_save = LC::Object.new "TestSave"
118
118
  test_save["foo"] = "bar"
119
119
  test_save.save
120
120
 
121
121
  assert_equal test_save["foo"], "bar"
122
- assert_equal test_save[AV::Protocol::KEY_CREATED_AT].class, String
123
- assert_equal test_save[AV::Protocol::KEY_OBJECT_ID].class, String
122
+ assert_equal test_save[LC::Protocol::KEY_CREATED_AT].class, String
123
+ assert_equal test_save[LC::Protocol::KEY_OBJECT_ID].class, String
124
124
  end
125
125
  end
126
126
 
127
127
  def test_update
128
128
  VCR.use_cassette('test_update', :record => :new_episodes) do
129
- foo = AV::Object.new "TestSave"
129
+ foo = LC::Object.new "TestSave"
130
130
  foo["age"] = 20
131
131
  foo.save
132
132
 
133
133
  assert_equal foo["age"], 20
134
- assert_equal foo[AV::Protocol::KEY_UPDATED_AT], nil
134
+ assert_equal foo[LC::Protocol::KEY_UPDATED_AT], nil
135
135
 
136
136
  foo["age"] = 40
137
137
  orig = foo.dup
138
138
  foo.save
139
139
 
140
140
  assert_equal foo["age"], 40
141
- assert_equal foo[AV::Protocol::KEY_UPDATED_AT].class, String
141
+ assert_equal foo[LC::Protocol::KEY_UPDATED_AT].class, String
142
142
 
143
143
  # only difference should be updatedAt
144
- orig_assoc = orig.reject{|k,v| k == AV::Protocol::KEY_UPDATED_AT}.to_a
145
- foo_assoc = foo.reject{|k,v| k == AV::Protocol::KEY_UPDATED_AT}.to_a
144
+ orig_assoc = orig.reject{|k,v| k == LC::Protocol::KEY_UPDATED_AT}.to_a
145
+ foo_assoc = foo.reject{|k,v| k == LC::Protocol::KEY_UPDATED_AT}.to_a
146
146
  assert_equal foo_assoc, orig_assoc
147
147
  end
148
148
  end
149
149
 
150
150
  def test_server_update
151
151
  VCR.use_cassette('test_server_update', :record => :new_episodes) do
152
- foo = AV::Object.new("TestSave").save
152
+ foo = LC::Object.new("TestSave").save
153
153
  foo["name"] = 'john'
154
154
  foo.save
155
155
 
156
- bar = AV.get("TestSave",foo.id) # pull it from the server
156
+ bar = LC.get("TestSave",foo.id) # pull it from the server
157
157
  assert_equal bar["name"], 'john'
158
158
  bar["name"] = 'dave'
159
159
  bar.save
160
160
 
161
- bat = AV.get("TestSave",foo.id)
161
+ bat = LC.get("TestSave",foo.id)
162
162
  assert_equal bat["name"], 'dave'
163
163
  end
164
164
  end
165
165
 
166
166
  def test_destroy
167
167
  VCR.use_cassette('test_destroy', :record => :new_episodes) do
168
- d = AV::Object.new "toBeDeleted"
168
+ d = LC::Object.new "toBeDeleted"
169
169
  d["foo"] = "bar"
170
170
  d.save
171
171
  d.parse_delete
@@ -176,7 +176,7 @@ class TestClient < AVTestCase
176
176
 
177
177
  def test_get_missing
178
178
  VCR.use_cassette('test_get_missing', :record => :new_episodes) do
179
- e = assert_raise(AV::AVProtocolError) { AV.get("SomeClass", "someIdThatDoesNotExist") }
179
+ e = assert_raise(LC::LCProtocolError) { LC.get("SomeClass", "someIdThatDoesNotExist") }
180
180
  assert_equal "101: Class or object doesn't exists.: SomeClass:someIdThatDoesNotExist", e.message
181
181
  end
182
182
  end
data/test/test_cloud.rb CHANGED
@@ -1,21 +1,21 @@
1
1
  require 'helper'
2
2
 
3
- class TestCloud < AVTestCase
3
+ class TestCloud < LCTestCase
4
4
  # functions stored in test/cloud_functions/MyCloudCode
5
- # see https://parse.com/docs/cloud_code_guide to learn how to use AV Cloud Code
5
+ # see https://parse.com/docs/cloud_code_guide to learn how to use LC Cloud Code
6
6
  #
7
- # AV.Cloud.define('trivial', function(request, response) {
7
+ # LC.Cloud.define('trivial', function(request, response) {
8
8
  # response.success(request.params);
9
9
  # });
10
10
 
11
11
  def test_cloud_function_initialize
12
- assert_not_equal nil, AV::Cloud::Function.new("trivial")
12
+ assert_not_equal nil, LC::Cloud::Function.new("trivial")
13
13
  end
14
14
 
15
15
  def test_request_sms
16
16
  VCR.use_cassette('test_request_sms', :record => :new_episodes) do
17
- assert_equal (AV::Cloud.request_sms :mobilePhoneNumber => "18668012283",:op => "test",:ttl => 5), {}
18
- puts AV::Cloud.verify_sms_code('18668012283', '123456').inspect
17
+ assert_equal (LC::Cloud.request_sms :mobilePhoneNumber => "186xxxxxxx",:op => "test",:ttl => 5), {}
18
+ puts LC::Cloud.verify_sms_code('186xxxxxxx', '123456').inspect
19
19
  end
20
20
  end
21
21
 
@@ -23,7 +23,7 @@ class TestCloud < AVTestCase
23
23
  omit("this should automate the parse deploy command by committing that binary to the repo")
24
24
 
25
25
  VCR.use_cassette('test_cloud_function', :record => :new_episodes) do
26
- function = AV::Cloud::Function.new("trivial")
26
+ function = LC::Cloud::Function.new("trivial")
27
27
  params = {"foo" => "bar"}
28
28
  resp = function.call(params)
29
29
  assert_equal resp, params
@@ -3,33 +3,33 @@ require 'helper'
3
3
  class TestDatatypes < Test::Unit::TestCase
4
4
  def test_pointer
5
5
  data = {
6
- AV::Protocol::KEY_CLASS_NAME => "DatatypeTestClass",
7
- AV::Protocol::KEY_OBJECT_ID => "12345abcd"
6
+ LC::Protocol::KEY_CLASS_NAME => "DatatypeTestClass",
7
+ LC::Protocol::KEY_OBJECT_ID => "12345abcd"
8
8
  }
9
- p = AV::Pointer.new data
9
+ p = LC::Pointer.new data
10
10
 
11
- assert_equal p.to_json, "{\"__type\":\"Pointer\",\"#{AV::Protocol::KEY_CLASS_NAME}\":\"DatatypeTestClass\",\"#{AV::Protocol::KEY_OBJECT_ID}\":\"12345abcd\"}"
11
+ assert_equal p.to_json, "{\"__type\":\"Pointer\",\"#{LC::Protocol::KEY_CLASS_NAME}\":\"DatatypeTestClass\",\"#{LC::Protocol::KEY_OBJECT_ID}\":\"12345abcd\"}"
12
12
  end
13
13
 
14
14
  def test_pointer_make
15
- p = AV::Pointer.make("SomeClass", "someId")
15
+ p = LC::Pointer.make("SomeClass", "someId")
16
16
  assert_equal "SomeClass", p.class_name
17
17
  assert_equal "someId", p.id
18
18
  end
19
19
 
20
20
  def test_date
21
21
  date_time = Time.at(0).to_datetime
22
- parse_date = AV::Date.new(date_time)
22
+ parse_date = LC::Date.new(date_time)
23
23
 
24
24
  assert_equal date_time, parse_date.value
25
25
  assert_equal "1970-01-01T00:00:00.000Z", JSON.parse(parse_date.to_json)["iso"]
26
26
  assert_equal 0, parse_date <=> parse_date
27
- assert_equal 0, AV::Date.new(date_time) <=> AV::Date.new(date_time)
27
+ assert_equal 0, LC::Date.new(date_time) <=> LC::Date.new(date_time)
28
28
 
29
- post = AV::Object.new("Post")
29
+ post = LC::Object.new("Post")
30
30
  post["time"] = parse_date
31
31
  post.save
32
- q = AV.get("Post", post.id)
32
+ q = LC.get("Post", post.id)
33
33
 
34
34
  # time zone from parse is utc so string formats don't compare equal,
35
35
  # also floating points vary a bit so only equality after rounding to millis is guaranteed
@@ -38,32 +38,32 @@ class TestDatatypes < Test::Unit::TestCase
38
38
 
39
39
  def test_date_with_bad_data
40
40
  assert_raise do
41
- AV::Date.new(2014)
41
+ LC::Date.new(2014)
42
42
  end
43
43
  assert_raise do
44
- AV::Date.new(nil)
44
+ LC::Date.new(nil)
45
45
  end
46
46
  end
47
47
 
48
48
  def test_date_with_time
49
49
  time = Time.parse("01/01/2012 23:59:59")
50
- assert_equal time, AV::Date.new(time).to_time
50
+ assert_equal time, LC::Date.new(time).to_time
51
51
  end
52
52
 
53
53
  def test_bytes
54
54
  data = {
55
55
  "base64" => Base64.encode64("testing bytes!")
56
56
  }
57
- byte = AV::Bytes.new data
57
+ byte = LC::Bytes.new data
58
58
 
59
59
  assert_equal byte.value, "testing bytes!"
60
- assert_equal JSON.parse(byte.to_json)[AV::Protocol::KEY_TYPE], AV::Protocol::TYPE_BYTES
60
+ assert_equal JSON.parse(byte.to_json)[LC::Protocol::KEY_TYPE], LC::Protocol::TYPE_BYTES
61
61
  assert_equal JSON.parse(byte.to_json)["base64"], Base64.encode64("testing bytes!")
62
62
  end
63
63
 
64
64
  def test_increment
65
65
  amount = 5
66
- increment = AV::Increment.new amount
66
+ increment = LC::Increment.new amount
67
67
 
68
68
  assert_equal increment.to_json, "{\"__op\":\"Increment\",\"amount\":#{amount}}"
69
69
  end
@@ -74,16 +74,16 @@ class TestDatatypes < Test::Unit::TestCase
74
74
  "longitude" => 40.0,
75
75
  "latitude" => -30.0
76
76
  }
77
- gp = AV::GeoPoint.new data
77
+ gp = LC::GeoPoint.new data
78
78
 
79
79
  assert_equal JSON.parse(gp.to_json)["longitude"], data["longitude"]
80
80
  assert_equal JSON.parse(gp.to_json)["latitude"], data["latitude"]
81
- assert_equal JSON.parse(gp.to_json)[AV::Protocol::KEY_TYPE], AV::Protocol::TYPE_GEOPOINT
81
+ assert_equal JSON.parse(gp.to_json)[LC::Protocol::KEY_TYPE], LC::Protocol::TYPE_GEOPOINT
82
82
 
83
- post = AV::Object.new("Post")
83
+ post = LC::Object.new("Post")
84
84
  post["location"] = gp
85
85
  post.save
86
- q = AV.get("Post", post.id)
86
+ q = LC.get("Post", post.id)
87
87
  assert_equal gp, q["location"]
88
88
  end
89
89
 
@@ -92,14 +92,14 @@ class TestDatatypes < Test::Unit::TestCase
92
92
  # ----------------------------
93
93
  #def test_file
94
94
  # data = {"name" => "test/parsers.png"}
95
- # file = AV::File.new(data)
95
+ # file = LC::File.new(data)
96
96
  # assert_equal JSON.parse(file.to_json)["name"], data["name"]
97
- # assert_equal JSON.parse(file.to_json)[AV::Protocol::KEY_TYPE], AV::Protocol::TYPE_FILE
97
+ # assert_equal JSON.parse(file.to_json)[LC::Protocol::KEY_TYPE], LC::Protocol::TYPE_FILE
98
98
 
99
- # post = AV::Object.new("Post")
99
+ # post = LC::Object.new("Post")
100
100
  # post["avatar"] = file
101
101
  # post.save
102
- # q = AV.get("Post", post.id)
102
+ # q = LC.get("Post", post.id)
103
103
  # assert_equal file.parse_filename, q["avatar"].parse_filename
104
104
  #end
105
105
  end
data/test/test_file.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  require 'helper'
2
2
 
3
- class TestFile < AVTestCase
3
+ class TestFile < LCTestCase
4
4
 
5
5
  def test_file_save
6
6
  VCR.use_cassette('test_text_file_save', :record => :new_episodes) do
7
- tf = AV::File.new({
7
+ tf = LC::File.new({
8
8
  :body => "Hello World!",
9
9
  :local_filename => "hello.txt",
10
10
  :content_type => "text/plain"
@@ -22,7 +22,7 @@ class TestFile < AVTestCase
22
22
 
23
23
  def test_image_save
24
24
  #VCR.use_cassette('test_image_file_save', :record => :new_episodes) do
25
- tf = AV::File.new({
25
+ tf = LC::File.new({
26
26
  :body => IO.read("test/parsers.jpg"),
27
27
  :local_filename => "parsers.jpg",
28
28
  :content_type => "image/jpeg"
@@ -39,7 +39,7 @@ class TestFile < AVTestCase
39
39
 
40
40
  def test_associate_with_object
41
41
  #VCR.use_cassette('test_image_file_associate_with_object', :record => :new_episodes) do
42
- tf = AV::File.new({
42
+ tf = LC::File.new({
43
43
  :body => IO.read("test/parsers.jpg"),
44
44
  :local_filename => "parsers.jpg",
45
45
  :content_type => "image/jpeg"
@@ -52,7 +52,7 @@ class TestFile < AVTestCase
52
52
  assert tf.body
53
53
  assert tf.to_json
54
54
 
55
- object = AV::Object.new("ShouldHaveFile")
55
+ object = LC::Object.new("ShouldHaveFile")
56
56
  object["photo"] = tf
57
57
  object.save
58
58
 
data/test/test_init.rb CHANGED
@@ -1,14 +1,14 @@
1
1
  require 'helper'
2
2
 
3
- #AV.init :application_id => $LC_APPLICATION_ID, :api_key => $LC_APPLICATION_KEY
3
+ #LC.init :application_id => $LC_APPLICATION_ID, :api_key => $LC_APPLICATION_KEY
4
4
 
5
5
  class TestInit < Test::Unit::TestCase
6
6
  def setup
7
- AV.destroy
7
+ LC.destroy
8
8
  end
9
9
 
10
10
  def test_no_api_keys_error
11
- fake = AV::Object.new "shouldNeverExist"
11
+ fake = LC::Object.new "shouldNeverExist"
12
12
  fake["foo"] = "bar"
13
13
 
14
14
  begin
@@ -18,6 +18,6 @@ class TestInit < Test::Unit::TestCase
18
18
  end
19
19
 
20
20
  assert_equal error_triggered, true
21
- assert_equal fake[AV::Protocol::KEY_OBJECT_ID], nil
21
+ assert_equal fake[LC::Protocol::KEY_OBJECT_ID], nil
22
22
  end
23
23
  end