ribose 0.3.1 → 0.5.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.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +27 -0
- data/.rubocop.yml +8 -643
- data/CHANGELOG.adoc +36 -0
- data/README.adoc +842 -0
- data/lib/ribose/actions/create.rb +1 -1
- data/lib/ribose/client.rb +26 -8
- data/lib/ribose/configuration.rb +20 -3
- data/lib/ribose/connection.rb +15 -0
- data/lib/ribose/event.rb +1 -1
- data/lib/ribose/file_uploader.rb +21 -3
- data/lib/ribose/file_version.rb +58 -7
- data/lib/ribose/request.rb +46 -10
- data/lib/ribose/response/raise_error.rb +0 -2
- data/lib/ribose/session.rb +40 -16
- data/lib/ribose/space.rb +4 -0
- data/lib/ribose/space_file.rb +16 -1
- data/lib/ribose/user.rb +9 -5
- data/lib/ribose/version.rb +1 -1
- data/lib/ribose/version_uploader.rb +27 -0
- data/ribose.gemspec +4 -5
- data/spec/ribose/client_spec.rb +18 -19
- data/spec/ribose/config_spec.rb +0 -1
- data/spec/ribose/connection_spec.rb +11 -0
- data/spec/ribose/file_uploader_spec.rb +16 -3
- data/spec/ribose/file_version_spec.rb +56 -0
- data/spec/ribose/message_spec.rb +3 -2
- data/spec/ribose/session_spec.rb +18 -24
- data/spec/ribose/space_file_spec.rb +32 -1
- data/spec/ribose/space_spec.rb +12 -1
- data/spec/ribose/user_spec.rb +2 -2
- data/spec/spec_helper.rb +2 -1
- data/spec/support/fake_ribose_api.rb +34 -7
- data/spec/support/file_upload_stub.rb +21 -15
- metadata +24 -38
- data/.travis.yml +0 -5
- data/CHANGELOG.md +0 -5
- data/README.md +0 -745
data/spec/ribose/client_spec.rb
CHANGED
@@ -7,42 +7,41 @@ RSpec.describe Ribose::Client do
|
|
7
7
|
client = Ribose::Client.new
|
8
8
|
|
9
9
|
expect(client.api_token).to eq(Ribose.configuration.api_token)
|
10
|
-
expect(client.
|
10
|
+
expect(client.api_email).to eq(Ribose.configuration.api_email)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
14
|
context "custom attribtues provided" do
|
15
15
|
it "initialize with the supplied attribtues" do
|
16
|
-
|
16
|
+
email = "john@ex.com"
|
17
|
+
token = "SECRET_API_TOKEN"
|
18
|
+
client = Ribose::Client.new(api_token: token, api_email: email)
|
17
19
|
|
18
|
-
expect(client.api_token).to eq(
|
19
|
-
expect(client.
|
20
|
+
expect(client.api_token).to eq(token)
|
21
|
+
expect(client.api_email).to eq(email)
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
24
26
|
describe ".from_login" do
|
25
27
|
it "authenticate the user and build a client" do
|
26
|
-
email = "
|
27
|
-
password = "
|
28
|
+
email = "user.email@gmail.com"
|
29
|
+
password = "supser.secrect.password"
|
28
30
|
|
29
|
-
allow(Ribose::Session).to receive(:create).and_return(
|
31
|
+
allow(Ribose::Session).to receive(:create).and_return(session)
|
30
32
|
client = Ribose::Client.from_login(email: email, password: password)
|
31
33
|
|
32
|
-
expect(client.
|
33
|
-
expect(client.
|
34
|
+
expect(client.api_email).to eq(email)
|
35
|
+
expect(client.uid).to eq(session.uid)
|
36
|
+
expect(client.client_id).to eq(session.client)
|
34
37
|
end
|
35
38
|
end
|
36
39
|
|
37
|
-
def
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
"browser" => "Ribose Ruby Client",
|
44
|
-
"user_id" => "user-uuid-123-4567"
|
45
|
-
},
|
46
|
-
}
|
40
|
+
def session
|
41
|
+
@session ||= Ribose::SessionData.new(
|
42
|
+
uid: "hello",
|
43
|
+
expiry: Time.now + 3600,
|
44
|
+
client: "RIBOSE_RUBY_CLIENT",
|
45
|
+
)
|
47
46
|
end
|
48
47
|
end
|
data/spec/ribose/config_spec.rb
CHANGED
@@ -20,7 +20,6 @@ RSpec.describe Ribose::Config do
|
|
20
20
|
expect(Ribose.configuration.debug_mode?).to be_falsey
|
21
21
|
expect(Ribose.configuration.api_token).to eq(api_token)
|
22
22
|
expect(Ribose.configuration.user_email).to eq(user_email)
|
23
|
-
expect(Ribose.configuration.web_url).to eq ["https", api_host].join("://")
|
24
23
|
end
|
25
24
|
end
|
26
25
|
|
@@ -23,4 +23,15 @@ RSpec.describe Ribose::Connection do
|
|
23
23
|
expect(suggestions.first.name).to eq("Jennie Doe")
|
24
24
|
end
|
25
25
|
end
|
26
|
+
|
27
|
+
describe ".disconnect" do
|
28
|
+
it "disconnect with provided connection" do
|
29
|
+
connection_id = 123_456
|
30
|
+
stub_ribose_connection_delete_api(connection_id)
|
31
|
+
|
32
|
+
expect do
|
33
|
+
Ribose::Connection.disconnect(connection_id)
|
34
|
+
end.not_to raise_error
|
35
|
+
end
|
36
|
+
end
|
26
37
|
end
|
@@ -7,18 +7,31 @@ RSpec.describe Ribose::FileUploader do
|
|
7
7
|
space_id = 123_456_789
|
8
8
|
|
9
9
|
stub_ribose_space_file_upload_api(space_id, file_attributes)
|
10
|
-
file_upload = Ribose::FileUploader.upload(space_id, file_attributes)
|
10
|
+
file_upload = Ribose::FileUploader.upload(space_id, **file_attributes)
|
11
11
|
|
12
12
|
expect(file_upload.attachment.id).not_to be_nil
|
13
13
|
expect(file_upload.attachment.author).to eq("John Doe")
|
14
14
|
expect(file_upload.attachment.content_type).to eq("image/png")
|
15
15
|
end
|
16
16
|
end
|
17
|
+
|
18
|
+
context "with unknown file type" do
|
19
|
+
it "creates a new upload as octet-stream" do
|
20
|
+
space_id = 123_456_789
|
21
|
+
attributes = file_attributes(File.join(Ribose.root, "Rakefile"))
|
22
|
+
|
23
|
+
stub_ribose_space_file_upload_api(space_id, attributes)
|
24
|
+
file_upload = Ribose::FileUploader.upload(space_id, **attributes)
|
25
|
+
|
26
|
+
expect(file_upload.attachment.id).not_to be_nil
|
27
|
+
expect(file_upload.attachment.author).to eq("John Doe")
|
28
|
+
end
|
29
|
+
end
|
17
30
|
end
|
18
31
|
|
19
|
-
def file_attributes
|
32
|
+
def file_attributes(file = nil)
|
20
33
|
{
|
21
|
-
file: sample_fixture_file,
|
34
|
+
file: file || sample_fixture_file,
|
22
35
|
tag_list: "sample, file, samplefile",
|
23
36
|
description: "This is a sample file",
|
24
37
|
}
|
@@ -17,4 +17,60 @@ RSpec.describe Ribose::FileVersion do
|
|
17
17
|
expect(file_version.current_version_id).to eq(789012)
|
18
18
|
end
|
19
19
|
end
|
20
|
+
|
21
|
+
describe ".download" do
|
22
|
+
context "with version id specified" do
|
23
|
+
it "downloads the specific file version" do
|
24
|
+
file_id = 123_456
|
25
|
+
space_id = 456_789
|
26
|
+
version_id = 789_012
|
27
|
+
|
28
|
+
output_file = "./tmp/download"
|
29
|
+
content = "This is the content in the file"
|
30
|
+
|
31
|
+
stub_aws_file_version_download_api(content)
|
32
|
+
buffer = stub_file_write_to_io(output_file)
|
33
|
+
stub_ribose_file_version_download_api(space_id, file_id, version_id)
|
34
|
+
|
35
|
+
Ribose::FileVersion.download(
|
36
|
+
space_id, file_id, version_id: version_id, output: output_file
|
37
|
+
)
|
38
|
+
|
39
|
+
expect(buffer).to eq(content)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe ".create" do
|
45
|
+
it "create a new file version" do
|
46
|
+
file_id = 123_456
|
47
|
+
space_id = 456_789
|
48
|
+
|
49
|
+
stub_ribose_space_file_upload_api(space_id, file_attributes, file_id)
|
50
|
+
file = Ribose::FileVersion.create(space_id, file_id, **file_attributes)
|
51
|
+
|
52
|
+
expect(file.id).not_to be_nil
|
53
|
+
expect(file.author).to eq("John Doe")
|
54
|
+
expect(file.content_type).to eq("image/png")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def file_attributes
|
59
|
+
{
|
60
|
+
file: sample_fixture_file,
|
61
|
+
description: "Version 2.0",
|
62
|
+
tag_list: "tags for new version",
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
def sample_fixture_file
|
67
|
+
@sample_fixture_file ||= File.join(Ribose.root, "spec/fixtures/sample.png")
|
68
|
+
end
|
69
|
+
|
70
|
+
def stub_file_write_to_io(output_file)
|
71
|
+
buffer = StringIO.new
|
72
|
+
allow(File).to receive(:open).with(output_file, "w").and_yield(buffer)
|
73
|
+
|
74
|
+
buffer.string
|
75
|
+
end
|
20
76
|
end
|
data/spec/ribose/message_spec.rb
CHANGED
@@ -20,9 +20,10 @@ RSpec.describe Ribose::Message do
|
|
20
20
|
describe ".create" do
|
21
21
|
it "creates a new message into a conversation" do
|
22
22
|
space_id = 123_456
|
23
|
+
message_attributes = message_attrs.merge(space_id: space_id)
|
23
24
|
|
24
25
|
stub_ribose_message_create(space_id, message: message_attrs)
|
25
|
-
message = Ribose::Message.create(
|
26
|
+
message = Ribose::Message.create(**message_attributes)
|
26
27
|
|
27
28
|
expect(message.id).not_to be_nil
|
28
29
|
expect(message.user.name).to eq("John Doe")
|
@@ -37,7 +38,7 @@ RSpec.describe Ribose::Message do
|
|
37
38
|
|
38
39
|
stub_ribose_message_update(space_id, message_id, message: message_attrs)
|
39
40
|
message = Ribose::Message.update(
|
40
|
-
message_attrs.merge(space_id: space_id, message_id: message_id),
|
41
|
+
**message_attrs.merge(space_id: space_id, message_id: message_id),
|
41
42
|
)
|
42
43
|
|
43
44
|
expect(message.user.name).to eq("John Doe")
|
data/spec/ribose/session_spec.rb
CHANGED
@@ -6,41 +6,35 @@ RSpec.describe Ribose::Session do
|
|
6
6
|
username = "super.user"
|
7
7
|
password = "supper.secreet.password"
|
8
8
|
|
9
|
-
|
9
|
+
stub_post_signin_request
|
10
10
|
session = Ribose::Session.create(username: username, password: password)
|
11
11
|
|
12
|
-
expect(session["
|
13
|
-
expect(session
|
12
|
+
expect(session.uid).to eq(session_headers["uid"])
|
13
|
+
expect(session.client).to eq(session_headers["client"])
|
14
|
+
expect(session["access-token"]).to eq(session_headers["access-token"])
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
17
|
-
def
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
def session_headers
|
19
|
+
@session_headers ||= {
|
20
|
+
"uid" => "user@example.com",
|
21
|
+
"expiry" => Time.now,
|
22
|
+
"client" => "sample-user-client",
|
23
|
+
"access-token" => "super.secret.access.token",
|
24
|
+
}
|
23
25
|
end
|
24
26
|
|
25
|
-
def
|
26
|
-
|
27
|
-
|
28
|
-
stub_general_inforomation_request
|
29
|
-
end
|
30
|
-
|
31
|
-
def stub_get_request_with_login_page
|
32
|
-
stub_request(:get, login_url).and_return(
|
33
|
-
body: ribose_fixture("login", "html"),
|
34
|
-
headers: { content_type: "text/html" },
|
27
|
+
def stub_post_signin_request
|
28
|
+
stub_request(:post, login_url).and_return(
|
29
|
+
body: ribose_fixture("empty"), headers: session_headers,
|
35
30
|
)
|
36
31
|
end
|
37
32
|
|
38
|
-
def
|
39
|
-
|
40
|
-
and_return(body: ribose_fixture("general_information"), status: 200)
|
33
|
+
def login_url
|
34
|
+
[api_host, "api/v2/auth/sign_in"].join("/")
|
41
35
|
end
|
42
36
|
|
43
|
-
def
|
44
|
-
|
37
|
+
def api_host
|
38
|
+
"https://#{Ribose.configuration.api_host}"
|
45
39
|
end
|
46
40
|
end
|
@@ -28,12 +28,43 @@ RSpec.describe Ribose::SpaceFile do
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
+
describe ".download" do
|
32
|
+
context "without specific version id" do
|
33
|
+
it "fetch version id and then downloads the file" do
|
34
|
+
file_id = 123_456_789
|
35
|
+
space_id = 456_789_012
|
36
|
+
|
37
|
+
allow(Ribose::FileVersion).to receive(:download)
|
38
|
+
stub_ribose_space_file_fetch_api(space_id, file_id)
|
39
|
+
|
40
|
+
Ribose::SpaceFile.download(space_id, file_id)
|
41
|
+
|
42
|
+
expect(Ribose::FileVersion).to have_received(:download).
|
43
|
+
with(space_id, file_id, version_id: 11559)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "with specific version id" do
|
48
|
+
it "sends downlod message to the downloader" do
|
49
|
+
file_id = 123_456_789
|
50
|
+
space_id = 456_789_012
|
51
|
+
version_id = 123_456_789
|
52
|
+
|
53
|
+
allow(Ribose::FileVersion).to receive(:download)
|
54
|
+
Ribose::SpaceFile.download(space_id, file_id, version_id: version_id)
|
55
|
+
|
56
|
+
expect(Ribose::FileVersion).to have_received(:download).
|
57
|
+
with(space_id, file_id, version_id: version_id)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
31
62
|
describe ".create" do
|
32
63
|
it "creates a new file with provided details" do
|
33
64
|
space_id = 123_456_789
|
34
65
|
|
35
66
|
stub_ribose_space_file_upload_api(space_id, file_attributes)
|
36
|
-
file = Ribose::SpaceFile.create(space_id, file_attributes)
|
67
|
+
file = Ribose::SpaceFile.create(space_id, **file_attributes)
|
37
68
|
|
38
69
|
expect(file.id).not_to be_nil
|
39
70
|
expect(file.author).to eq("John Doe")
|
data/spec/ribose/space_spec.rb
CHANGED
@@ -28,7 +28,7 @@ RSpec.describe Ribose::Space do
|
|
28
28
|
describe ".create" do
|
29
29
|
it "creates a new space with provided details" do
|
30
30
|
stub_ribose_space_create_api(space_attributes)
|
31
|
-
space = Ribose::Space.create(space_attributes)
|
31
|
+
space = Ribose::Space.create(**space_attributes)
|
32
32
|
|
33
33
|
expect(space.id).not_to be_nil
|
34
34
|
expect(space.visibility).to eq("invisible")
|
@@ -59,6 +59,17 @@ RSpec.describe Ribose::Space do
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
+
describe ".delete" do
|
63
|
+
it "deletes an existing space" do
|
64
|
+
space_id = 123_456_789
|
65
|
+
stub_ribose_space_remove_api(space_id, password_confirmation: 1234)
|
66
|
+
|
67
|
+
expect do
|
68
|
+
Ribose::Space.delete(space_id, confirmation: 1234)
|
69
|
+
end.not_to raise_error
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
62
73
|
def space_attributes
|
63
74
|
{
|
64
75
|
access: "private",
|
data/spec/ribose/user_spec.rb
CHANGED
@@ -18,7 +18,7 @@ RSpec.describe Ribose::User do
|
|
18
18
|
describe ".activate" do
|
19
19
|
it "complete the user signup process" do
|
20
20
|
stub_ribose_app_user_activate_api(user_attributes)
|
21
|
-
user = Ribose::User.activate(user_attributes)
|
21
|
+
user = Ribose::User.activate(**user_attributes)
|
22
22
|
|
23
23
|
expect(user.id).not_to be_nil
|
24
24
|
expect(user.name).to eq("John Doe")
|
@@ -30,7 +30,7 @@ RSpec.describe Ribose::User do
|
|
30
30
|
@user_attributes ||= {
|
31
31
|
email: "john.doe@example.com",
|
32
32
|
password: "SecurePassword",
|
33
|
-
|
33
|
+
edata: "OTP_RECEIVED_VIA_EMAIL",
|
34
34
|
}
|
35
35
|
end
|
36
36
|
|
data/spec/spec_helper.rb
CHANGED
@@ -15,8 +15,9 @@ RSpec.configure do |config|
|
|
15
15
|
|
16
16
|
config.before :all do
|
17
17
|
Ribose.configure do |ribose_config|
|
18
|
-
ribose_config.api_token = ENV["RIBOSE_API_TOKEN"] || "RIBOSE_API_TOKEN"
|
19
18
|
ribose_config.user_email = ENV["RIBOSE_USER_EMAIL"] || "RIBOSE_USER_EMAIL"
|
19
|
+
ribose_config.user_password = ENV["RIBOSE_USER_PASSWORD"] || "SECRET_PASS"
|
20
|
+
ribose_config.client = Ribose::Client.new
|
20
21
|
end
|
21
22
|
end
|
22
23
|
end
|
@@ -30,6 +30,12 @@ module Ribose
|
|
30
30
|
)
|
31
31
|
end
|
32
32
|
|
33
|
+
def stub_ribose_space_delete_api(space_id, options = {})
|
34
|
+
stub_api_response(
|
35
|
+
:delete, "spaces/#{space_id}", data: options, filename: "empty"
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
33
39
|
def stub_ribose_feed_api
|
34
40
|
stub_api_response(:get, "feeds", filename: "feeds")
|
35
41
|
end
|
@@ -173,7 +179,7 @@ module Ribose
|
|
173
179
|
def stub_ribose_app_user_activate_api(attributes)
|
174
180
|
stub_api_response(
|
175
181
|
:post,
|
176
|
-
"
|
182
|
+
"api/v2/auth",
|
177
183
|
data: { user: attributes },
|
178
184
|
filename: "user_activated",
|
179
185
|
)
|
@@ -220,6 +226,17 @@ module Ribose
|
|
220
226
|
)
|
221
227
|
end
|
222
228
|
|
229
|
+
def stub_ribose_file_version_download_api(sid, fid, vid)
|
230
|
+
version = ["spaces", sid, "file/files", fid, "versions", vid].join("/")
|
231
|
+
stub_request(:get, ribose_endpoint(version)).to_return(
|
232
|
+
headers: { location: "https://ribose-data.aws.com", status: 302 },
|
233
|
+
)
|
234
|
+
end
|
235
|
+
|
236
|
+
def stub_aws_file_version_download_api(content)
|
237
|
+
stub_request(:get, "https://ribose-data.aws.com").to_return(body: content)
|
238
|
+
end
|
239
|
+
|
223
240
|
def stub_ribose_space_conversation_list(space_id)
|
224
241
|
stub_api_response(
|
225
242
|
:get, conversations_path(space_id), filename: "conversations"
|
@@ -310,6 +327,12 @@ module Ribose
|
|
310
327
|
stub_api_response(:get, "people/connections?s=", filename: "connections")
|
311
328
|
end
|
312
329
|
|
330
|
+
def stub_ribose_connection_delete_api(id)
|
331
|
+
stub_api_response(
|
332
|
+
:delete, ["people", "connections", id].join("/"), filename: "empty"
|
333
|
+
)
|
334
|
+
end
|
335
|
+
|
313
336
|
def stub_ribose_suggestion_list_api
|
314
337
|
stub_api_response(
|
315
338
|
:get, "people_finding", filename: "connection_suggestion"
|
@@ -526,16 +549,16 @@ module Ribose
|
|
526
549
|
|
527
550
|
if Ribose.configuration.api_token
|
528
551
|
headers["X-Indigo-Token"] = client.api_token
|
529
|
-
headers["X-Indigo-Email"] = client.
|
552
|
+
headers["X-Indigo-Email"] = client.api_email
|
530
553
|
end
|
531
554
|
end
|
532
555
|
end
|
533
556
|
|
534
|
-
def response_with(filename:, status:)
|
557
|
+
def response_with(filename:, status:, content_type: "application/json")
|
535
558
|
{
|
536
559
|
status: status,
|
537
560
|
body: ribose_fixture(filename),
|
538
|
-
headers: { content_type:
|
561
|
+
headers: { content_type: content_type },
|
539
562
|
}
|
540
563
|
end
|
541
564
|
|
@@ -546,11 +569,15 @@ module Ribose
|
|
546
569
|
File.read(File.expand_path(file_path, __FILE__))
|
547
570
|
end
|
548
571
|
|
549
|
-
def stub_api_response(method, endpoint, filename:,
|
550
|
-
|
572
|
+
def stub_api_response(method, endpoint, filename:, status: 200, data: nil,
|
573
|
+
client: nil, content_type: "application/json")
|
551
574
|
stub_request(method, ribose_endpoint(endpoint)).
|
552
575
|
with(ribose_headers(data: data, client: client)).
|
553
|
-
to_return(
|
576
|
+
to_return(
|
577
|
+
response_with(
|
578
|
+
filename: filename, status: status, content_type: content_type,
|
579
|
+
),
|
580
|
+
)
|
554
581
|
end
|
555
582
|
end
|
556
583
|
end
|
@@ -2,16 +2,16 @@ require "faraday"
|
|
2
2
|
|
3
3
|
module Ribose
|
4
4
|
module FileUploadStub
|
5
|
-
def stub_ribose_space_file_upload_api(space_id, attributes)
|
5
|
+
def stub_ribose_space_file_upload_api(space_id, attributes, file_id = nil)
|
6
6
|
stub_ribose_aws_s3_file_upload_api
|
7
|
-
stub_ribose_file_prepare_api(space_id, attributes)
|
8
|
-
stub_ribose_file_upload_notify_api(space_id, attributes)
|
7
|
+
stub_ribose_file_prepare_api(space_id, attributes, file_id)
|
8
|
+
stub_ribose_file_upload_notify_api(space_id, attributes, file_id)
|
9
9
|
end
|
10
10
|
|
11
|
-
def stub_ribose_file_prepare_api(space_id, attributes)
|
11
|
+
def stub_ribose_file_prepare_api(space_id, attributes, file_id = nil)
|
12
12
|
stub_api_response(
|
13
13
|
:get,
|
14
|
-
ribose_prepare_endpoint(space_id, attributes),
|
14
|
+
ribose_prepare_endpoint(space_id, attributes, file_id),
|
15
15
|
filename: "file_upload_prepared",
|
16
16
|
)
|
17
17
|
end
|
@@ -22,23 +22,26 @@ module Ribose
|
|
22
22
|
to_return(response_with(filename: "empty", status: 200))
|
23
23
|
end
|
24
24
|
|
25
|
-
def stub_ribose_file_upload_notify_api(space_id, attributes)
|
25
|
+
def stub_ribose_file_upload_notify_api(space_id, attributes, file_id = nil)
|
26
26
|
stub_api_response(
|
27
27
|
:post,
|
28
|
-
ribose_file_endpoint(space_id),
|
29
|
-
data: build_notify_request_body(attributes),
|
28
|
+
ribose_file_endpoint(space_id, file_id),
|
29
|
+
data: build_notify_request_body(attributes, file_id),
|
30
30
|
filename: "file_uploaded",
|
31
|
+
content_type: "text/html",
|
31
32
|
)
|
32
33
|
end
|
33
34
|
|
34
35
|
private
|
35
36
|
|
36
|
-
def ribose_file_endpoint(space_id)
|
37
|
-
|
37
|
+
def ribose_file_endpoint(space_id, file_id = nil)
|
38
|
+
end_path = file_id ? "#{file_id}/versions" : nil
|
39
|
+
["spaces", space_id, "file", "files", end_path].compact.join("/")
|
38
40
|
end
|
39
41
|
|
40
|
-
def ribose_prepare_endpoint(sid, attrs)
|
41
|
-
[ribose_file_endpoint(sid), "prepare?#{prepare_params(attrs)}"].
|
42
|
+
def ribose_prepare_endpoint(sid, attrs, file_id = nil)
|
43
|
+
[ribose_file_endpoint(sid, file_id), "prepare?#{prepare_params(attrs)}"].
|
44
|
+
join("/")
|
42
45
|
end
|
43
46
|
|
44
47
|
def prepare_params(attributes)
|
@@ -49,16 +52,19 @@ module Ribose
|
|
49
52
|
)
|
50
53
|
end
|
51
54
|
|
52
|
-
def build_notify_request_body(attributes)
|
55
|
+
def build_notify_request_body(attributes, file_id = nil)
|
56
|
+
file_info_key = file_id ? "file_info_version" : "file_info"
|
57
|
+
|
53
58
|
extract_file_details(attributes).merge(
|
54
|
-
|
59
|
+
file_info_key.to_sym => extract_file_info(attributes),
|
55
60
|
key: "uploads/123456789/${filename}",
|
56
61
|
)
|
57
62
|
end
|
58
63
|
|
59
64
|
def content_type_form_file(file)
|
60
65
|
require "mime/types"
|
61
|
-
MIME::Types.type_for(file).first
|
66
|
+
mime = MIME::Types.type_for(file).first
|
67
|
+
mime ? mime.content_type : "application/octet-stream"
|
62
68
|
end
|
63
69
|
|
64
70
|
def extract_file_details(attributes)
|