unistats 1.0.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.
Files changed (2) hide show
  1. data/lib/unistats.rb +102 -0
  2. metadata +78 -0
data/lib/unistats.rb ADDED
@@ -0,0 +1,102 @@
1
+ require 'rubygems'
2
+ require 'httparty'
3
+
4
+ class Unistats
5
+ include HTTParty
6
+ format :json
7
+
8
+ base_uri 'data.unistats.ac.uk/api/KIS'
9
+
10
+ # Initialises the Unistats class and configures authentication with an
11
+ # access token - obtain one at http://dataportal.unistats.ac.uk/Account/Register
12
+ # Params:
13
+ # +access_token+:: an access token for the Unistats API
14
+ def initialize(access_token)
15
+ self.class.basic_auth access_token, nil
16
+ end
17
+
18
+ # Checks whether provided API authentication credentials for the Unistats
19
+ # API are correct, returning *true* or *false*
20
+ def authenticated?
21
+ response = institutions
22
+ case response.code
23
+ when 401
24
+ false
25
+ else
26
+ true
27
+ end
28
+ end
29
+
30
+ # Returns a list of institutions registered on Unistats in pages of 25
31
+ # entries as an object parsed from JSON
32
+ # Params:
33
+ # +pageIndex+:: the page number to view, starting from 0
34
+ def institutions(pageIndex=0, options={})
35
+ options.merge!({:query => {:pageIndex => pageIndex}})
36
+ self.class.get("/Institutions.json", options)
37
+ end
38
+
39
+ # Returns information about a specified institution as an object parsed
40
+ # from JSON
41
+ # Params:
42
+ # +institution+:: the UKPRN identifier for an institution
43
+ def institution(institution, options={})
44
+ self.class.get("/Institution/#{institution}.json", options)
45
+ end
46
+
47
+ # Returns information about courses at an institution as an object parsed
48
+ # from JSON, in pages of 25 entries
49
+ # Params:
50
+ # +institution+:: the UKPRN identifier for an institution
51
+ # +pageIndex+:: the page number to view, starting from 0
52
+ def courses(institution, pageIndex=0, options={})
53
+ options.merge!({:query => {:pageIndex => pageIndex}})
54
+ self.class.get("/Institution/#{institution}/Courses.json", options)
55
+ end
56
+
57
+ # Returns information about a specific course at an institution as an object
58
+ # parsed from JSON
59
+ # Params:
60
+ # +institution+:: the UKPRN identifier for an institution
61
+ # +course+:: the KIS ID for a course, unique to a course provider (UKPRN)
62
+ # +recursive+:: (boolean) sets whether to use the other course data methods
63
+ # to find out more details about this course (e.g. statistics, stages)
64
+ def course(institution, course, recursive=true, options={})
65
+ response = self.class.get("/Institution/#{institution}/Course/#{course}.json", options)
66
+ if recursive
67
+ response.merge!({:accreditations => course_accreditations(institution, course)})
68
+ response.merge!({:stages => course_stages(institution, course)})
69
+ response.merge!({:statistics => course_statistics(institution, course)})
70
+ end
71
+ response
72
+ end
73
+
74
+ # Returns information on accreditations for a specific course at an
75
+ # institution as an object parsed from JSON
76
+ # Params:
77
+ # +institution+:: the UKPRN identifier for an institution
78
+ # +course+:: the KIS ID for a course, unique to a course provider (UKPRN)
79
+ def course_accreditations(institution, course, options={})
80
+ self.class.get("/Institution/#{institution}/Course/#{course}/Accreditation.json", options)
81
+ end
82
+
83
+ # Returns information on stages of a specific course at an
84
+ # institution as an object parsed from JSON
85
+ # Params:
86
+ # +institution+:: the UKPRN identifier for an institution
87
+ # +course+:: the KIS idea for a course, unique to a course provider (UKPRN)
88
+ def course_stages(institution, course, options={})
89
+ self.class.get("/Institution/#{institution}/Course/#{course}/Stages.json", options)
90
+ end
91
+
92
+ # Returns statistics aboout a specific course at an institution as an object
93
+ # parsed from JSON
94
+ # Params:
95
+ # +institution+:: the UKPRN identifier for an institution
96
+ # +course+:: the KIS idea for a course, unique to a course provider (UKPRN)
97
+ def course_statistics(institution, course, options={})
98
+ self.class.get("/Institution/#{institution}/Course/#{course}/Statistics.json", options)
99
+ end
100
+ end
101
+
102
+
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: unistats
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tim Rogers
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: json
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: An API for accessing the Unistats API, which provides data from the Higher
47
+ Education Funding Council for England on further education.
48
+ email: tim@tim-rogers.co.uk
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - lib/unistats.rb
54
+ homepage: https://github.com/timrogers/unistats
55
+ licenses: []
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 1.8.24
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: An API library for UK higher education data
78
+ test_files: []