progresso 0.1.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 +7 -0
- data/.gitignore +8 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +35 -0
- data/README.md +36 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/progresso.rb +5 -0
- data/lib/progresso/client.rb +141 -0
- data/lib/progresso/errors.rb +4 -0
- data/lib/progresso/token.rb +16 -0
- data/lib/progresso/version.rb +3 -0
- data/progresso.gemspec +27 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b042d6f7ebb1625c8d007a75f9596cda09da0529
|
4
|
+
data.tar.gz: 136fc38ba249c4055c432acc377780dd2dd03e66
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c6941986f342d9c5df046fe6d122e3c1c77f58dcea11e74271759cc6e0a282f1c26c7a855c76716fa126d1b885e0ca3ac3f47416f6ae1dce02964d6be2020da5
|
7
|
+
data.tar.gz: f314473f9cc23454b9acce1eeea4835b41423e4f954b2e65f1099dfaf282f1dda2b4ce4a7116808ec6728d8c6f5289814af5b56dd3be6df313990bf9ddf7258d
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
progresso (0.1.0)
|
5
|
+
activesupport (>= 4)
|
6
|
+
excon (>= 0.45)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activesupport (5.2.0)
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
+
i18n (>= 0.7, < 2)
|
14
|
+
minitest (~> 5.1)
|
15
|
+
tzinfo (~> 1.1)
|
16
|
+
concurrent-ruby (1.0.5)
|
17
|
+
excon (0.62.0)
|
18
|
+
i18n (1.0.1)
|
19
|
+
concurrent-ruby (~> 1.0)
|
20
|
+
minitest (5.11.3)
|
21
|
+
rake (10.5.0)
|
22
|
+
thread_safe (0.3.6)
|
23
|
+
tzinfo (1.2.5)
|
24
|
+
thread_safe (~> 0.1)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
ruby
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
bundler (~> 1.16.a)
|
31
|
+
progresso!
|
32
|
+
rake (~> 10.0)
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
1.16.1
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Progresso
|
2
|
+
|
3
|
+
Progresso API client
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'progresso'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install progresso
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
client = Progresso::Client.new(subdomain, username, password)
|
24
|
+
client.learners.each do |student|
|
25
|
+
puts "#{student.forename} #{student.surname}"
|
26
|
+
end
|
27
|
+
|
28
|
+
## Development
|
29
|
+
|
30
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
31
|
+
|
32
|
+
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).
|
33
|
+
|
34
|
+
## Contributing
|
35
|
+
|
36
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/progresso.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "progresso"
|
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(__FILE__)
|
data/bin/setup
ADDED
data/lib/progresso.rb
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
require "excon"
|
2
|
+
require "json"
|
3
|
+
require "progresso/token"
|
4
|
+
require "progresso/errors"
|
5
|
+
require "active_support/core_ext/string"
|
6
|
+
|
7
|
+
module Progresso
|
8
|
+
class Client
|
9
|
+
def initialize(subdomain, username, password)
|
10
|
+
@url = "https://#{subdomain}.progresso.net/v2"
|
11
|
+
@username = username
|
12
|
+
@password = URI.encode(password)
|
13
|
+
end
|
14
|
+
|
15
|
+
%w(
|
16
|
+
employees
|
17
|
+
employee_contacts
|
18
|
+
staff_absences
|
19
|
+
employee_checks
|
20
|
+
contacts
|
21
|
+
learners
|
22
|
+
learner_other_details
|
23
|
+
learner_contacts
|
24
|
+
learner_health
|
25
|
+
learner_exclusions
|
26
|
+
learner_sen_provisions
|
27
|
+
learner_sen_major_needs
|
28
|
+
learner_siblings
|
29
|
+
document
|
30
|
+
roll_call_times
|
31
|
+
attendance_codes
|
32
|
+
learner_roll_call_attendance
|
33
|
+
learner_lesson_attendance
|
34
|
+
get_photo
|
35
|
+
udf
|
36
|
+
udf_values
|
37
|
+
assessment_screens
|
38
|
+
learner_assessment_result
|
39
|
+
learner_sats_result
|
40
|
+
learner_assessment_cats_data
|
41
|
+
learner_assessment_cat4_data
|
42
|
+
learner_assessment_kS2fft_data
|
43
|
+
learner_exam_option_result
|
44
|
+
groups
|
45
|
+
group_association
|
46
|
+
school
|
47
|
+
academic_year
|
48
|
+
academic_terms
|
49
|
+
term_breaks
|
50
|
+
week_structure
|
51
|
+
academic_calendar_events
|
52
|
+
courses
|
53
|
+
course_year
|
54
|
+
subjects
|
55
|
+
pay_scales
|
56
|
+
tt_sources
|
57
|
+
day_structures
|
58
|
+
date_mappings
|
59
|
+
day_compositions
|
60
|
+
day_compositions_periods
|
61
|
+
week_ranges
|
62
|
+
tt_events
|
63
|
+
employee_tt_events
|
64
|
+
room_categories
|
65
|
+
room_types
|
66
|
+
rooms
|
67
|
+
site
|
68
|
+
bm_events
|
69
|
+
bm_configuration
|
70
|
+
bm_staff_on_behalf
|
71
|
+
bm_assign_to
|
72
|
+
detention_event
|
73
|
+
bm_structure
|
74
|
+
).each do |resource|
|
75
|
+
define_method resource do |options = {}|
|
76
|
+
resource = resource.split('_').map {|w| w.capitalize}.join
|
77
|
+
response = http_request_with_token("/#{resource}", params: options)
|
78
|
+
|
79
|
+
content_type = response.headers["Content-Type"].match(/^(\w*\/\w*)/)[1]
|
80
|
+
|
81
|
+
case response.status
|
82
|
+
when 204
|
83
|
+
[]
|
84
|
+
when 404
|
85
|
+
raise InvalidRequestError, response.body
|
86
|
+
when 200
|
87
|
+
JSON.parse(response.body)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
def http_request_with_token path, options = {}
|
94
|
+
fetch_token if !@token || @token.expired?
|
95
|
+
|
96
|
+
options[:headers] ||= {}
|
97
|
+
options[:headers]['Authorization'] = "Bearer #{@token.token}"
|
98
|
+
|
99
|
+
http_get_request path, options
|
100
|
+
end
|
101
|
+
|
102
|
+
def fetch_token
|
103
|
+
response = http_post_request "/Token",
|
104
|
+
params: {
|
105
|
+
username: @username,
|
106
|
+
password: @password,
|
107
|
+
grant_type: 'password'
|
108
|
+
},
|
109
|
+
headers: {
|
110
|
+
'Content-Type' => 'application/x-www-form-urlencoded'
|
111
|
+
}
|
112
|
+
|
113
|
+
if response.status != 200
|
114
|
+
raise InvalidCredentialsError, "Username or password incorrect"
|
115
|
+
end
|
116
|
+
|
117
|
+
json = JSON.parse(response.body)
|
118
|
+
|
119
|
+
@token = Token.new(json)
|
120
|
+
end
|
121
|
+
|
122
|
+
def http_post_request path, options = {}
|
123
|
+
Excon.post(
|
124
|
+
"#{@url}#{path}",
|
125
|
+
body: URI.encode_www_form(options[:params]),
|
126
|
+
headers: options[:headers]
|
127
|
+
)
|
128
|
+
end
|
129
|
+
|
130
|
+
def http_get_request path, options = {}
|
131
|
+
Excon.get(
|
132
|
+
"#{@url}#{path}?#{URI.encode_www_form(options[:params])}",
|
133
|
+
headers: options[:headers]
|
134
|
+
)
|
135
|
+
end
|
136
|
+
|
137
|
+
def handle_exceptions(body, parsed_body)
|
138
|
+
StringIO.new(parsed_body["error"] + ", " + parsed_body["message"]) unless [200, 201].include?(body)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
module Progresso
|
4
|
+
class Token
|
5
|
+
attr_reader :token
|
6
|
+
|
7
|
+
def initialize(json)
|
8
|
+
@token = json['access_token']
|
9
|
+
@expires = DateTime.strptime(json['.expires'], '%a, %d %b %Y %H:%M:%S %Z')
|
10
|
+
end
|
11
|
+
|
12
|
+
def expired?
|
13
|
+
@expires < DateTime.now
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/progresso.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "progresso/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "progresso"
|
8
|
+
spec.version = Progresso::VERSION
|
9
|
+
spec.authors = ["Hakim Aryan"]
|
10
|
+
spec.email = ["hakim.aryan@cpoms.co.uk"]
|
11
|
+
|
12
|
+
spec.summary = %q{Progresso API client}
|
13
|
+
spec.homepage = "http://www.cpoms.co.uk"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
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_runtime_dependency "excon", '>= 0.45'
|
23
|
+
spec.add_runtime_dependency 'activesupport', ">= 4"
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.16.a"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: progresso
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hakim Aryan
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-08-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: excon
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.45'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.45'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.16.a
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.16.a
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- hakim.aryan@cpoms.co.uk
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- Gemfile.lock
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- bin/console
|
82
|
+
- bin/setup
|
83
|
+
- lib/progresso.rb
|
84
|
+
- lib/progresso/client.rb
|
85
|
+
- lib/progresso/errors.rb
|
86
|
+
- lib/progresso/token.rb
|
87
|
+
- lib/progresso/version.rb
|
88
|
+
- progresso.gemspec
|
89
|
+
homepage: http://www.cpoms.co.uk
|
90
|
+
licenses: []
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.6.12
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: Progresso API client
|
112
|
+
test_files: []
|