coach_assist 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/coach_assist.gemspec +29 -0
- data/lib/coach/entity.rb +40 -0
- data/lib/coach/partnership.rb +23 -0
- data/lib/coach/subscription.rb +14 -0
- data/lib/coach/user.rb +67 -0
- data/lib/coach_assist/version.rb +3 -0
- data/lib/coach_assist.rb +10 -0
- metadata +145 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7d93c8b4d519afebc117cce60ff174c47775b94b
|
4
|
+
data.tar.gz: 8f5da22c34ee3866b07c2e78dea5dbfc651ee6af
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 40c24cedfe271cb717b1f8f1f338f3098dc1b6fd33d6201846da6a328b92f8972cb567cf5e3c35a6a81d9279cf2ef08b4735ed70355e410fc5ec642c72b93134
|
7
|
+
data.tar.gz: 1bd423e6502524df5a02eac7b6c4e982b8c60835f25d15a1ba093cc62c9071831598f2ce5e62f3c5829c98fc735809bfbbec52e3bf11188495cbffa2ac1c7c84
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Urs Gerber
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# CoachAssist
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/coach_assist`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'coach_assist'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install coach_assist
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/coach_assist.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "coach_assist"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
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
|
data/bin/setup
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'coach_assist/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "coach_assist"
|
8
|
+
spec.version = CoachAssist::VERSION
|
9
|
+
spec.authors = ["Urs Gerber"]
|
10
|
+
spec.email = ["ug.gerber@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Ruby gem to interface with the UniFR Cybercoach REST server}
|
13
|
+
#spec.description = %q{Write a longer description or delete this line.}
|
14
|
+
spec.homepage = "https://github.com/moose-secret-agents/coach_assist"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
|
26
|
+
spec.add_dependency 'httparty'
|
27
|
+
spec.add_dependency 'hashie'
|
28
|
+
spec.add_dependency 'activesupport'
|
29
|
+
end
|
data/lib/coach/entity.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module Coach
|
2
|
+
class Entity < Hashie::Trash
|
3
|
+
include Hashie::Extensions::IndifferentAccess
|
4
|
+
include HTTParty
|
5
|
+
|
6
|
+
property :uri
|
7
|
+
property :id
|
8
|
+
property :created_at, from: :datecreated
|
9
|
+
property :visibility, from: :publicvisible
|
10
|
+
|
11
|
+
headers 'Accept' => 'application/json'
|
12
|
+
base_uri 'http://diufvm31.unifr.ch:8090/CyberCoachServer/resources'
|
13
|
+
|
14
|
+
class << self
|
15
|
+
def authenticated(username, password, &block)
|
16
|
+
@auth = { username: username, password: password }
|
17
|
+
res = instance_eval &block
|
18
|
+
@auth = nil
|
19
|
+
res
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Fetch an entity based on its uri. Each entity containing a valid uri will be retrievable through this method
|
24
|
+
def fetch
|
25
|
+
return self if @fetched
|
26
|
+
raise 'Entity has not been loaded yet and does not have "uri" property' if self.uri.blank?
|
27
|
+
|
28
|
+
response = Entity.get clean_uri
|
29
|
+
update_attributes! JSON.parse(response.body)
|
30
|
+
|
31
|
+
@fetched = true
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
# Remove overlapping url parts
|
36
|
+
def clean_uri
|
37
|
+
self.uri.gsub('/CyberCoachServer/resources', '')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Coach
|
2
|
+
class Partnership < Coach::Entity
|
3
|
+
property :confirmed_by_user1, from: :userconfirmed1
|
4
|
+
property :confirmed_by_user2, from: :userconfirmed2
|
5
|
+
property :user1
|
6
|
+
property :user2
|
7
|
+
|
8
|
+
alias_method :old_user1, :user1
|
9
|
+
alias_method :old_user2, :user2
|
10
|
+
|
11
|
+
def user1
|
12
|
+
Coach::User.new(old_user1).fetch
|
13
|
+
end
|
14
|
+
|
15
|
+
def user2
|
16
|
+
Coach::User.new(old_user2).fetch
|
17
|
+
end
|
18
|
+
|
19
|
+
def users
|
20
|
+
[user1, user2]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/coach/user.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
module Coach
|
2
|
+
class User < Coach::Entity
|
3
|
+
|
4
|
+
property :username
|
5
|
+
property :password
|
6
|
+
property :real_name, from: :realname
|
7
|
+
property :email
|
8
|
+
property :partnerships
|
9
|
+
property :subscriptions
|
10
|
+
|
11
|
+
alias_method :old_partnerships, :partnerships
|
12
|
+
alias_method :old_subscriptions, :subscriptions
|
13
|
+
|
14
|
+
class << self
|
15
|
+
# Find all users on server. Pass :eager option to return results eagerly (slow)
|
16
|
+
# Pass :search option to only include users matching the search query
|
17
|
+
def all(options={})
|
18
|
+
eager, search = options.values_at(:eager, :search)
|
19
|
+
response = get '/users', query: { searchCriteria: search }
|
20
|
+
JSON.parse(response.body)['users'].map { |u| eager ? Coach::User.new(u).fetch : Coach::User.new(u) }
|
21
|
+
end
|
22
|
+
|
23
|
+
# Find user by username
|
24
|
+
def find(username)
|
25
|
+
response = get "/users/#{username}", basic_auth: @auth
|
26
|
+
response.code == 200 ? Coach::User.new(JSON.parse(response.body)) : nil
|
27
|
+
end
|
28
|
+
|
29
|
+
# Check whether user exists
|
30
|
+
def exists?(username)
|
31
|
+
!!find(username)
|
32
|
+
end
|
33
|
+
|
34
|
+
def authenticated?(username, password)
|
35
|
+
authenticated(username, password) do
|
36
|
+
response = get '/authenticateduser', basic_auth: @auth
|
37
|
+
response.code == 200 ? Coach::User.new(JSON.parse(response.body)) : nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Create new user
|
42
|
+
def create(username, attributes={})
|
43
|
+
response = put "/users/#{username}", body: attributes
|
44
|
+
response.code == 201 ? Coach::User.new(JSON.parse(response.body)) : nil
|
45
|
+
end
|
46
|
+
|
47
|
+
# Update user
|
48
|
+
def update(username, attributes={})
|
49
|
+
response = put "/users/#{username}", body: attributes, basic_auth: @auth
|
50
|
+
response.code == 200 ? Coach::User.new(JSON.parse(response.body)) : nil
|
51
|
+
end
|
52
|
+
|
53
|
+
# Delete user
|
54
|
+
def delete(username)
|
55
|
+
HTTParty::delete "/users/#{username}", basic_auth: @auth
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def partnerships
|
60
|
+
(old_partnerships || []).map { |p| Coach::Partnership.new(p).fetch }
|
61
|
+
end
|
62
|
+
|
63
|
+
def subscriptions
|
64
|
+
(old_subscriptions || []).map { |p| Coach::Subscription.new(p).fetch }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/coach_assist.rb
ADDED
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: coach_assist
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Urs Gerber
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: httparty
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: hashie
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: activesupport
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- ug.gerber@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".travis.yml"
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- bin/console
|
112
|
+
- bin/setup
|
113
|
+
- coach_assist.gemspec
|
114
|
+
- lib/coach/entity.rb
|
115
|
+
- lib/coach/partnership.rb
|
116
|
+
- lib/coach/subscription.rb
|
117
|
+
- lib/coach/user.rb
|
118
|
+
- lib/coach_assist.rb
|
119
|
+
- lib/coach_assist/version.rb
|
120
|
+
homepage: https://github.com/moose-secret-agents/coach_assist
|
121
|
+
licenses:
|
122
|
+
- MIT
|
123
|
+
metadata: {}
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
requirements: []
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 2.4.8
|
141
|
+
signing_key:
|
142
|
+
specification_version: 4
|
143
|
+
summary: Ruby gem to interface with the UniFR Cybercoach REST server
|
144
|
+
test_files: []
|
145
|
+
has_rdoc:
|