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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +539 -970
- data/.sample.pryrc +4 -0
- data/CHANGELOG.md +5 -0
- data/README.md +539 -3
- data/bin/console +2 -5
- data/lib/ribose.rb +31 -1
- data/lib/ribose/actions.rb +10 -0
- data/lib/ribose/actions/all.rb +43 -0
- data/lib/ribose/actions/base.rb +11 -0
- data/lib/ribose/actions/create.rb +44 -0
- data/lib/ribose/actions/delete.rb +32 -0
- data/lib/ribose/actions/fetch.rb +44 -0
- data/lib/ribose/actions/update.rb +35 -0
- data/lib/ribose/app_data.rb +15 -0
- data/lib/ribose/app_relation.rb +12 -0
- data/lib/ribose/base.rb +48 -0
- data/lib/ribose/calendar.rb +22 -0
- data/lib/ribose/client.rb +31 -0
- data/lib/ribose/config.rb +21 -0
- data/lib/ribose/configuration.rb +25 -0
- data/lib/ribose/connection.rb +39 -0
- data/lib/ribose/connection_invitation.rb +51 -0
- data/lib/ribose/conversation.rb +87 -0
- data/lib/ribose/error.rb +30 -0
- data/lib/ribose/feed.rb +11 -0
- data/lib/ribose/file_uploader.rb +93 -0
- data/lib/ribose/join_space_request.rb +41 -0
- data/lib/ribose/leaderboard.rb +19 -0
- data/lib/ribose/member.rb +34 -0
- data/lib/ribose/message.rb +94 -0
- data/lib/ribose/profile.rb +56 -0
- data/lib/ribose/request.rb +122 -0
- data/lib/ribose/resource_helper.rb +81 -0
- data/lib/ribose/response/raise_error.rb +15 -0
- data/lib/ribose/rspec.rb +19 -0
- data/lib/ribose/session.rb +48 -0
- data/lib/ribose/setting.rb +16 -0
- data/lib/ribose/space.rb +30 -0
- data/lib/ribose/space_file.rb +49 -0
- data/lib/ribose/space_invitation.rb +70 -0
- data/lib/ribose/stream.rb +15 -0
- data/lib/ribose/user.rb +42 -0
- data/lib/ribose/version.rb +1 -1
- data/lib/ribose/widget.rb +11 -0
- data/lib/ribose/wiki.rb +80 -0
- data/ribose.gemspec +6 -0
- data/spec/fixtures/app_data.json +188 -0
- data/spec/fixtures/app_relation.json +19 -0
- data/spec/fixtures/app_relations.json +89 -0
- data/spec/fixtures/calendar.json +12 -0
- data/spec/fixtures/calendars.json +34 -0
- data/spec/fixtures/connection_invitation.json +26 -0
- data/spec/fixtures/connection_invitation_accepted.json +26 -0
- data/spec/fixtures/connection_invitations.json +28 -0
- data/spec/fixtures/connection_invitations_created.json +37 -0
- data/spec/fixtures/connection_suggestion.json +22 -0
- data/spec/fixtures/connections.json +28 -0
- data/spec/fixtures/conversation.json +26 -0
- data/spec/fixtures/conversation_created.json +31 -0
- data/spec/fixtures/conversations.json +34 -0
- data/spec/fixtures/empty.json +1 -0
- data/spec/fixtures/feeds.json +84 -0
- data/spec/fixtures/file_upload_prepared.json +17 -0
- data/spec/fixtures/file_uploaded.json +38 -0
- data/spec/fixtures/general_information.json +16 -0
- data/spec/fixtures/join_space_request_created.json +26 -0
- data/spec/fixtures/join_space_request_updated.json +25 -0
- data/spec/fixtures/join_space_requests.json +34 -0
- data/spec/fixtures/leaderboard.json +21 -0
- data/spec/fixtures/login.html +323 -0
- data/spec/fixtures/members.json +20 -0
- data/spec/fixtures/message.json +22 -0
- data/spec/fixtures/messages.json +24 -0
- data/spec/fixtures/ping.json +3 -0
- data/spec/fixtures/profile.json +10 -0
- data/spec/fixtures/sample.png +0 -0
- data/spec/fixtures/setting.json +16 -0
- data/spec/fixtures/settings.json +18 -0
- data/spec/fixtures/space.json +59 -0
- data/spec/fixtures/space_created.json +59 -0
- data/spec/fixtures/space_file.json +58 -0
- data/spec/fixtures/space_invitation.json +32 -0
- data/spec/fixtures/space_invitation_updated.json +35 -0
- data/spec/fixtures/space_invitations.json +34 -0
- data/spec/fixtures/space_mass_invitations.json +46 -0
- data/spec/fixtures/spaces.json +61 -0
- data/spec/fixtures/stream.json +176 -0
- data/spec/fixtures/user_activated.json +6 -0
- data/spec/fixtures/widgets.json +50 -0
- data/spec/fixtures/wiki.json +79 -0
- data/spec/fixtures/wikis.json +197 -0
- data/spec/ribose/actions/create_spec.rb +40 -0
- data/spec/ribose/actions/delete_spec.rb +24 -0
- data/spec/ribose/actions/fetch_spec.rb +32 -0
- data/spec/ribose/actions/update_spec.rb +36 -0
- data/spec/ribose/app_data_spec.rb +15 -0
- data/spec/ribose/app_relation_spec.rb +27 -0
- data/spec/ribose/calendar_spec.rb +50 -0
- data/spec/ribose/client_spec.rb +48 -0
- data/spec/ribose/config_spec.rb +41 -0
- data/spec/ribose/connection_invitation_spec.rb +79 -0
- data/spec/ribose/connection_spec.rb +26 -0
- data/spec/ribose/conversation_spec.rb +84 -0
- data/spec/ribose/error_spec.rb +67 -0
- data/spec/ribose/feed_spec.rb +14 -0
- data/spec/ribose/file_uploader_spec.rb +30 -0
- data/spec/ribose/join_space_request_spec.rb +70 -0
- data/spec/ribose/leaderboard_spec.rb +13 -0
- data/spec/ribose/member_spec.rb +16 -0
- data/spec/ribose/message_spec.rb +69 -0
- data/spec/ribose/profile_spec.rb +40 -0
- data/spec/ribose/request_spec.rb +66 -0
- data/spec/ribose/resource_helper_spec.rb +58 -0
- data/spec/ribose/session_spec.rb +46 -0
- data/spec/ribose/setting_spec.rb +40 -0
- data/spec/ribose/space_file_spec.rb +41 -0
- data/spec/ribose/space_invitation_spec.rb +117 -0
- data/spec/ribose/space_spec.rb +70 -0
- data/spec/ribose/stream_spec.rb +14 -0
- data/spec/ribose/user_spec.rb +48 -0
- data/spec/ribose/widget_spec.rb +14 -0
- data/spec/ribose/wiki_spec.rb +67 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/support/fake_ribose_api.rb +431 -0
- data/spec/support/file_upload_stub.rb +76 -0
- metadata +190 -3
- 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
|
-
|
|
11
|
-
|
|
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
|
-
|
|
32
|
+
def self.root
|
|
33
|
+
File.dirname(__dir__)
|
|
34
|
+
end
|
|
5
35
|
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,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
|
data/lib/ribose/base.rb
ADDED
|
@@ -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
|