Module: Diegoedoolsapi
- Includes:
- HTTParty
- Defined in:
- lib/diegoedoolsapi.rb,
lib/diegoedoolsapi/version.rb
Constant Summary collapse
- VERSION =
"0.1.1"
Class Attribute Summary collapse
-
.configuration ⇒ Object
Returns the value of attribute configuration.
Instance Attribute Summary collapse
-
#configuration ⇒ Object
Returns the value of attribute configuration.
Class Method Summary collapse
- .configure {|configuration| ... } ⇒ Object
- .create_course(data) ⇒ Object
- .create_school(data) ⇒ Object
- .create_school_product(school_id, data) ⇒ Object
- .get_all(endpoint) ⇒ Object
- .get_headers ⇒ Object
- .get_school_product_students(school_product_id) ⇒ Object
- .get_students(response) ⇒ Object
- .invitation_student(data) ⇒ Object
- .update_school(school_id, data) ⇒ Object
Instance Method Summary collapse
Class Attribute Details
.configuration ⇒ Object
Returns the value of attribute configuration.
13 14 15 |
# File 'lib/diegoedoolsapi.rb', line 13 def configuration @configuration end |
Instance Attribute Details
#configuration ⇒ Object
Returns the value of attribute configuration.
9 10 11 |
# File 'lib/diegoedoolsapi.rb', line 9 def configuration @configuration end |
Class Method Details
.configure {|configuration| ... } ⇒ Object
20 21 22 |
# File 'lib/diegoedoolsapi.rb', line 20 def self.configure yield(configuration) end |
.create_course(data) ⇒ Object
46 47 48 49 |
# 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) ⇒ Object
30 31 32 33 34 35 |
# 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) ⇒ Object
51 52 53 54 |
# 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) ⇒ Object
56 57 58 59 |
# File 'lib/diegoedoolsapi.rb', line 56 def self.get_all(endpoint) response = get("/#{endpoint}", headers: get_headers) check_response(response) end |
.get_headers ⇒ Object
76 77 78 79 80 81 |
# 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) ⇒ Object
66 67 68 69 |
# 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) ⇒ Object
71 72 73 74 |
# 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) ⇒ Object
61 62 63 64 |
# File 'lib/diegoedoolsapi.rb', line 61 def self.invitation_student(data) response = post("/invitations", body: data, headers: get_headers) check_response(response) end |
.update_school(school_id, data) ⇒ Object
37 38 39 40 41 42 43 44 |
# 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 |
Instance Method Details
#initialize ⇒ Object
24 25 26 27 28 |
# 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 |