ribose 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
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/bin/console CHANGED
@@ -7,8 +7,5 @@ require "ribose"
7
7
  # with your gem easier. You can also use a different console, if you like.
8
8
 
9
9
  # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
10
+ require "pry"
11
+ Pry.start
data/lib/ribose.rb CHANGED
@@ -1,5 +1,35 @@
1
+ require "faraday"
2
+ require "sawyer"
3
+
1
4
  require "ribose/version"
5
+ require "ribose/base"
6
+ require "ribose/config"
7
+ require "ribose/client"
8
+ require "ribose/request"
9
+ require "ribose/setting"
10
+ require "ribose/space"
11
+ require "ribose/app_data"
12
+ require "ribose/app_relation"
13
+ require "ribose/feed"
14
+ require "ribose/widget"
15
+ require "ribose/stream"
16
+ require "ribose/leaderboard"
17
+ require "ribose/connection"
18
+ require "ribose/calendar"
19
+ require "ribose/member"
20
+ require "ribose/space_file"
21
+ require "ribose/conversation"
22
+ require "ribose/message"
23
+ require "ribose/space_invitation"
24
+ require "ribose/join_space_request"
25
+ require "ribose/connection_invitation"
26
+ require "ribose/user"
27
+ require "ribose/session"
28
+ require "ribose/profile"
29
+ require "ribose/wiki"
2
30
 
3
31
  module Ribose
4
- # Your code goes here...
32
+ def self.root
33
+ File.dirname(__dir__)
34
+ end
5
35
  end
@@ -0,0 +1,10 @@
1
+ require "ribose/actions/all"
2
+ require "ribose/actions/fetch"
3
+ require "ribose/actions/create"
4
+ require "ribose/actions/update"
5
+ require "ribose/actions/delete"
6
+
7
+ module Ribose
8
+ module Actions
9
+ end
10
+ end
@@ -0,0 +1,43 @@
1
+ require "ribose/actions/base"
2
+
3
+ module Ribose
4
+ module Actions
5
+ module All
6
+ extend Ribose::Actions::Base
7
+ # List Resources
8
+ #
9
+ # Retrieve the list of resources via :get and then extract the
10
+ # the root element from the response object.
11
+ #
12
+ # @return [Array <Sawyer::Resource>]
13
+ #
14
+ def all
15
+ response = Ribose::Request.get(resources_path, custom_option)
16
+ extract_root(response) || response
17
+ end
18
+
19
+ private
20
+
21
+ def extract_root(response)
22
+ unless resources.nil?
23
+ response[resources]
24
+ end
25
+ end
26
+
27
+ module ClassMethods
28
+ # List Resources
29
+ #
30
+ # This exposes the instance method as class methods, and once
31
+ # invoked then it instantiate a new instance & invokes the all
32
+ # instance method with the provided parameters.
33
+ #
34
+ # @param options [Hash] Query parameters as Hash
35
+ # @return [Array <Sawyer::Resource>]
36
+ #
37
+ def all(options = {})
38
+ new(options).all
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,11 @@
1
+ require "ribose/request"
2
+
3
+ module Ribose
4
+ module Actions
5
+ module Base
6
+ def included(base)
7
+ base.extend(const_get(:ClassMethods))
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,44 @@
1
+ require "ribose/actions/base"
2
+
3
+ module Ribose
4
+ module Actions
5
+ module Create
6
+ extend Ribose::Actions::Base
7
+
8
+ def create
9
+ create_resource[resource]
10
+ end
11
+
12
+ private
13
+
14
+ # Attribute validations
15
+ #
16
+ # This method will be invoked by the create action to validate the
17
+ # attributes before submitting to the actual endpoint. We can override
18
+ # this one to validate user provider attributes.
19
+ #
20
+ def validate(attributes)
21
+ attributes
22
+ end
23
+
24
+ def request_body(attributes)
25
+ custom_option.merge(resource_key.to_sym => validate(attributes))
26
+ end
27
+
28
+ def create_resource
29
+ Ribose::Request.post(resources_path, request_body(attributes))
30
+ end
31
+
32
+ module ClassMethods
33
+ # Create resource
34
+ #
35
+ # @param attributes [Hash] Resoruce attributes
36
+ # @return [Sawyer::Resource] Newly created resource
37
+ #
38
+ def create(attributes)
39
+ new(attributes).create
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,32 @@
1
+ require "ribose/actions/base"
2
+
3
+ module Ribose
4
+ module Actions
5
+ module Delete
6
+ extend Ribose::Actions::Base
7
+
8
+ def delete
9
+ Ribose::Request.delete(resource_path, custom_option)
10
+ end
11
+
12
+ module ClassMethods
13
+ # Delete a resource
14
+ #
15
+ # @param resource_id [String] Resource UUID
16
+ # @param options [Hash] Query parameters as Hash
17
+ #
18
+ def delete(resource_id, options = {})
19
+ new(resource_id: resource_id, **options).delete
20
+ end
21
+
22
+ # Aliases for delete
23
+ #
24
+ # There is another variation `cancel` that we have been using in
25
+ # some resources inter exchangbly, so let's keep that legacy support
26
+ # for now and we can decide about those in the future.
27
+ #
28
+ alias_method :cancel, :delete
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,44 @@
1
+ require "ribose/actions/base"
2
+
3
+ module Ribose
4
+ module Actions
5
+ module Fetch
6
+ extend Ribose::Actions::Base
7
+
8
+ # Fetch A Resource
9
+ #
10
+ # Retrieve the details for a specific resource via HTTP GET
11
+ # and retrurns those as `Sawyer::Resource`.
12
+ #
13
+ # @return [Sawyer::Resource]
14
+ #
15
+ def fetch
16
+ response = Request.get(resource_path, custom_option)
17
+ extract_resource(response) || response
18
+ end
19
+
20
+ private
21
+
22
+ def extract_resource(response)
23
+ unless resource.nil?
24
+ response[resource.to_s]
25
+ end
26
+ end
27
+
28
+ module ClassMethods
29
+ # Fetch A Resource
30
+ #
31
+ # This exposes the `#fetch` instance method as class methods. Once
32
+ # this methods is invoked then it will create an instnace with all
33
+ # of the provided attributes & then invoke the `fetch` action on it
34
+ #
35
+ # @param resource_id [String] The specific resource Id
36
+ # @return [Sawyer::Resource]
37
+ #
38
+ def fetch(resource_id, options = {})
39
+ new(options.merge(resource_id: resource_id)).fetch
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,35 @@
1
+ require "ribose/actions/base"
2
+
3
+ module Ribose
4
+ module Actions
5
+ module Update
6
+ extend Ribose::Actions::Base
7
+
8
+ # Update a resource
9
+ #
10
+ # @return [Sawyer::Resource] Update resource response
11
+ def update
12
+ update_resource[resource]
13
+ end
14
+
15
+ private
16
+
17
+ def update_resource
18
+ Ribose::Request.put(
19
+ resource_path, custom_option.merge(resource_key.to_sym => attributes)
20
+ )
21
+ end
22
+
23
+ module ClassMethods
24
+ # Update a resource
25
+ #
26
+ # @param resource_id [String] The Resource UUID
27
+ # @param attributes [Hash] New attributes as Hash
28
+ # @return [Sawyer::Resource] The Updated Resource
29
+ def update(resource_id, attributes = {})
30
+ new(attributes.merge(resource_id: resource_id)).update
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,15 @@
1
+ module Ribose
2
+ class AppData < Ribose::Base
3
+ include Ribose::Actions::All
4
+
5
+ private
6
+
7
+ def resource
8
+ "app_data"
9
+ end
10
+
11
+ def resources
12
+ resource
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ module Ribose
2
+ class AppRelation < Ribose::Base
3
+ include Ribose::Actions::All
4
+ include Ribose::Actions::Fetch
5
+
6
+ private
7
+
8
+ def resource
9
+ "app_relation"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,48 @@
1
+ require "ribose/resource_helper"
2
+
3
+ module Ribose
4
+ class Base
5
+ include Ribose::ResourceHelper
6
+
7
+ def initialize(attributes = {})
8
+ @attributes = attributes
9
+ extract_base_attributes
10
+ extract_local_attributes
11
+ end
12
+
13
+ private
14
+
15
+ attr_reader :resource_id, :attributes, :client, :query
16
+
17
+ # User provided options
18
+ #
19
+ # Some of the API endpoints has support for custom options,
20
+ # for example sending a request as different client, pass
21
+ # some query parameters and etc, and that's where this will
22
+ # come in handy.
23
+ #
24
+ def custom_option
25
+ { client: client, query: query }
26
+ end
27
+
28
+ # Extract Local Attributes
29
+ #
30
+ # This hook method let us extract sub-class specific attributes
31
+ # And the way to do it is pretty simple, we only need to override
32
+ # this method and extract the keys from the attributes hash. For
33
+ # exmaple if `attributes` contains a has key `space_id` and we
34
+ # want to extract it to a sub-class then we can do it as follow
35
+ #
36
+ # def extract_local_attributes
37
+ # @space_id = attributes.delete(:space_id)
38
+ # end
39
+ #
40
+ def extract_local_attributes; end
41
+
42
+ def extract_base_attributes
43
+ @query = attributes.delete(:query)
44
+ @client = attributes.delete(:client)
45
+ @resource_id = attributes.delete(:resource_id)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,22 @@
1
+ module Ribose
2
+ class Calendar < Ribose::Base
3
+ include Ribose::Actions::All
4
+ include Ribose::Actions::Fetch
5
+ include Ribose::Actions::Create
6
+ include Ribose::Actions::Delete
7
+
8
+ private
9
+
10
+ def resource
11
+ "calendar"
12
+ end
13
+
14
+ def resources_path
15
+ "calendar/calendar"
16
+ end
17
+
18
+ def validate(name:, **attributes)
19
+ attributes.merge(name: name)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,31 @@
1
+ module Ribose
2
+ class Client
3
+ attr_reader :api_token, :user_email
4
+
5
+ def initialize(options = {})
6
+ @api_token = options.fetch(:token, configuration.api_token).to_s
7
+ @user_email = options.fetch(:email, configuration.user_email).to_s
8
+ end
9
+
10
+ # Initiate a ribose client
11
+ #
12
+ # This interface takes email and password and then it will
13
+ # do all the underlying work to find out the authentication
14
+ # token and retrun a ribose client.
15
+ #
16
+ # @param :email [String] The email for your Ribose account
17
+ # @param :password [String] The password for your account
18
+ # @return [Ribose::Client] A new client with your details
19
+ #
20
+ def self.from_login(email:, password:)
21
+ session = Session.create(username: email, password: password)
22
+ new(email: email, token: session["authentication_token"])
23
+ end
24
+
25
+ private
26
+
27
+ def configuration
28
+ Ribose.configuration
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,21 @@
1
+ require "ribose/configuration"
2
+
3
+ module Ribose
4
+ module Config
5
+ def configure
6
+ if block_given?
7
+ yield configuration
8
+ end
9
+ end
10
+
11
+ def configuration
12
+ @configuration ||= Configuration.new
13
+ end
14
+ end
15
+
16
+ # This following line exposes `Ribose::Config` moduel's methods in class
17
+ # scope, so we can easily use those to configure or access Ribose config
18
+ # throughout the gem and the client applications.
19
+ #
20
+ extend Config
21
+ end
@@ -0,0 +1,25 @@
1
+ require "ribose/response/raise_error"
2
+
3
+ module Ribose
4
+ class Configuration
5
+ attr_accessor :api_host, :api_token, :user_email, :debug_mode
6
+
7
+ def initialize
8
+ @debug_mode = false
9
+ @api_host ||= "www.ribose.com"
10
+ end
11
+
12
+ def debug_mode?
13
+ debug_mode == true
14
+ end
15
+
16
+ def web_url
17
+ ["https", api_host].join("://")
18
+ end
19
+ def add_default_middleware(builder)
20
+ builder.use(Ribose::Response::RaiseError)
21
+ builder.response(:logger, nil, bodies: true) if debug_mode?
22
+ builder.adapter(Faraday.default_adapter)
23
+ end
24
+ end
25
+ end