class Edools::Client
Constants
- BASE_URI
Attributes
access_token[RW]
Public Class Methods
new(config = {})
click to toggle source
# File lib/edools.rb, line 15 def initialize(config = {}) @access_token = config[:access_token] @raise_errors = config[:raise_errors] || false @retries = config[:retries] || 0 @read_timeout = config[:read_timeout] || 10 @write_timeout = config[:write_timeout] || 10 @connection = Excon.new(BASE_URI, persistent: config[:persistent] || false) end
Public Instance Methods
close_connection()
click to toggle source
# File lib/edools.rb, line 29 def close_connection @connection.reset end
courses()
click to toggle source
courses list courses
# File lib/edools.rb, line 49 def courses run(:get,"/courses", [200]) end
create_and_invitation_studant(params = {})
click to toggle source
create studants and invitation
# File lib/edools.rb, line 89 def create_and_invitation_studant(params = {}) run(:post, "/invitations", [201,422], JSON.dump(params)) end
create_course(params = {})
click to toggle source
create course
# File lib/edools.rb, line 57 def create_course(params = {}) run(:post, "/courses", [201,422], JSON.dump(params)) end
create_product(school_id, params = {})
click to toggle source
create products
# File lib/edools.rb, line 78 def create_product(school_id, params = {}) run(:post, "/schools/#{school_id}/school_products", [201,422], JSON.dump(params)) end
create_school(params = {})
click to toggle source
create school
# File lib/edools.rb, line 39 def create_school(params = {}) run(:post, "/schools/wizard", [201,422], JSON.dump(params)) end
create_studant(params = {})
click to toggle source
create studants
# File lib/edools.rb, line 98 def create_studant(params = {}) run(:post, "/studants/", [201,422], JSON.dump(params)) end
destroy_course(id)
click to toggle source
destroy course
# File lib/edools.rb, line 67 def destroy_course(id) run(:put, "/courses/#{id}", [204,404]) end
destroy_studant(id)
click to toggle source
destroy studant
# File lib/edools.rb, line 109 def destroy_studant(id) run(:delete, "/studants/#{id}", [204,404]) end
inspect()
click to toggle source
# File lib/edools.rb, line 24 def inspect vars = instance_variables.map { |v| "#{v}=#{instance_variable_get(v).inspect}" }.join(', ') "<#{self.class}: #{vars}>" end
products()
click to toggle source
products TODO error not rerturn products list products
# File lib/edools.rb, line 73 def products run(:get,"/school_products", [200]) end
show_course(id)
click to toggle source
show course
# File lib/edools.rb, line 53 def show_course(id) run(:get, "/courses/#{id}", [200]) end
show_school(id)
click to toggle source
show school
# File lib/edools.rb, line 35 def show_school(id) run(:get, "/schools/#{id}", [200]) end
show_studant(id)
click to toggle source
show studant
# File lib/edools.rb, line 93 def show_studant(id) run(:get, "/studants/#{id}", [200,404]) end
studants()
click to toggle source
studantes studants
# File lib/edools.rb, line 84 def studants run(:get,"/studants", [200]) end
update_course(id, params = {})
click to toggle source
update course
# File lib/edools.rb, line 62 def update_course(id, params = {}) run(:put, "/courses/#{id}", [200,422], JSON.dump(params)) end
update_school(id, params = {})
click to toggle source
update school
# File lib/edools.rb, line 43 def update_school(id, params = {}) run(:put, "/schools/#{id}", [200,422], JSON.dump(params)) end
update_studant(id, params = {})
click to toggle source
update studants
# File lib/edools.rb, line 104 def update_studant(id, params = {}) run(:put, "/studants/#{id}", [200,422], JSON.dump(params)) end
Protected Instance Methods
run(verb, path, expected_status_codes, params = {}, idempotent = true)
click to toggle source
# File lib/edools.rb, line 116 def run(verb, path, expected_status_codes, params = {}, idempotent = true) run!(verb, path, expected_status_codes, params, idempotent) rescue Error => e if @raise_errors raise e else false end end
run!(verb, path, expected_status_codes, params_or_body = nil, idempotent = true)
click to toggle source
# File lib/edools.rb, line 127 def run!(verb, path, expected_status_codes, params_or_body = nil, idempotent = true) packet = { idempotent: idempotent, expects: expected_status_codes, method: verb, path: path, read_timeout: @read_timeout, write_timeout: @write_timeout, retry_limit: @retries, headers: { 'Content-Type' => 'application/json', 'Accept' => 'application/vnd.edools.core.v1+json' } } if params_or_body.is_a?(Hash) packet.merge!(query: params_or_body) else packet.merge!(body: params_or_body) end if !@access_token.nil? && @access_token != '' packet[:headers].merge!('Authorization' => 'Token token="' + @access_token +'"') end response = @connection.request(packet) @response_body = response.body ::JSON.load(@response_body) rescue Excon::Errors::NotFound => exception raise(ResourceNotFound, "Error: #{exception.message}") rescue Excon::Errors::BadRequest => exception raise(BadRequest, "Error: #{exception.message}") rescue Excon::Errors::Forbidden => exception raise(InsufficientClientScopeError, "Error: #{exception.message}") rescue Excon::Errors::Unauthorized => exception raise(AuthenticationError, "Error: #{exception.message}") rescue Excon::Errors::Error => exception raise(HTTPError, "Error: #{exception.message}") end