Class: Unistats

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/unistats.rb

Instance Method Summary collapse

Constructor Details

#initialize(access_token) ⇒ Unistats

Initialises the Unistats class and configures authentication with an access token - obtain one at dataportal.unistats.ac.uk/Account/Register Params:

access_token

an access token for the Unistats API



14
15
16
# File 'lib/unistats.rb', line 14

def initialize(access_token)
  self.class.basic_auth access_token, nil
end

Instance Method Details

#authenticated?Boolean

Checks whether provided API authentication credentials for the Unistats API are correct, returning true or false

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
# File 'lib/unistats.rb', line 20

def authenticated?
  response = institutions
  case response.code
  when 401
    false
  else
    true
  end
end

#course(institution, course, recursive = true, options = {}) ⇒ Object

Returns information about a specific course at an institution as an object parsed from JSON Params:

institution

the UKPRN identifier for an institution

course

the KIS ID for a course, unique to a course provider (UKPRN)

recursive

(boolean) sets whether to use the other course data methods

to find out more details about this course (e.g. statistics, stages)



64
65
66
67
68
69
70
71
72
# File 'lib/unistats.rb', line 64

def course(institution, course, recursive=true, options={})
  response = self.class.get("/Institution/#{institution}/Course/#{course}.json", options)
  if recursive
    response.merge!({:accreditations => course_accreditations(institution, course)})
    response.merge!({:stages => course_stages(institution, course)})
    response.merge!({:statistics => course_statistics(institution, course)})
  end
  response
end

#course_accreditations(institution, course, options = {}) ⇒ Object

Returns information on accreditations for a specific course at an institution as an object parsed from JSON Params:

institution

the UKPRN identifier for an institution

course

the KIS ID for a course, unique to a course provider (UKPRN)



79
80
81
# File 'lib/unistats.rb', line 79

def course_accreditations(institution, course, options={})
  self.class.get("/Institution/#{institution}/Course/#{course}/Accreditation.json", options)
end

#course_stages(institution, course, options = {}) ⇒ Object

Returns information on stages of a specific course at an institution as an object parsed from JSON Params:

institution

the UKPRN identifier for an institution

course

the KIS idea for a course, unique to a course provider (UKPRN)



88
89
90
# File 'lib/unistats.rb', line 88

def course_stages(institution, course, options={})
  self.class.get("/Institution/#{institution}/Course/#{course}/Stages.json", options)
end

#course_statistics(institution, course, options = {}) ⇒ Object

Returns statistics aboout a specific course at an institution as an object parsed from JSON Params:

institution

the UKPRN identifier for an institution

course

the KIS idea for a course, unique to a course provider (UKPRN)



97
98
99
# File 'lib/unistats.rb', line 97

def course_statistics(institution, course, options={})
  self.class.get("/Institution/#{institution}/Course/#{course}/Statistics.json", options)
end

#courses(institution, pageIndex = 0, options = {}) ⇒ Object

Returns information about courses at an institution as an object parsed from JSON, in pages of 25 entries Params:

institution

the UKPRN identifier for an institution

pageIndex

the page number to view, starting from 0



52
53
54
55
# File 'lib/unistats.rb', line 52

def courses(institution, pageIndex=0, options={})
  options.merge!({:query => {:pageIndex => pageIndex}})
  self.class.get("/Institution/#{institution}/Courses.json", options)
end

#institution(institution, options = {}) ⇒ Object

Returns information about a specified institution as an object parsed from JSON Params:

institution

the UKPRN identifier for an institution



43
44
45
# File 'lib/unistats.rb', line 43

def institution(institution, options={})
  self.class.get("/Institution/#{institution}.json", options)
end

#institutions(pageIndex = 0, options = {}) ⇒ Object

Returns a list of institutions registered on Unistats in pages of 25 entries as an object parsed from JSON Params:

pageIndex

the page number to view, starting from 0



34
35
36
37
# File 'lib/unistats.rb', line 34

def institutions(pageIndex=0, options={})
  options.merge!({:query => {:pageIndex => pageIndex}})
  self.class.get("/Institutions.json", options)
end