module Diegoedoolsapi
Constants
- VERSION
Attributes
configuration[RW]
configuration[RW]
Public Class Methods
configure() { |configuration| ... }
click to toggle source
# File lib/diegoedoolsapi.rb, line 20 def self.configure yield(configuration) end
create_course(data)
click to toggle source
# File lib/diegoedoolsapi.rb, line 46 def self.create_course(data) response = post("/courses", body: data, headers: get_headers ) check_response(response) end
create_school(data)
click to toggle source
# File lib/diegoedoolsapi.rb, line 30 def self.create_school(data) response = post("/schools/wizard", body: data, headers: get_headers) credentials = to_hash(response.body)[:admin][:credentials] @created_token = credentials check_response(response) end
create_school_product(school_id, data)
click to toggle source
# File lib/diegoedoolsapi.rb, line 51 def self.create_school_product(school_id, data) response = post("/schools/#{school_id}/school_products", body: data, headers: get_headers) check_response(response) end
get_all(endpoint)
click to toggle source
# File lib/diegoedoolsapi.rb, line 56 def self.get_all(endpoint) response = get("/#{endpoint}", headers: get_headers) check_response(response) end
get_headers()
click to toggle source
# File lib/diegoedoolsapi.rb, line 76 def self.get_headers token = @created_token || self.configuration.token || self.configuration.token_master { "Authorization" => "Token token=#{token}" } end
get_school_product_students(school_product_id)
click to toggle source
# File lib/diegoedoolsapi.rb, line 66 def self.get_school_product_students(school_product_id) response = get("/school_products/#{school_product_id}/enrollments", headers: get_headers) check_response(response) end
get_students(response)
click to toggle source
# File lib/diegoedoolsapi.rb, line 71 def self.get_students(response) parsed_response = to_hash(response) parsed_response[:enrollments].map{ |enrollment| enrollment[:student] } end
invitation_student(data)
click to toggle source
# File lib/diegoedoolsapi.rb, line 61 def self.invitation_student(data) response = post("/invitations", body: data, headers: get_headers) check_response(response) end
new()
click to toggle source
# File lib/diegoedoolsapi.rb, line 24 def initialize @created_token = nil raise "Você não configurou o token master." if self.configuration.token_master.nil? end
update_school(school_id, data)
click to toggle source
# File lib/diegoedoolsapi.rb, line 37 def self.update_school(school_id, data) response = put("/schools/#{school_id}", body: data, headers: get_headers) if response.success? response.parsed_response else puts "#{response.body}" end end
Private Class Methods
check_response(response)
click to toggle source
# File lib/diegoedoolsapi.rb, line 85 def self.check_response(response) if response.success? puts "#{response.parsed_response}" return response.code else puts "#{response.body}" end end
to_hash(object)
click to toggle source
# File lib/diegoedoolsapi.rb, line 94 def self.to_hash(object) JSON.parse object, symbolize_names: true end