Coach4rb
Coach4rb is a quick and dirty client solution for the Cyber Coach Webservice @unifr.ch.
For more details see.
Principles:
-
This client mainly focuses on verbs (create/delete/update etc.) and tries to avoid the bad nouns.
-
Another principle is that each returned object can be used again as input for another request and that all resources are retrievable / updatable / deletable by their corresponding cyber coach uri.
-
A retrieved coach user object can be reused for retrieving its subscriptions etc.
-
A coach client can be encapsulated behind a proxy object to provide access on protected resources in the scope of a user.
Some examples
Example: Retrieving a user: ruby @coach_user = @coach.user_by_uri
'/CyberCoachServer/resources/users/arueedlinger' # get a user by
its uri @coach_user = @coach.user 'arueedlinger' # get a user
Example: Encapsulating a coach client behind a proxy
@proxy = Coach4rb::Proxy::Access.new 'arueedlinger', 'muha', @coach #@coach is our coach client
Example: Updating a user: “`ruby @uri = '/CyberCoachServer/resources/users/arueedlinger' @proxy.update_user(@uri) do |user| user.real_name = 'Alex Rueedlinger' end
@user = @coach.user 'arueedlinger' # get a user @proxy.update_user(@user) do |user| user.real_name = 'Alex Rueedlinger' end
## Installation
Add this line to your application's Gemfile:
ruby gem 'coach4rb' “`
And then execute:
$ bundle
Or install it yourself as:
$ gem install coach4rb
Usage
For testing the examples on this page open a terminal and run the ruby
shell: irb
Now, require the gem 'coach4rb'
require 'coach4rb'
Documentation
For a better understanding how the client works see the code examples in
the file: lib/coach4rb/coach.rb
and have a look at the tests with
prefix test_coach_X
.
Configuration
Coach4rb can be easily configured as the following example shows:
@coach = Coach4rb.configure(
scheme: 'http',
host: 'diufvm31.unifr.ch',
port: 8090,
path: '/CyberCoachServer/resources'
)
Without the debug options all coach4rb exceptions are catched. By adding the option debug: true all exceptions are 'ducked' to the caller.
@coach = Coach4rb.configure(
scheme: 'http',
host: 'diufvm31.unifr.ch',
port: 8090,
path: '/CyberCoachServer/resources',
debug: true
)
To be sure that Coach4rb is correctly configured the method
valid?
can be executed for testing purposes.
@coach.available? # => true | false
Contributing
-
Fork it ( github.com/[my-github-username]/coach4rb/fork )
-
Create your feature branch (
git checkout -b my-new-feature
) -
Commit your changes (
git commit -am 'Add some feature'
) -
Push to the branch (
git push origin my-new-feature
) -
Create a new Pull Request