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
@@ -0,0 +1,39 @@
1
+ module Ribose
2
+ class Connection < Ribose::Base
3
+ include Ribose::Actions::All
4
+
5
+ # List Connections
6
+ #
7
+ # Note: Currently, There are some chaching in place for this endpoint
8
+ # which requires us to pass the `s` query params otherwise we might
9
+ # have some unexpected behavior sometime. That's why we are adding
10
+ # the `s` incase that's not present with the query options.
11
+ #
12
+ # @param options [Hash] Query parameters as a Hash
13
+ # @return [Sawyer::Resource]
14
+ #
15
+ def self.all(options = {})
16
+ new(options.merge(query: { s: "" })).all
17
+ end
18
+
19
+ # List connection suggestions
20
+ #
21
+ # @param options [Hash] Query parameters as a Hash
22
+ # @return [Array <Sawyer::Resource>]
23
+ #
24
+ def self.suggestions(client: nil, **options)
25
+ Request.get("people_finding", client: client, query: options).
26
+ suggested_connection
27
+ end
28
+
29
+ private
30
+
31
+ def resource
32
+ "connection"
33
+ end
34
+
35
+ def resources_path
36
+ "people/connections"
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,51 @@
1
+ module Ribose
2
+ class ConnectionInvitation < Ribose::Base
3
+ include Ribose::Actions::All
4
+ include Ribose::Actions::Fetch
5
+ include Ribose::Actions::Update
6
+ include Ribose::Actions::Delete
7
+
8
+ def create
9
+ create_invitations[:invitations]
10
+ end
11
+
12
+ def self.create(body:, emails:, **attributes)
13
+ new(attributes.merge(body: body, emails: emails)).create
14
+ end
15
+
16
+ def self.accept(invitation_id, attributes = {})
17
+ new(attributes.merge(resource_id: invitation_id, state: 1)).update
18
+ end
19
+
20
+ def self.reject(invitation_id, attributes = {})
21
+ new(attributes.merge(resource_id: invitation_id, state: 2)).update
22
+ end
23
+
24
+ private
25
+
26
+ def resource
27
+ "to_connection"
28
+ end
29
+
30
+ def resource_key
31
+ "invitation"
32
+ end
33
+
34
+ def resources_path
35
+ "invitations/to_connection"
36
+ end
37
+
38
+ def extract_local_attributes
39
+ @invitation_id = attributes.delete(:invitation_id)
40
+ end
41
+
42
+ def create_invitations
43
+ Ribose::Request.post(
44
+ [resources_path, "mass_create"].join("/"),
45
+ custom_option.merge(
46
+ invitation: { body: attributes[:body], emails: attributes[:emails] }
47
+ )
48
+ )
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,87 @@
1
+ module Ribose
2
+ class Conversation < Ribose::Base
3
+ include Ribose::Actions::All
4
+ include Ribose::Actions::Fetch
5
+ include Ribose::Actions::Create
6
+ include Ribose::Actions::Update
7
+ include Ribose::Actions::Delete
8
+
9
+ # Listing Space Conversations
10
+ #
11
+ # @param space_id [String] The Space UUID
12
+ # @param options [Hash] Query parameters as a Hash
13
+ # @return [Array <Sawyer::Resource>]
14
+ #
15
+ def self.all(space_id, options = {})
16
+ new(space_id: space_id, **options).all
17
+ end
18
+
19
+ # Fetch a conversation
20
+ #
21
+ # @param space_id [String] The Space UUID
22
+ # @param conversation_id [String] Conversation UUID
23
+ # @param options [Hash] Query parameters as a Hash
24
+ # @return [Sawyer::Resource] The conversation
25
+ #
26
+ def self.fetch(space_id, conversation_id, options = {})
27
+ new(space_id: space_id, conversation_id: conversation_id, **options).fetch
28
+ end
29
+
30
+ # Create A New Conversation
31
+ #
32
+ # @param space_id [String] The Space UUID
33
+ # @param attributes [Hash] The conversation attributes
34
+ # @return [Sawyer::Resource]
35
+ #
36
+ def self.create(space_id, attributes)
37
+ new(attributes.merge(space_id: space_id)).create
38
+ end
39
+
40
+ # Update a conversation
41
+ #
42
+ # @param space_id [String] The Space UUID
43
+ # @param conversation_id [String] Conversation UUID
44
+ # @param attributes [Hash] Query parameters as a Hash
45
+ # @return [Sawyer::Resource] The updated conversation
46
+ #
47
+ def self.update(space_id, conversation_id, attributes = {})
48
+ new(
49
+ space_id: space_id,
50
+ conversation_id: conversation_id,
51
+ **attributes,
52
+ ).update
53
+ end
54
+
55
+ # Remove a conversation
56
+ #
57
+ # @param space_id [String] The Space UUID
58
+ # @param conversation_id [String] Conversation UUID
59
+ # @param options [Hash] Query parameters as a Hash
60
+ #
61
+ def self.destroy(space_id:, conversation_id:, **opts)
62
+ new(space_id: space_id, conversation_id: conversation_id, **opts).delete
63
+ end
64
+
65
+ private
66
+
67
+ attr_reader :space_id, :conversation_id
68
+ alias_method :resource_id, :conversation_id
69
+
70
+ def extract_local_attributes
71
+ @space_id = attributes.delete(:space_id)
72
+ @conversation_id = attributes.delete(:conversation_id)
73
+ end
74
+
75
+ def resource
76
+ "conversation"
77
+ end
78
+
79
+ def resources_path
80
+ ["spaces", space_id, "conversation", "conversations"].join("/")
81
+ end
82
+
83
+ def validate(attributes)
84
+ attributes.merge(space_id: space_id)
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,30 @@
1
+ module Ribose
2
+ class Error < StandardError
3
+ def initialize(response = nil)
4
+ @response = response
5
+ super
6
+ end
7
+
8
+ def self.from_response(response)
9
+ status = response[:status].to_i
10
+ if klass = case status
11
+ when 400 then Ribose::BadRequest
12
+ when 401 then Ribose::Unauthorized
13
+ when 403 then Ribose::Forbidden
14
+ when 404 then Ribose::NotFound
15
+ when 422 then Ribose::UnprocessableEntity
16
+ when 500..599 then Ribose::ServerError
17
+ end
18
+
19
+ klass.new(response)
20
+ end
21
+ end
22
+ end
23
+
24
+ class BadRequest < Error; end
25
+ class Unauthorized < Error; end
26
+ class Forbidden < Error; end
27
+ class NotFound < Error; end
28
+ class UnprocessableEntity < Error; end
29
+ class ServerError < Error; end
30
+ end
@@ -0,0 +1,11 @@
1
+ module Ribose
2
+ class Feed < Ribose::Base
3
+ include Ribose::Actions::All
4
+
5
+ private
6
+
7
+ def resource
8
+ "feed"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,93 @@
1
+ require "faraday"
2
+
3
+ module Ribose
4
+ class FileUploader
5
+ # Initialize the file uploader
6
+ #
7
+ # @param space_id [String] The Space UUID
8
+ # @param file [File] The complete path for file
9
+ # @param attributes [Hash] Attributes as a Hash
10
+ def initialize(space_id, file:, **attributes)
11
+ @space_id = space_id
12
+ @file = File.new(file)
13
+ @attributes = attributes
14
+ end
15
+
16
+ # Create a file upload
17
+ #
18
+ # @return [Sawyer::Resource] File upload response.
19
+ def create
20
+ upload_meta = prepare_to_upload
21
+ response = upload_to_aws_s3(upload_meta)
22
+ notify_ribose_file_upload_endpoint(response, upload_meta.fields.key)
23
+ end
24
+
25
+ # Create a new upload
26
+ #
27
+ # @param space_id [String] The Space UUID
28
+ # @param file [File] The complete path for file
29
+ # @param attributes [Hash] Attributes as a Hash
30
+ # @return [Sawyer::Resource] File upload response.
31
+ def self.upload(space_id, file:, **attributes)
32
+ new(space_id, attributes.merge(file: file)).create
33
+ end
34
+
35
+ private
36
+
37
+ attr_reader :file, :space_id, :attributes
38
+
39
+ def prepare_to_upload
40
+ file_upload_path = [space_file_path, "prepare"].join("/")
41
+ Ribose::Request.get(file_upload_path, query: file_attributes)
42
+ end
43
+
44
+ def upload_to_aws_s3(meta)
45
+ aws_connection(meta.url).post do |request|
46
+ request.body = meta.fields.attrs.merge(file: faraday_file_io)
47
+ end
48
+ end
49
+
50
+ def notify_ribose_file_upload_endpoint(response, key)
51
+ if response.status.to_i == 200
52
+ Ribose::Request.post(space_file_path, file_attributes.merge(key: key))
53
+ end
54
+ end
55
+
56
+ def faraday_file_io
57
+ Faraday::UploadIO.new(file.path, file_attributes[:filetype])
58
+ end
59
+
60
+ def space_file_path
61
+ ["spaces", space_id, "file", "files"].join("/")
62
+ end
63
+
64
+ def file_content_type
65
+ @file_content_type ||= content_type_form_file
66
+ end
67
+
68
+ def content_type_form_file
69
+ require "mime/types"
70
+ MIME::Types.type_for(file.path).first.content_type
71
+ end
72
+
73
+ def file_attributes
74
+ @file_attributes ||= {
75
+ filesize: file.size,
76
+ filetype: file_content_type,
77
+ filename: File.basename(file),
78
+ file_info: {
79
+ tag_list: attributes[:tag_list] || "",
80
+ description: attributes[:description] || "",
81
+ },
82
+ }
83
+ end
84
+
85
+ def aws_connection(upload_url)
86
+ Faraday.new(upload_url) do |builder|
87
+ builder.request :multipart
88
+ builder.request :url_encoded
89
+ Ribose.configuration.add_default_middleware(builder)
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,41 @@
1
+ module Ribose
2
+ class JoinSpaceRequest < Ribose::Base
3
+ include Ribose::Actions::All
4
+ include Ribose::Actions::Create
5
+ include Ribose::Actions::Update
6
+
7
+ def self.accept(invitation_id, options = {})
8
+ new(resource_id: invitation_id, state: 1, **options).update
9
+ end
10
+
11
+ def self.reject(invitation_id, options = {})
12
+ new(resource_id: invitation_id, state: 2, **options).update
13
+ end
14
+
15
+ def self.update(invitation_id, attributes)
16
+ new(attributes.merge(resource_id: invitation_id)).update
17
+ end
18
+
19
+ private
20
+
21
+ def resource
22
+ "join_space_request"
23
+ end
24
+
25
+ def resource_key
26
+ "invitation"
27
+ end
28
+
29
+ def resources_path
30
+ "invitations/join_space_request"
31
+ end
32
+
33
+ def validate(space_id:, **attributes)
34
+ attributes.merge(space_id: space_id)
35
+ end
36
+
37
+ def extract_local_attributes
38
+ @invitation_id = attributes.delete(:invitation_id)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,19 @@
1
+ module Ribose
2
+ class Leaderboard < Ribose::Base
3
+ include Ribose::Actions::All
4
+
5
+ private
6
+
7
+ def resource
8
+ "leaderboard"
9
+ end
10
+
11
+ def resources
12
+ resource
13
+ end
14
+
15
+ def resources_path
16
+ "activity_point/leaderboard"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,34 @@
1
+ module Ribose
2
+ class Member < Ribose::Base
3
+ include Ribose::Actions::All
4
+
5
+ # List A Space Members
6
+ #
7
+ # This interface retrieves the list of members for any speicfic
8
+ # user spaces and then will return those as `Sawyer::Resource`
9
+ #
10
+ # @param space_id [String] The Space Id
11
+ # @param options [Hash] Query parameters as a Hash
12
+ # @return [Array<Sawyer::Resource>]
13
+ #
14
+ def self.all(space_id, options = {})
15
+ new(space_id: space_id, **options).all
16
+ end
17
+
18
+ private
19
+
20
+ attr_reader :space_id
21
+
22
+ def resource
23
+ "spaces_user"
24
+ end
25
+
26
+ def resources_path
27
+ ["spaces", space_id, "members"].join("/")
28
+ end
29
+
30
+ def extract_local_attributes
31
+ @space_id = attributes.delete(:space_id)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,94 @@
1
+ module Ribose
2
+ class Message
3
+ include Ribose::ResourceHelper
4
+
5
+ include Ribose::Actions::All
6
+ include Ribose::Actions::Create
7
+ include Ribose::Actions::Update
8
+ include Ribose::Actions::Delete
9
+
10
+ # Message initilaiztion
11
+ #
12
+ # @param space_id [String] The Space UUID
13
+ # @param conversation_id [String] The Conversation UUID
14
+ # @param attributes [Hash] The Message related attributes
15
+ # @return [Ribose::Message] The `Ribose::Message` Instance
16
+ #
17
+ def initialize(space_id, conversation_id, attributes = {})
18
+ @space_id = space_id
19
+ @attributes = attributes
20
+ @conversation_id = conversation_id
21
+ @message_id = attributes.delete(:message_id)
22
+ end
23
+
24
+ # Listing Conversation Messages
25
+ #
26
+ # @param space_id [String] The Space UUID
27
+ # @param conversation_id [String] The Conversation UUID
28
+ # @param options [Hash] The Query parameters as a Hash
29
+ # @return [Array<Sawyer::Resource>]
30
+ #
31
+ def self.all(space_id:, conversation_id:, **options)
32
+ new(space_id, conversation_id, **options).all
33
+ end
34
+
35
+ # Create A New Message
36
+ #
37
+ # @param space_id [String] The Space UUID
38
+ # @param conversation_id [String] The Conversation UUID
39
+ # @param attributes [Hash] The message attributes
40
+ # @return [Sawyer::Resource]
41
+ #
42
+ def self.create(space_id:, conversation_id:, **attributes)
43
+ new(space_id, conversation_id, attributes).create
44
+ end
45
+
46
+ # Update A Messsage
47
+ #
48
+ # @param space_id [String] The Space UUID
49
+ # @param message_id [String] The Message UUID
50
+ # @param conversation_id [String] The Conversation UUID
51
+ # @param attributes [Hash] The message attributes
52
+ # @return [Sawyer::Resource]
53
+ #
54
+ def self.update(space_id:, message_id:, conversation_id:, **attrs)
55
+ new(space_id, conversation_id, attrs.merge(message_id: message_id)).update
56
+ end
57
+
58
+ # Remove A Message
59
+ #
60
+ # @param space_id [String] The Space UUID
61
+ # @param message_id [String] The Message UUID
62
+ # @param conversation_id [String] The Conversation UUID
63
+ # @return [Sawyer::Resource]
64
+ #
65
+ def self.remove(space_id:, message_id:, conversation_id:, **options)
66
+ new(space_id, conversation_id, message_id: message_id, **options).delete
67
+ end
68
+
69
+ private
70
+
71
+ attr_reader :space_id, :conversation_id, :message_id, :attributes
72
+ alias_method :resource_id, :message_id
73
+
74
+ def resource
75
+ "message"
76
+ end
77
+
78
+ def custom_option
79
+ {}
80
+ end
81
+
82
+ def validate(attributes)
83
+ attributes.merge(conversation_id: conversation_id)
84
+ end
85
+
86
+ def resources_path
87
+ [conversations_path, conversation_id, "messages"].join("/")
88
+ end
89
+
90
+ def conversations_path
91
+ ["spaces", space_id, "conversation/conversations"].join("/")
92
+ end
93
+ end
94
+ end