ribose 0.1.0 → 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.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +539 -970
  4. data/.sample.pryrc +4 -0
  5. data/CHANGELOG.md +5 -0
  6. data/README.md +539 -3
  7. data/bin/console +2 -5
  8. data/lib/ribose.rb +31 -1
  9. data/lib/ribose/actions.rb +10 -0
  10. data/lib/ribose/actions/all.rb +43 -0
  11. data/lib/ribose/actions/base.rb +11 -0
  12. data/lib/ribose/actions/create.rb +44 -0
  13. data/lib/ribose/actions/delete.rb +32 -0
  14. data/lib/ribose/actions/fetch.rb +44 -0
  15. data/lib/ribose/actions/update.rb +35 -0
  16. data/lib/ribose/app_data.rb +15 -0
  17. data/lib/ribose/app_relation.rb +12 -0
  18. data/lib/ribose/base.rb +48 -0
  19. data/lib/ribose/calendar.rb +22 -0
  20. data/lib/ribose/client.rb +31 -0
  21. data/lib/ribose/config.rb +21 -0
  22. data/lib/ribose/configuration.rb +25 -0
  23. data/lib/ribose/connection.rb +39 -0
  24. data/lib/ribose/connection_invitation.rb +51 -0
  25. data/lib/ribose/conversation.rb +87 -0
  26. data/lib/ribose/error.rb +30 -0
  27. data/lib/ribose/feed.rb +11 -0
  28. data/lib/ribose/file_uploader.rb +93 -0
  29. data/lib/ribose/join_space_request.rb +41 -0
  30. data/lib/ribose/leaderboard.rb +19 -0
  31. data/lib/ribose/member.rb +34 -0
  32. data/lib/ribose/message.rb +94 -0
  33. data/lib/ribose/profile.rb +56 -0
  34. data/lib/ribose/request.rb +122 -0
  35. data/lib/ribose/resource_helper.rb +81 -0
  36. data/lib/ribose/response/raise_error.rb +15 -0
  37. data/lib/ribose/rspec.rb +19 -0
  38. data/lib/ribose/session.rb +48 -0
  39. data/lib/ribose/setting.rb +16 -0
  40. data/lib/ribose/space.rb +30 -0
  41. data/lib/ribose/space_file.rb +49 -0
  42. data/lib/ribose/space_invitation.rb +70 -0
  43. data/lib/ribose/stream.rb +15 -0
  44. data/lib/ribose/user.rb +42 -0
  45. data/lib/ribose/version.rb +1 -1
  46. data/lib/ribose/widget.rb +11 -0
  47. data/lib/ribose/wiki.rb +80 -0
  48. data/ribose.gemspec +6 -0
  49. data/spec/fixtures/app_data.json +188 -0
  50. data/spec/fixtures/app_relation.json +19 -0
  51. data/spec/fixtures/app_relations.json +89 -0
  52. data/spec/fixtures/calendar.json +12 -0
  53. data/spec/fixtures/calendars.json +34 -0
  54. data/spec/fixtures/connection_invitation.json +26 -0
  55. data/spec/fixtures/connection_invitation_accepted.json +26 -0
  56. data/spec/fixtures/connection_invitations.json +28 -0
  57. data/spec/fixtures/connection_invitations_created.json +37 -0
  58. data/spec/fixtures/connection_suggestion.json +22 -0
  59. data/spec/fixtures/connections.json +28 -0
  60. data/spec/fixtures/conversation.json +26 -0
  61. data/spec/fixtures/conversation_created.json +31 -0
  62. data/spec/fixtures/conversations.json +34 -0
  63. data/spec/fixtures/empty.json +1 -0
  64. data/spec/fixtures/feeds.json +84 -0
  65. data/spec/fixtures/file_upload_prepared.json +17 -0
  66. data/spec/fixtures/file_uploaded.json +38 -0
  67. data/spec/fixtures/general_information.json +16 -0
  68. data/spec/fixtures/join_space_request_created.json +26 -0
  69. data/spec/fixtures/join_space_request_updated.json +25 -0
  70. data/spec/fixtures/join_space_requests.json +34 -0
  71. data/spec/fixtures/leaderboard.json +21 -0
  72. data/spec/fixtures/login.html +323 -0
  73. data/spec/fixtures/members.json +20 -0
  74. data/spec/fixtures/message.json +22 -0
  75. data/spec/fixtures/messages.json +24 -0
  76. data/spec/fixtures/ping.json +3 -0
  77. data/spec/fixtures/profile.json +10 -0
  78. data/spec/fixtures/sample.png +0 -0
  79. data/spec/fixtures/setting.json +16 -0
  80. data/spec/fixtures/settings.json +18 -0
  81. data/spec/fixtures/space.json +59 -0
  82. data/spec/fixtures/space_created.json +59 -0
  83. data/spec/fixtures/space_file.json +58 -0
  84. data/spec/fixtures/space_invitation.json +32 -0
  85. data/spec/fixtures/space_invitation_updated.json +35 -0
  86. data/spec/fixtures/space_invitations.json +34 -0
  87. data/spec/fixtures/space_mass_invitations.json +46 -0
  88. data/spec/fixtures/spaces.json +61 -0
  89. data/spec/fixtures/stream.json +176 -0
  90. data/spec/fixtures/user_activated.json +6 -0
  91. data/spec/fixtures/widgets.json +50 -0
  92. data/spec/fixtures/wiki.json +79 -0
  93. data/spec/fixtures/wikis.json +197 -0
  94. data/spec/ribose/actions/create_spec.rb +40 -0
  95. data/spec/ribose/actions/delete_spec.rb +24 -0
  96. data/spec/ribose/actions/fetch_spec.rb +32 -0
  97. data/spec/ribose/actions/update_spec.rb +36 -0
  98. data/spec/ribose/app_data_spec.rb +15 -0
  99. data/spec/ribose/app_relation_spec.rb +27 -0
  100. data/spec/ribose/calendar_spec.rb +50 -0
  101. data/spec/ribose/client_spec.rb +48 -0
  102. data/spec/ribose/config_spec.rb +41 -0
  103. data/spec/ribose/connection_invitation_spec.rb +79 -0
  104. data/spec/ribose/connection_spec.rb +26 -0
  105. data/spec/ribose/conversation_spec.rb +84 -0
  106. data/spec/ribose/error_spec.rb +67 -0
  107. data/spec/ribose/feed_spec.rb +14 -0
  108. data/spec/ribose/file_uploader_spec.rb +30 -0
  109. data/spec/ribose/join_space_request_spec.rb +70 -0
  110. data/spec/ribose/leaderboard_spec.rb +13 -0
  111. data/spec/ribose/member_spec.rb +16 -0
  112. data/spec/ribose/message_spec.rb +69 -0
  113. data/spec/ribose/profile_spec.rb +40 -0
  114. data/spec/ribose/request_spec.rb +66 -0
  115. data/spec/ribose/resource_helper_spec.rb +58 -0
  116. data/spec/ribose/session_spec.rb +46 -0
  117. data/spec/ribose/setting_spec.rb +40 -0
  118. data/spec/ribose/space_file_spec.rb +41 -0
  119. data/spec/ribose/space_invitation_spec.rb +117 -0
  120. data/spec/ribose/space_spec.rb +70 -0
  121. data/spec/ribose/stream_spec.rb +14 -0
  122. data/spec/ribose/user_spec.rb +48 -0
  123. data/spec/ribose/widget_spec.rb +14 -0
  124. data/spec/ribose/wiki_spec.rb +67 -0
  125. data/spec/spec_helper.rb +11 -0
  126. data/spec/support/fake_ribose_api.rb +431 -0
  127. data/spec/support/file_upload_stub.rb +76 -0
  128. metadata +190 -3
  129. data/spec/ribose_spec.rb +0 -4
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,9 @@
1
+ require "webmock/rspec"
1
2
  require "bundler/setup"
2
3
  require "ribose"
4
+ require "ribose/rspec"
5
+
6
+ Dir["./spec/support/**/*.rb"].sort.each { |file| require file }
3
7
 
4
8
  RSpec.configure do |config|
5
9
  # Enable flags like --only-failures and --next-failure
@@ -8,4 +12,11 @@ RSpec.configure do |config|
8
12
  config.expect_with :rspec do |c|
9
13
  c.syntax = :expect
10
14
  end
15
+
16
+ config.before :all do
17
+ Ribose.configure do |ribose_config|
18
+ ribose_config.api_token = ENV["RIBOSE_API_TOKEN"] || "RIBOSE_API_TOKEN"
19
+ ribose_config.user_email = ENV["RIBOSE_USER_EMAIL"] || "RIBOSE_USER_EMAIL"
20
+ end
21
+ end
11
22
  end
@@ -0,0 +1,431 @@
1
+ require File.join(Ribose.root, "spec/support/file_upload_stub")
2
+
3
+ module Ribose
4
+ module FakeRiboseApi
5
+ include Ribose::FileUploadStub
6
+
7
+ def stub_ribose_space_list_api
8
+ stub_api_response(:get, "spaces", filename: "spaces")
9
+ end
10
+
11
+ def stub_ribose_space_create_api(attributes)
12
+ stub_api_response(
13
+ :post, "spaces", data: { space: attributes }, filename: "space_created"
14
+ )
15
+ end
16
+
17
+ def stub_ribose_space_update_api(uuid, attributes)
18
+ stub_api_response(
19
+ :put, "spaces/#{uuid}", data: { space: attributes }, filename: "space"
20
+ )
21
+ end
22
+
23
+ def stub_ribose_space_fetch_api(space_id)
24
+ stub_api_response(:get, "spaces/#{space_id}", filename: "space")
25
+ end
26
+
27
+ def stub_ribose_space_remove_api(space_uuid, options = {})
28
+ stub_api_response(
29
+ :post, "spaces/#{space_uuid}/freeze", data: options, filename: "empty"
30
+ )
31
+ end
32
+
33
+ def stub_ribose_feed_api
34
+ stub_api_response(:get, "feeds", filename: "feeds")
35
+ end
36
+
37
+ def stub_ribose_space_member_list(space_id)
38
+ stub_api_response(:get, "spaces/#{space_id}/members", filename: "members")
39
+ end
40
+
41
+ def stub_ribose_setting_list_api
42
+ stub_api_response(:get, "settings", filename: "settings")
43
+ end
44
+
45
+ def stub_ribose_setting_find_api(id)
46
+ stub_api_response(:get, "settings/#{id}", filename: "setting")
47
+ end
48
+
49
+ def stub_ribose_setting_update_api(uuid, attributes)
50
+ stub_api_response(
51
+ :put,
52
+ "settings/#{uuid}",
53
+ data: { setting: attributes },
54
+ filename: "setting",
55
+ )
56
+ end
57
+
58
+ def stub_ribose_stream_list_api
59
+ stub_api_response(:get, "stream", filename: "stream")
60
+ end
61
+
62
+ def stub_ribose_widget_list_api
63
+ stub_api_response(:get, "widgets", filename: "widgets")
64
+ end
65
+
66
+ def stub_ribose_calendar_list_api
67
+ stub_api_response(:get, "calendar/calendar", filename: "calendars")
68
+ end
69
+
70
+ def stub_ribose_calendar_fetch_api(calender_id)
71
+ stub_api_response(
72
+ :get,
73
+ "calendar/calendar/#{calender_id}",
74
+ filename: "calendar",
75
+ )
76
+ end
77
+
78
+ def stub_ribose_calendar_create_api(attributes)
79
+ stub_api_response(
80
+ :post,
81
+ "calendar/calendar",
82
+ data: { calendar: attributes },
83
+ filename: "calendar",
84
+ )
85
+ end
86
+
87
+ def stub_ribose_calendar_delete_api(calender_id)
88
+ stub_api_response(
89
+ :delete, "calendar/calendar/#{calender_id}", filename: "empty"
90
+ )
91
+ end
92
+
93
+ def stub_ribose_app_user_create_api(attributes)
94
+ stub_api_response(
95
+ :post,
96
+ "signup_requests",
97
+ data: { user: attributes },
98
+ filename: "empty",
99
+ )
100
+ end
101
+
102
+ def stub_ribose_app_user_activate_api(attributes)
103
+ stub_api_response(
104
+ :post,
105
+ "signup.user",
106
+ data: { user: attributes },
107
+ filename: "user_activated",
108
+ )
109
+ end
110
+
111
+ def stub_ribose_app_data_api
112
+ stub_api_response(:get, "app_data", filename: "app_data")
113
+ end
114
+
115
+ def stub_ribose_space_file_list(space_id)
116
+ file_endppoint = ["spaces", space_id, "file", "files"].join("/")
117
+ stub_api_response(:get, file_endppoint, filename: "space_file")
118
+ end
119
+
120
+ def stub_ribose_space_conversation_list(space_id)
121
+ stub_api_response(
122
+ :get, conversations_path(space_id), filename: "conversations"
123
+ )
124
+ end
125
+
126
+ def stub_ribose_space_conversation_fetch_api(space_id, conv_id)
127
+ stub_api_response(
128
+ :get,
129
+ [conversations_path(space_id), conv_id].join("/"),
130
+ filename: "conversation",
131
+ )
132
+ end
133
+
134
+ def stub_ribose_space_conversation_create(space_id, attributes)
135
+ stub_api_response(
136
+ :post,
137
+ conversations_path(space_id),
138
+ filename: "conversation_created",
139
+ data: { conversation: attributes },
140
+ )
141
+ end
142
+
143
+ def stub_ribose_space_conversation_update_api(sid, cid, attributes)
144
+ attributes.delete(:space_id)
145
+
146
+ stub_api_response(
147
+ :put,
148
+ [conversations_path(sid), cid].join("/"),
149
+ data: { conversation: attributes },
150
+ filename: "conversation",
151
+ )
152
+ end
153
+
154
+ def stub_ribose_space_conversation_remove(space_id, conversation_id)
155
+ path = [conversations_path(space_id), conversation_id].join("/")
156
+ stub_api_response(:delete, path, filename: "empty", status: 200)
157
+ end
158
+
159
+ def stub_ribose_message_list(space_id, conversation_id)
160
+ stub_api_response(
161
+ :get, messages_path(space_id, conversation_id), filename: "messages"
162
+ )
163
+ end
164
+
165
+ def stub_ribose_message_create(space_id, attributes)
166
+ path = messages_path(space_id, attributes[:message][:conversation_id])
167
+ stub_api_response(:post, path, data: attributes, filename: "message")
168
+ end
169
+
170
+ def stub_ribose_message_update(space_id, message_id, attributes)
171
+ conversation_id = attributes[:message].delete(:conversation_id)
172
+ path = [messages_path(space_id, conversation_id), message_id].join("/")
173
+
174
+ stub_api_response(:put, path, data: attributes, filename: "message")
175
+ end
176
+
177
+ def stub_ribose_message_remove(space_id, message_id, conversation_id)
178
+ path = [messages_path(space_id, conversation_id), message_id].join("/")
179
+ stub_api_response(:delete, path, filename: "empty", status: 200)
180
+ end
181
+
182
+ def stub_ribose_leaderboard_api
183
+ stub_api_response(
184
+ :get, "activity_point/leaderboard", filename: "leaderboard"
185
+ )
186
+ end
187
+
188
+ def stub_ribose_app_relation_list_api
189
+ stub_api_response(:get, "app_relations", filename: "app_relations")
190
+ end
191
+
192
+ def stub_ribose_app_relation_find_api(relation_id)
193
+ stub_api_response(
194
+ :get, "app_relations/#{relation_id}", filename: "app_relation"
195
+ )
196
+ end
197
+
198
+ def stub_ribose_connection_list_api
199
+ stub_api_response(:get, "people/connections?s=", filename: "connections")
200
+ end
201
+
202
+ def stub_ribose_suggestion_list_api
203
+ stub_api_response(
204
+ :get, "people_finding", filename: "connection_suggestion"
205
+ )
206
+ end
207
+
208
+ def stub_ribose_connection_invitation_lis_api
209
+ stub_api_response(
210
+ :get, "invitations/to_connection", filename: "connection_invitations"
211
+ )
212
+ end
213
+
214
+ def stub_ribose_connection_invitation_fetch_api(invitation_id)
215
+ stub_api_response(
216
+ :get,
217
+ "invitations/to_connection/#{invitation_id}",
218
+ filename: "connection_invitation",
219
+ )
220
+ end
221
+
222
+ def stub_ribose_connection_invitation_create_api(emails, body)
223
+ stub_api_response(
224
+ :post,
225
+ "invitations/to_connection/mass_create",
226
+ filename: "connection_invitations_created",
227
+ data: { invitation: { body: body, emails: emails } },
228
+ )
229
+ end
230
+
231
+ def stub_ribose_connection_invitation_update_api(invitation_id, state)
232
+ stub_api_response(
233
+ :put,
234
+ "invitations/to_connection/#{invitation_id}",
235
+ data: { invitation: { state: state } },
236
+ filename: "connection_invitation_accepted",
237
+ )
238
+ end
239
+
240
+ def stub_ribose_connection_invitation_cancel_api(invitation_id)
241
+ stub_api_response(
242
+ :delete, "invitations/to_connection/#{invitation_id}", filename: "empty"
243
+ )
244
+ end
245
+
246
+ def stub_ribose_space_invitation_lis_api
247
+ stub_api_response(
248
+ :get, "invitations/to_space", filename: "space_invitations"
249
+ )
250
+ end
251
+
252
+ def stub_ribose_space_invitation_create_api(attributes)
253
+ stub_api_response(
254
+ :post,
255
+ "invitations/to_space",
256
+ data: { invitation: attributes },
257
+ filename: "space_invitation",
258
+ )
259
+ end
260
+
261
+ def stub_ribose_space_invitation_mass_create(space_id, attributes)
262
+ stub_api_response(
263
+ :post,
264
+ "spaces/#{space_id}/invitations/to_space/mass_create",
265
+ data: { invitation: attributes.merge(space_id: space_id) },
266
+ filename: "space_mass_invitations",
267
+ )
268
+ end
269
+
270
+ def stub_ribose_space_invitation_resend_api(invitation_id)
271
+ stub_api_response(
272
+ :post,
273
+ "invitations/to_new_member/#{invitation_id}/resend",
274
+ filename: "space_invitation_updated",
275
+ )
276
+ end
277
+
278
+ def stub_ribose_space_invitation_update_api(invitation_id, attributes)
279
+ stub_api_response(
280
+ :put,
281
+ "invitations/to_space/#{invitation_id}",
282
+ data: { invitation: attributes },
283
+ filename: "space_invitation_updated",
284
+ )
285
+ end
286
+
287
+ def stub_ribose_space_invitation_cancel_api(invitation_id)
288
+ stub_api_response(
289
+ :delete, "invitations/to_space/#{invitation_id}", filename: "empty"
290
+ )
291
+ end
292
+
293
+ def stub_ribose_join_space_request_list_api
294
+ stub_api_response(
295
+ :get, "invitations/join_space_request", filename: "join_space_requests"
296
+ )
297
+ end
298
+
299
+ def stub_ribose_join_space_request_create_api(attributes)
300
+ stub_api_response(
301
+ :post,
302
+ "invitations/join_space_request",
303
+ data: { invitation: attributes },
304
+ filename: "join_space_request_created",
305
+ )
306
+ end
307
+
308
+ def stub_ribose_join_space_request_update(invitation_id, attributes)
309
+ stub_api_response(
310
+ :put,
311
+ "invitations/join_space_request/#{invitation_id}",
312
+ data: { invitation: attributes },
313
+ filename: "join_space_request_updated",
314
+ )
315
+ end
316
+
317
+ def stub_ribose_fetch_profile_api
318
+ stub_api_response(:get, "people/profile/", filename: "profile")
319
+ end
320
+
321
+ def stub_ribose_update_profile_api(attributes)
322
+ stub_api_response(
323
+ :put, "people/profile/", data: { user: attributes }, filename: "profile"
324
+ )
325
+ end
326
+
327
+ def stub_ribose_set_login_name_api(user_id, name)
328
+ stub_api_response(
329
+ :put,
330
+ "people/users/#{user_id}",
331
+ data: { user: { login: name } },
332
+ filename: "profile",
333
+ )
334
+ end
335
+
336
+ def stub_ribose_wiki_list_api(space_id)
337
+ stub_api_response(
338
+ :get, "spaces/#{space_id}/wiki/wiki_pages", filename: "wikis"
339
+ )
340
+ end
341
+
342
+ def stub_ribose_wiki_fetch_api(sid, wiki_id)
343
+ stub_api_response(
344
+ :get, "spaces/#{sid}/wiki/wiki_pages/#{wiki_id}", filename: "wiki"
345
+ )
346
+ end
347
+
348
+ def stub_ribose_wiki_create_api(space_id, attributes)
349
+ stub_api_response(
350
+ :post,
351
+ "spaces/#{space_id}/wiki/wiki_pages",
352
+ data: { wiki_page: attributes },
353
+ filename: "wiki",
354
+ )
355
+ end
356
+
357
+ def stub_ribose_wiki_update_api(space_id, wiki_id, attributes)
358
+ stub_api_response(
359
+ :put,
360
+ "spaces/#{space_id}/wiki/wiki_pages/#{wiki_id}",
361
+ data: { wiki_page: attributes },
362
+ filename: "wiki",
363
+ )
364
+ end
365
+
366
+ def stub_ribose_wiki_delete_api(sid, wiki_id)
367
+ stub_api_response(
368
+ :delete, "spaces/#{sid}/wiki/wiki_pages/#{wiki_id}", filename: "empty"
369
+ )
370
+ end
371
+
372
+ private
373
+
374
+ def ribose_endpoint(endpoint)
375
+ ["https://www.ribose.com", endpoint].join("/")
376
+ end
377
+
378
+ def conversations_path(space_id)
379
+ ["spaces", space_id, "conversation", "conversations"].join("/")
380
+ end
381
+
382
+ def messages_path(space_id, conversation_id)
383
+ [conversations_path(space_id), conversation_id, "messages"].join("/")
384
+ end
385
+
386
+ def ribose_headers(data: nil, client: nil)
387
+ client ||= Ribose::Client.new
388
+
389
+ Hash.new.tap do |request|
390
+ request[:headers] = ribose_auth_headers(client)
391
+
392
+ unless data.nil?
393
+ request[:body] = data.to_json
394
+ end
395
+ end
396
+ end
397
+
398
+ def ribose_auth_headers(client)
399
+ Hash.new.tap do |headers|
400
+ headers["Accept"] = "application/json"
401
+
402
+ if Ribose.configuration.api_token
403
+ headers["X-Indigo-Token"] = client.api_token
404
+ headers["X-Indigo-Email"] = client.user_email
405
+ end
406
+ end
407
+ end
408
+
409
+ def response_with(filename:, status:)
410
+ {
411
+ status: status,
412
+ body: ribose_fixture(filename),
413
+ headers: { content_type: "application/json" },
414
+ }
415
+ end
416
+
417
+ def ribose_fixture(filename, ext = "json")
418
+ filename = [filename, ext].join(".")
419
+ file_path = File.join(Ribose.root, "spec", "fixtures", filename)
420
+
421
+ File.read(File.expand_path(file_path, __FILE__))
422
+ end
423
+
424
+ def stub_api_response(method, endpoint, filename:,
425
+ status: 200, data: nil, client: nil)
426
+ stub_request(method, ribose_endpoint(endpoint)).
427
+ with(ribose_headers(data: data, client: client)).
428
+ to_return(response_with(filename: filename, status: status))
429
+ end
430
+ end
431
+ end