one45 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 16dc956d8f62c8d9d3e2f891d57b92c9a74a9bb2
4
+ data.tar.gz: cd6ce58c8b2faca3a4ba250a9a219d4ba1e06f46
5
+ SHA512:
6
+ metadata.gz: e13dd53ac33f7c098fa29230195184c613d4d53042ee5b4ca8864da1f05089c1a37c540ec30a26f0c1162f1effdb02d9aa0456ebc196babfa0cbcc6de08d9acd
7
+ data.tar.gz: 742d0d3585d0df43c780920e2fa628f8fda980564419e6b3b9eb3e6e4b5a6ab391f61723367f59f42c0a7760102c1fc9c82c044df2e75bfdcb4bee9120e21765
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ TODO.md
11
+ *.gem
12
+ test/cassettes/*
13
+ test/config/application.rb
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in one45.gemspec
4
+ gemspec
@@ -0,0 +1,73 @@
1
+ # One45
2
+
3
+ Ruby bindings for the [one45 API](https://api.one45.com/api/docs/all).
4
+
5
+ Under development since most endpoints remain listed as Early Access/In Development.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'one45'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install one45
22
+
23
+ ## Usage
24
+
25
+ Add your school credentials. In a Rails application create a new initializer `config/initializers/one45.rb`
26
+
27
+ ```
28
+ One45.api_host = ENV['ONE45_API_HOST']
29
+ One45.client_key = ENV['ONE45_CLIENT_KEY']
30
+ One45.client_secret = ENV['ONE45_CLIENT_SECRET']
31
+ One45.access_token = ENV['ONE45_ACCESS_TOKEN'] # optional
32
+ ```
33
+
34
+ A request for a new token will be made prior to each call if no access token provided (which is slowing response).
35
+ In future, an alternate solution would be to implement OAuth2 strategy.
36
+
37
+ Retrieve collection
38
+
39
+ ```
40
+ One45::Evaluations.list(
41
+ target_id: 111,
42
+ target_role_id: 3,
43
+ evaluator_role_id: 2,
44
+ completed_on: "2015-01-01|2015-12-31",
45
+ event_category: "rotation",
46
+ limit: 100
47
+ )
48
+ ```
49
+
50
+ Fetch specific record by One45 ID
51
+
52
+ ```
53
+ One45::Questions.find(504)
54
+ ```
55
+
56
+ __Current limits__
57
+
58
+ - Only GET methods so far (POST, DELETE, PATCH, PUT are excluded at the moment)
59
+ - Only token#generate is implemented
60
+
61
+ For complete list of implementation please refer to test file.
62
+
63
+ ## Development
64
+
65
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
66
+
67
+ You need to set up credentials to run the tests. Clone and rename `application.sample.rb` under `test/config`.
68
+
69
+ 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).
70
+
71
+ ## Contributing
72
+
73
+ Bug reports and pull requests are welcome on GitHub at https://github.com/uOttawaMedtech/one45-ruby.
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "one45"
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
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,99 @@
1
+ require "one45/version"
2
+
3
+ # Dependencies
4
+ require "restclient"
5
+
6
+ # Common
7
+ require "one45/base"
8
+
9
+ # API resources
10
+ require "one45/evaluations"
11
+ require "one45/forms"
12
+ require "one45/groups"
13
+ require "one45/questions"
14
+ require "one45/rotations"
15
+ require "one45/users"
16
+
17
+ # Errors
18
+ require "one45/errors/one45_error"
19
+
20
+
21
+ module One45
22
+ VERBS = %w(get post put)
23
+
24
+ class << self
25
+ attr_accessor :api_host, :client_key, :client_secret, :access_token
26
+
27
+ def generate_token(client_key, client_secret)
28
+ params = { params: { client_key: client_key, client_secret: client_secret} }
29
+ begin
30
+ response = RestClient.get(token_url, params)
31
+ @access_token = JSON.parse(response)['access_token']
32
+ # puts "generated access_token: #{@access_token}"
33
+ @access_token
34
+ rescue => e
35
+ One45Error.new("error: #{e.class} : #{e.response} : #{e.response}")
36
+ end
37
+ end
38
+
39
+ def api_url
40
+ "https://#{One45.api_host}/web/one45_stage.php/api/v1"
41
+ end
42
+
43
+ def token_url
44
+ "https://#{One45.api_host}/web/one45_stage.php/api/token/generate"
45
+ end
46
+
47
+ VERBS.each do |verb|
48
+ define_method verb do |path, *params|
49
+ send_request(verb, path, *params)
50
+ end
51
+ end
52
+
53
+ private
54
+
55
+ def validate_configuration
56
+ [@api_host, @client_key, @client_secret].each do |config|
57
+ raise One45Error.new("api_host, client_key or client_secret not set") if config.nil?
58
+ end
59
+ end
60
+
61
+ def send_request(verb, path, options = {})
62
+ validate_configuration
63
+
64
+ url = path.start_with?('http') ? path : api_url + "/#{path}"
65
+
66
+ url = URI::encode(url)
67
+
68
+ params = format_body_params(options, @access_token) if @access_token
69
+
70
+ begin
71
+ response = RestClient.send(verb, url, params)
72
+ rescue RestClient::Unauthorized
73
+ # token may be expired or nil
74
+ # submit request again with a fresh token
75
+ @access_token = generate_token(@client_key, @client_secret)
76
+ params = format_body_params(options, @access_token)
77
+ response = RestClient.send(verb, url, params)
78
+ rescue => e
79
+ One45Error.new("error: #{e.class} : #{e.response} : #{e.response}")
80
+ end
81
+
82
+ JSON.parse response if response && response.length >= 2
83
+ # http://stackoverflow.com/questions/8390256/a-json-text-must-at-least-contain-two-octets
84
+ end
85
+
86
+ def format_body_params(options, access_token)
87
+ # insert access_token in the original hash
88
+ token_hash = { access_token: access_token }
89
+ options.merge! token_hash
90
+ # nest options under the key 'params'
91
+ params = { params: options }
92
+ end
93
+
94
+ def default_headers
95
+ { 'Content-Type' => "application/json",
96
+ 'Accept' => "application/json" }
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,14 @@
1
+ module One45
2
+ class Base
3
+
4
+ def self.list(options = {})
5
+ One45.get resource_url, options
6
+ end
7
+
8
+ def self.find(id)
9
+ url = "#{resource_url}/#{id}"
10
+ One45.get url
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,20 @@
1
+ module One45
2
+ class One45Error < StandardError
3
+ attr_reader :message
4
+ attr_reader :http_status
5
+ attr_reader :http_body
6
+ attr_reader :json_body
7
+
8
+ def initialize(message=nil, http_status=nil, http_body=nil, json_body=nil)
9
+ @message = message
10
+ @http_status = http_status
11
+ @http_body = http_body
12
+ @json_body = json_body
13
+ end
14
+
15
+ def to_s
16
+ status_string = @http_status.nil? ? "" : "(Status #{@http_status}) "
17
+ "#{status_string}#{@message}"
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,26 @@
1
+ module One45
2
+ class Evaluations < Base
3
+
4
+ def self.answers(id)
5
+ url = "#{resource_url}/#{id}/answers"
6
+ One45.get url
7
+ end
8
+
9
+ def self.contributors(id)
10
+ url = "#{resource_url}/#{id}/contributors"
11
+ One45.get url
12
+ end
13
+
14
+ def self.question_answers(id, question_id)
15
+ url = "#{resource_url}/#{id}/question/#{question_id}/answer"
16
+ One45.get url
17
+ end
18
+
19
+ private
20
+
21
+ def self.resource_url
22
+ "evaluations"
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,21 @@
1
+ module One45
2
+ class Forms < Base
3
+
4
+ def self.groups(id)
5
+ url = "#{resource_url}/#{id}/groups"
6
+ One45.get url
7
+ end
8
+
9
+ def self.questions(id)
10
+ url = "#{resource_url}/#{id}/questions"
11
+ One45.get url
12
+ end
13
+
14
+ private
15
+
16
+ def self.resource_url
17
+ "forms"
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,16 @@
1
+ module One45
2
+ class Groups < Base
3
+
4
+ def self.subgroups(id)
5
+ url = "#{resource_url}/#{id}/children"
6
+ One45.get url
7
+ end
8
+
9
+ private
10
+
11
+ def self.resource_url
12
+ "groups"
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ module One45
2
+ class Questions < Base
3
+
4
+ private
5
+
6
+ def self.resource_url
7
+ "questions"
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module One45
2
+ class Rotations < Base
3
+
4
+ private
5
+
6
+ def self.resource_url
7
+ "rotations"
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ module One45
2
+ class Users < Base
3
+
4
+ def self.preferences(id)
5
+ url = "#{resource_url}/#{id}/preferences"
6
+ One45.get url
7
+ end
8
+
9
+ def self.todos(id, options = {})
10
+ url = "#{resource_url}/#{id}/todos"
11
+ One45.get url
12
+ end
13
+
14
+ def self.evaluations(id, options = {})
15
+ url = "#{resource_url}/#{id}/todos/evaluations"
16
+ One45.get url
17
+ end
18
+
19
+ private
20
+
21
+ def self.resource_url
22
+ "people"
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module One45
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'one45/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "one45"
8
+ spec.version = One45::VERSION
9
+ spec.authors = ["Olivier"]
10
+ spec.email = ["osimart@uottawa.ca", "olivier@yafoy.com"]
11
+
12
+ spec.summary = "Ruby bindings for the one45 API"
13
+ spec.description = "Interact with one45 key endpoints"
14
+ spec.homepage = "https://github.com/uOttawaMedtech/one45-ruby"
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_dependency 'rest-client', '~> 1.7'
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.10"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+
27
+ # TESTS
28
+ spec.add_development_dependency "minitest", "~> 5.0"
29
+ spec.add_development_dependency "minitest-reporters", "~> 1.0"
30
+ spec.add_development_dependency "vcr", "~> 3.0"
31
+ spec.add_development_dependency "webmock", "~> 1.22"
32
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: one45
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Olivier
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-01-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest-reporters
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.22'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.22'
111
+ description: Interact with one45 key endpoints
112
+ email:
113
+ - osimart@uottawa.ca
114
+ - olivier@yafoy.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".travis.yml"
121
+ - Gemfile
122
+ - README.md
123
+ - Rakefile
124
+ - bin/console
125
+ - bin/setup
126
+ - lib/one45.rb
127
+ - lib/one45/base.rb
128
+ - lib/one45/errors/one45_error.rb
129
+ - lib/one45/evaluations.rb
130
+ - lib/one45/forms.rb
131
+ - lib/one45/groups.rb
132
+ - lib/one45/questions.rb
133
+ - lib/one45/rotations.rb
134
+ - lib/one45/users.rb
135
+ - lib/one45/version.rb
136
+ - one45.gemspec
137
+ homepage: https://github.com/uOttawaMedtech/one45-ruby
138
+ licenses:
139
+ - MIT
140
+ metadata: {}
141
+ post_install_message:
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubyforge_project:
157
+ rubygems_version: 2.4.3
158
+ signing_key:
159
+ specification_version: 4
160
+ summary: Ruby bindings for the one45 API
161
+ test_files: []