ribose 0.3.0 → 0.4.1
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 +5 -5
- data/.github/workflows/test.yml +27 -0
- data/.rubocop.yml +21 -16
- data/CHANGELOG.md +20 -0
- data/README.md +99 -0
- data/lib/ribose/actions/create.rb +2 -1
- data/lib/ribose/actions/update.rb +2 -1
- data/lib/ribose/calendar.rb +2 -2
- data/lib/ribose/client.rb +27 -9
- data/lib/ribose/configuration.rb +13 -4
- data/lib/ribose/connection.rb +15 -0
- data/lib/ribose/conversation.rb +18 -0
- data/lib/ribose/event.rb +86 -0
- data/lib/ribose/file_uploader.rb +20 -2
- data/lib/ribose/file_version.rb +97 -0
- data/lib/ribose/request.rb +49 -10
- data/lib/ribose/session.rb +36 -22
- data/lib/ribose/space.rb +4 -0
- data/lib/ribose/space_category.rb +15 -0
- data/lib/ribose/space_file.rb +29 -0
- data/lib/ribose/user.rb +9 -5
- data/lib/ribose/version.rb +1 -1
- data/lib/ribose/version_uploader.rb +27 -0
- data/lib/ribose.rb +3 -0
- data/ribose.gemspec +3 -4
- data/spec/fixtures/calendar_event.json +48 -0
- data/spec/fixtures/conversation.json +1 -1
- data/spec/fixtures/event_created.json +21 -0
- data/spec/fixtures/event_updated.json +23 -0
- data/spec/fixtures/file_version.json +14 -0
- data/spec/fixtures/space_categories.json +150 -0
- data/spec/fixtures/space_file_icon.json +4 -0
- data/spec/ribose/connection_spec.rb +11 -0
- data/spec/ribose/conversation_spec.rb +14 -0
- data/spec/ribose/event_spec.rb +85 -0
- data/spec/ribose/file_uploader_spec.rb +15 -2
- data/spec/ribose/file_version_spec.rb +76 -0
- data/spec/ribose/session_spec.rb +2 -2
- data/spec/ribose/space_category_spec.rb +13 -0
- data/spec/ribose/space_file_spec.rb +44 -0
- data/spec/ribose/space_spec.rb +11 -0
- data/spec/support/fake_ribose_api.rb +93 -5
- data/spec/support/file_upload_stub.rb +21 -15
- metadata +32 -34
- data/.travis.yml +0 -5
@@ -0,0 +1,85 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Ribose::Event do
|
4
|
+
describe ".all" do
|
5
|
+
it "retrieves the list of events" do
|
6
|
+
calendar_id = 123
|
7
|
+
stub_ribose_calendar_events_api(calendar_id)
|
8
|
+
|
9
|
+
calendar_events = Ribose::Event.all(calendar_id).events
|
10
|
+
|
11
|
+
expect(calendar_events.first.id).not_to be_nil
|
12
|
+
expect(calendar_events.first.calendar_id).to eq(123)
|
13
|
+
expect(calendar_events.first.name).to eq("Sample event")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe ".fetch" do
|
18
|
+
it "retrives the details for an event" do
|
19
|
+
event_id = 456_789
|
20
|
+
calendar_id = 123_456_789
|
21
|
+
|
22
|
+
stub_ribose_event_fetch_api(calendar_id, event_id)
|
23
|
+
event = Ribose::Event.fetch(calendar_id, event_id)
|
24
|
+
|
25
|
+
expect(event.id).to eq(event_id)
|
26
|
+
expect(event.name).to eq("Sample event")
|
27
|
+
expect(event.calendar_id).to eq(calendar_id)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe ".create" do
|
32
|
+
it "creates a new event" do
|
33
|
+
calendar_id = 123_456_789
|
34
|
+
|
35
|
+
stub_ribose_event_create_api(calendar_id, event_attributes)
|
36
|
+
event = Ribose::Event.create(calendar_id, event_attributes)
|
37
|
+
|
38
|
+
expect(event.id).not_to be_nil
|
39
|
+
expect(event.name).to eq(event_attributes[:name])
|
40
|
+
expect(event.description).to eq(event_attributes[:description])
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe ".update" do
|
45
|
+
it "updates an existing event" do
|
46
|
+
event_id = 345_678_901
|
47
|
+
calendar_id = 123_456_789
|
48
|
+
|
49
|
+
stub_ribose_event_update_api(calendar_id, event_id, event_attributes)
|
50
|
+
event = Ribose::Event.update(calendar_id, event_id, event_attributes)
|
51
|
+
|
52
|
+
expect(event.first.id).not_to be_nil
|
53
|
+
expect(event.first.name).to eq("Sample event")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe ".delete" do
|
58
|
+
it "removes a calendar event" do
|
59
|
+
event_id = 456_789
|
60
|
+
calendar_id = 123_456_789
|
61
|
+
stub_ribose_event_delete_api(calendar_id, event_id)
|
62
|
+
|
63
|
+
expect do
|
64
|
+
Ribose::Event.delete(calendar_id, event_id)
|
65
|
+
end.not_to raise_error
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def event_attributes
|
70
|
+
@event_attributes ||= {
|
71
|
+
name: "Sample Event",
|
72
|
+
recurring_type: "not_repeat",
|
73
|
+
until: "never",
|
74
|
+
repeat_every: "1",
|
75
|
+
where: "Skype",
|
76
|
+
description: "Sample event",
|
77
|
+
all_day: false,
|
78
|
+
|
79
|
+
date_start: "04/04/2018",
|
80
|
+
time_start: "4:30pm",
|
81
|
+
date_finish: "04/04/2018",
|
82
|
+
time_finish: "5:30pm",
|
83
|
+
}
|
84
|
+
end
|
85
|
+
end
|
@@ -14,11 +14,24 @@ RSpec.describe Ribose::FileUploader do
|
|
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
|
}
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Ribose::FileVersion do
|
4
|
+
describe ".fetch" do
|
5
|
+
it "retrieves the details of a file version" do
|
6
|
+
file_id = 123_456
|
7
|
+
space_id = 456_789
|
8
|
+
version_id = 789_012
|
9
|
+
|
10
|
+
stub_ribose_file_version_fetch_api(space_id, file_id, version_id)
|
11
|
+
file_version = Ribose::FileVersion.fetch(
|
12
|
+
space_id: space_id, file_id: file_id, version_id: version_id,
|
13
|
+
)
|
14
|
+
|
15
|
+
expect(file_version.version).to eq(1)
|
16
|
+
expect(file_version.author).to eq("John Doe")
|
17
|
+
expect(file_version.current_version_id).to eq(789012)
|
18
|
+
end
|
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
|
76
|
+
end
|
data/spec/ribose/session_spec.rb
CHANGED
@@ -15,11 +15,11 @@ RSpec.describe Ribose::Session do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def login_url
|
18
|
-
ribose_url_for("
|
18
|
+
ribose_url_for("api/v2/auth/sign_in")
|
19
19
|
end
|
20
20
|
|
21
21
|
def ribose_url_for(*endpoints)
|
22
|
-
[Ribose.configuration.
|
22
|
+
[Ribose.configuration.api_host, *endpoints].join("/")
|
23
23
|
end
|
24
24
|
|
25
25
|
def stub_session_creation_request_via_web
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Ribose::SpaceCategory do
|
4
|
+
describe ".all" do
|
5
|
+
it "retrieves the list of space categories" do
|
6
|
+
stub_ribose_space_categories_api
|
7
|
+
categories = Ribose::SpaceCategory.all
|
8
|
+
|
9
|
+
expect(categories.first.id).not_to be_nil
|
10
|
+
expect(categories.first.name).to eq("animals")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -28,6 +28,37 @@ 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
|
@@ -67,6 +98,19 @@ RSpec.describe Ribose::SpaceFile do
|
|
67
98
|
end
|
68
99
|
end
|
69
100
|
|
101
|
+
describe ".fetch_icon" do
|
102
|
+
it "retrives the details for a file icon" do
|
103
|
+
file_id = 456_789_012
|
104
|
+
space_id = 123_456_789
|
105
|
+
|
106
|
+
stub_ribose_space_file_fetch_icon_api(space_id, file_id)
|
107
|
+
icon = Ribose::SpaceFile.fetch_icon(space_id, file_id)
|
108
|
+
|
109
|
+
expect(icon.icon_processed).to be_truthy
|
110
|
+
expect(icon.icon_path).to eq("/spaces/files/icon_path?type=usual")
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
70
114
|
def file_attributes
|
71
115
|
{
|
72
116
|
file: sample_fixture_file,
|
data/spec/ribose/space_spec.rb
CHANGED
@@ -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",
|
@@ -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
|
@@ -127,6 +133,40 @@ module Ribose
|
|
127
133
|
)
|
128
134
|
end
|
129
135
|
|
136
|
+
def stub_ribose_event_fetch_api(calender_id, event_id)
|
137
|
+
stub_api_response(
|
138
|
+
:get,
|
139
|
+
"calendar/calendar/#{calender_id}/event/#{event_id}",
|
140
|
+
filename: "calendar_event",
|
141
|
+
)
|
142
|
+
end
|
143
|
+
|
144
|
+
def stub_ribose_event_create_api(calender_id, event_attributes)
|
145
|
+
stub_api_response(
|
146
|
+
:post,
|
147
|
+
"calendar/calendar/#{calender_id}/event",
|
148
|
+
data: { event: event_attributes },
|
149
|
+
filename: "event_created",
|
150
|
+
)
|
151
|
+
end
|
152
|
+
|
153
|
+
def stub_ribose_event_update_api(calender_id, event_id, attributes)
|
154
|
+
stub_api_response(
|
155
|
+
:put,
|
156
|
+
"calendar/calendar/#{calender_id}/event/#{event_id}",
|
157
|
+
data: { event: attributes },
|
158
|
+
filename: "event_updated",
|
159
|
+
)
|
160
|
+
end
|
161
|
+
|
162
|
+
def stub_ribose_event_delete_api(calender_id, event_id)
|
163
|
+
stub_api_response(
|
164
|
+
:delete,
|
165
|
+
"calendar/calendar/#{calender_id}/event/#{event_id}",
|
166
|
+
filename: "empty",
|
167
|
+
)
|
168
|
+
end
|
169
|
+
|
130
170
|
def stub_ribose_app_user_create_api(attributes)
|
131
171
|
stub_api_response(
|
132
172
|
:post,
|
@@ -159,6 +199,11 @@ module Ribose
|
|
159
199
|
stub_api_response(:get, file_endppoint, filename: "space_file")
|
160
200
|
end
|
161
201
|
|
202
|
+
def stub_ribose_space_file_fetch_icon_api(space_id, file_id)
|
203
|
+
path = ["spaces", space_id, "file", "files", file_id, "icon"].join("/")
|
204
|
+
stub_api_response(:get, path, filename: "space_file_icon")
|
205
|
+
end
|
206
|
+
|
162
207
|
def stub_ribose_space_file_update_api(space_id, file_id, attributes)
|
163
208
|
stub_api_response(
|
164
209
|
:put,
|
@@ -173,6 +218,25 @@ module Ribose
|
|
173
218
|
stub_api_response(:delete, file_endppoint, filename: "empty")
|
174
219
|
end
|
175
220
|
|
221
|
+
def stub_ribose_file_version_fetch_api(sid, fid, vid)
|
222
|
+
stub_api_response(
|
223
|
+
:get,
|
224
|
+
["spaces", sid, "file/files", fid, "versions", vid].join("/"),
|
225
|
+
filename: "file_version",
|
226
|
+
)
|
227
|
+
end
|
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
|
+
|
176
240
|
def stub_ribose_space_conversation_list(space_id)
|
177
241
|
stub_api_response(
|
178
242
|
:get, conversations_path(space_id), filename: "conversations"
|
@@ -207,6 +271,14 @@ module Ribose
|
|
207
271
|
)
|
208
272
|
end
|
209
273
|
|
274
|
+
def stub_ribose_space_conversation_mafav_api(sid, cid)
|
275
|
+
stub_api_response(
|
276
|
+
:put,
|
277
|
+
[conversations_path(sid), cid, "mark_as_favorite"].join("/"),
|
278
|
+
filename: "conversation",
|
279
|
+
)
|
280
|
+
end
|
281
|
+
|
210
282
|
def stub_ribose_space_conversation_remove(space_id, conversation_id)
|
211
283
|
path = [conversations_path(space_id), conversation_id].join("/")
|
212
284
|
stub_api_response(:delete, path, filename: "empty", status: 200)
|
@@ -255,6 +327,12 @@ module Ribose
|
|
255
327
|
stub_api_response(:get, "people/connections?s=", filename: "connections")
|
256
328
|
end
|
257
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
|
+
|
258
336
|
def stub_ribose_suggestion_list_api
|
259
337
|
stub_api_response(
|
260
338
|
:get, "people_finding", filename: "connection_suggestion"
|
@@ -433,6 +511,12 @@ module Ribose
|
|
433
511
|
)
|
434
512
|
end
|
435
513
|
|
514
|
+
def stub_ribose_space_categories_api
|
515
|
+
stub_api_response(
|
516
|
+
:get, "space_categories", filename: "space_categories"
|
517
|
+
)
|
518
|
+
end
|
519
|
+
|
436
520
|
private
|
437
521
|
|
438
522
|
def ribose_endpoint(endpoint)
|
@@ -470,11 +554,11 @@ module Ribose
|
|
470
554
|
end
|
471
555
|
end
|
472
556
|
|
473
|
-
def response_with(filename:, status:)
|
557
|
+
def response_with(filename:, status:, content_type: "application/json")
|
474
558
|
{
|
475
559
|
status: status,
|
476
560
|
body: ribose_fixture(filename),
|
477
|
-
headers: { content_type:
|
561
|
+
headers: { content_type: content_type },
|
478
562
|
}
|
479
563
|
end
|
480
564
|
|
@@ -485,11 +569,15 @@ module Ribose
|
|
485
569
|
File.read(File.expand_path(file_path, __FILE__))
|
486
570
|
end
|
487
571
|
|
488
|
-
def stub_api_response(method, endpoint, filename:,
|
489
|
-
|
572
|
+
def stub_api_response(method, endpoint, filename:, status: 200, data: nil,
|
573
|
+
client: nil, content_type: "application/json")
|
490
574
|
stub_request(method, ribose_endpoint(endpoint)).
|
491
575
|
with(ribose_headers(data: data, client: client)).
|
492
|
-
to_return(
|
576
|
+
to_return(
|
577
|
+
response_with(
|
578
|
+
filename: filename, status: status, content_type: content_type,
|
579
|
+
),
|
580
|
+
)
|
493
581
|
end
|
494
582
|
end
|
495
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)
|