Class: Assembly::Client
- Inherits:
-
Object
- Object
- Assembly::Client
- Defined in:
- lib/assembly/client.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #academic_years ⇒ Object
- #aspects ⇒ Object
- #assessment_points ⇒ Object
- #assessments ⇒ Object
- #attendances ⇒ Object
- #calendar_events ⇒ Object
- #contacts ⇒ Object
- #delete(url) ⇒ Object
- #exclusions ⇒ Object
- #facets ⇒ Object
- #get(url, params = {}) ⇒ Object
- #grade_sets ⇒ Object
-
#initialize(config = Assembly.config) ⇒ Client
constructor
A new instance of Client.
- #on_token_refresh(&blk) ⇒ Object
- #post(url, params = {}) ⇒ Object
- #put(url, params = {}) ⇒ Object
- #refresh_token! ⇒ Object
- #registration_groups ⇒ Object
- #results ⇒ Object
- #school_details ⇒ Object
- #staff_members ⇒ Object
- #students ⇒ Object
- #subjects ⇒ Object
- #teaching_groups ⇒ Object
- #year_groups ⇒ Object
Constructor Details
#initialize(config = Assembly.config) ⇒ Client
Returns a new instance of Client.
5 6 7 8 9 |
# File 'lib/assembly/client.rb', line 5 def initialize(config=Assembly.config) @config = config @on_token_refresh = nil build_api_adapter end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
3 4 5 |
# File 'lib/assembly/client.rb', line 3 def config @config end |
Instance Method Details
#academic_years ⇒ Object
43 44 45 |
# File 'lib/assembly/client.rb', line 43 def academic_years Assembly::AcademicYearResource.new(self) end |
#aspects ⇒ Object
55 56 57 |
# File 'lib/assembly/client.rb', line 55 def aspects Assembly::AspectResource.new(self) end |
#assessment_points ⇒ Object
51 52 53 |
# File 'lib/assembly/client.rb', line 51 def assessment_points Assembly::AssessmentPointResource.new(self) end |
#assessments ⇒ Object
47 48 49 |
# File 'lib/assembly/client.rb', line 47 def assessments Assembly::AssessmentResource.new(self) end |
#attendances ⇒ Object
103 104 105 |
# File 'lib/assembly/client.rb', line 103 def attendances Assembly::AttendanceResource.new(self) end |
#calendar_events ⇒ Object
59 60 61 |
# File 'lib/assembly/client.rb', line 59 def calendar_events Assembly::CalendarEventResource.new(self) end |
#contacts ⇒ Object
63 64 65 |
# File 'lib/assembly/client.rb', line 63 def contacts Assembly::ContactResource.new(self) end |
#delete(url) ⇒ Object
37 38 39 40 41 |
# File 'lib/assembly/client.rb', line 37 def delete(url) response = @api.delete url check_errors(response) response.status == 200 end |
#exclusions ⇒ Object
107 108 109 |
# File 'lib/assembly/client.rb', line 107 def exclusions Assembly::ExclusionResource.new(self) end |
#facets ⇒ Object
83 84 85 |
# File 'lib/assembly/client.rb', line 83 def facets Assembly::FacetResource.new(self) end |
#get(url, params = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/assembly/client.rb', line 11 def get(url, params={}) if_modified_since = params.delete(:since) headers = {} headers.merge!({ 'IF_MODIFIED_SINCE': if_modified_since }) if if_modified_since response = @api.get(url, params, headers) ok = check_errors(response) if ok response.body else get(url, params) end end |
#grade_sets ⇒ Object
67 68 69 |
# File 'lib/assembly/client.rb', line 67 def grade_sets Assembly::GradeSetResource.new(self) end |
#on_token_refresh(&blk) ⇒ Object
115 116 117 |
# File 'lib/assembly/client.rb', line 115 def on_token_refresh(&blk) @on_token_refresh = blk end |
#post(url, params = {}) ⇒ Object
25 26 27 28 29 |
# File 'lib/assembly/client.rb', line 25 def post(url, params={}) response = @api.post url, params.to_json check_errors(response) response.body end |
#put(url, params = {}) ⇒ Object
31 32 33 34 35 |
# File 'lib/assembly/client.rb', line 31 def put(url, params={}) response = @api.put url, params.to_json check_errors(response) response.body end |
#refresh_token! ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/assembly/client.rb', line 119 def refresh_token! return false unless config.client_id && config.client_secret && config.refresh_token refresh_api = Faraday.new(:url => config.auth_host) do |faraday| faraday.request :url_encoded faraday.response :json faraday.adapter Faraday.default_adapter end refresh_api.headers[:accept] = "application/vnd.assembly+json; version=#{config.api_version}" refresh_api.headers[:authorization] = refresh_api.basic_auth(config.client_id, config.client_secret) response = refresh_api.post('/oauth/token', { grant_type: 'refresh_token', refresh_token: config.refresh_token }) return false unless check_errors(response) config.token = response.body[:access_token] build_api_adapter @on_token_refresh.call(response.body) if @on_token_refresh true end |
#registration_groups ⇒ Object
71 72 73 |
# File 'lib/assembly/client.rb', line 71 def registration_groups Assembly::RegistrationGroupResource.new(self) end |
#results ⇒ Object
75 76 77 |
# File 'lib/assembly/client.rb', line 75 def results Assembly::ResultResource.new(self) end |
#school_details ⇒ Object
79 80 81 |
# File 'lib/assembly/client.rb', line 79 def school_details Assembly::SchoolDetailResource.new(self) end |
#staff_members ⇒ Object
87 88 89 |
# File 'lib/assembly/client.rb', line 87 def staff_members Assembly::StaffMemberResource.new(self) end |
#students ⇒ Object
91 92 93 |
# File 'lib/assembly/client.rb', line 91 def students Assembly::StudentResource.new(self) end |
#subjects ⇒ Object
95 96 97 |
# File 'lib/assembly/client.rb', line 95 def subjects Assembly::SubjectResource.new(self) end |
#teaching_groups ⇒ Object
99 100 101 |
# File 'lib/assembly/client.rb', line 99 def teaching_groups Assembly::TeachingGroupResource.new(self) end |
#year_groups ⇒ Object
111 112 113 |
# File 'lib/assembly/client.rb', line 111 def year_groups Assembly::YearGroupResource.new(self) end |