edools_sdk 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/edools_sdk.rb +16 -0
- data/lib/edools_sdk/course.rb +188 -0
- data/lib/edools_sdk/edools_base.rb +13 -0
- data/lib/edools_sdk/invitation.rb +58 -0
- data/lib/edools_sdk/product.rb +262 -0
- data/lib/edools_sdk/school.rb +211 -0
- data/lib/edools_sdk/student.rb +167 -0
- metadata +64 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: df9bf12b8cdeb83a7fa6535f06755ccd0d94c416
|
4
|
+
data.tar.gz: f377db745565bace218cb3271f34b221dfd61f52
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 43b640df7e14a6ae25bac2193b45270240a81af5b2fcc4e62883b866a0de5f659d893956a9afe743319145e9fa12c119ce0fb36312d35cbe285ec987f77630f0
|
7
|
+
data.tar.gz: 01471b24d3e25437c3e71f24f0f388d2f50afc89cfd2ee162b0f7042fee3767f54768ac73c93ca2e99b6e7ef4b978d1bb2375c0586c9ac7744d334ac0772289c
|
data/lib/edools_sdk.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'edools_sdk/edools_base'
|
2
|
+
require 'edools_sdk/school'
|
3
|
+
require 'edools_sdk/course'
|
4
|
+
require 'edools_sdk/product'
|
5
|
+
require 'edools_sdk/student'
|
6
|
+
require 'edools_sdk/invitation'
|
7
|
+
require 'yaml'
|
8
|
+
|
9
|
+
file_exists = File.file?('config/edools.yml')
|
10
|
+
|
11
|
+
if ENV['edools_token'].nil? && file_exists
|
12
|
+
config = YAML.load_file('config/edools.yml')
|
13
|
+
ENV['edools_token'] = config['token']
|
14
|
+
elsif ENV['edools_token'].nil? && !file_exists
|
15
|
+
puts "WARNING: edools token not configurated!"
|
16
|
+
end
|
@@ -0,0 +1,188 @@
|
|
1
|
+
module EdoolsSdk
|
2
|
+
# Course class
|
3
|
+
class Course < EdoolsBase
|
4
|
+
attr_accessor(
|
5
|
+
:id,
|
6
|
+
:name,
|
7
|
+
:description,
|
8
|
+
:image_url,
|
9
|
+
:duration,
|
10
|
+
:ready,
|
11
|
+
:path_ids,
|
12
|
+
:forum_section_ids,
|
13
|
+
:linear_requirements,
|
14
|
+
:library_resource,
|
15
|
+
:created_at,
|
16
|
+
:updated_at
|
17
|
+
)
|
18
|
+
|
19
|
+
COURSE_URL = 'https://core.myedools.info/api/courses'
|
20
|
+
private_constant :COURSE_URL
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
@id = nil
|
24
|
+
@name = nil
|
25
|
+
@description = nil
|
26
|
+
@image_url = nil
|
27
|
+
@duration = nil
|
28
|
+
@ready = nil
|
29
|
+
@path_ids = nil
|
30
|
+
@forum_section_ids = nil
|
31
|
+
@linear_requirements = nil
|
32
|
+
@library_resource = nil
|
33
|
+
@created_at = nil
|
34
|
+
@updated_at = nil
|
35
|
+
end
|
36
|
+
|
37
|
+
# Parse json to Course object
|
38
|
+
def self.parse_json(props)
|
39
|
+
course = Course.new
|
40
|
+
course.id = props['id']
|
41
|
+
course.name = props['name']
|
42
|
+
course.description = props['description']
|
43
|
+
course.image_url = props['image_url']
|
44
|
+
course.duration = props['duration']
|
45
|
+
course.ready = props['ready']
|
46
|
+
course.path_ids = props['path_ids']
|
47
|
+
course.forum_section_ids = props['forum_section_ids']
|
48
|
+
course.linear_requirements = props['linear_requirements']
|
49
|
+
course.library_resource = props['library_resource']
|
50
|
+
|
51
|
+
unless props['created_at'].nil?
|
52
|
+
course.created_at = Date.parse(props['created_at'])
|
53
|
+
end
|
54
|
+
unless props['updated_at'].nil?
|
55
|
+
course.updated_at = Date.parse(props['updated_at'])
|
56
|
+
end
|
57
|
+
|
58
|
+
course
|
59
|
+
end
|
60
|
+
|
61
|
+
# Get all courses, if anything goes wrong an exception will be raised
|
62
|
+
#
|
63
|
+
# Example:
|
64
|
+
# >> Course.all!
|
65
|
+
# => [#<EdoolsSdk::Course:0x00000001aef0c8 @id=21530, @name="test 4", @description=nil, @image_url=nil, @duration=nil, @ready=nil, @path_ids=[], @forum_section_ids=[], @linear_requirements=nil, @library_resource={"id"=>1152227, "library"=>{"id"=>572}, "library_tags"=>[], "school_products"=>[]}, @created_at=#<Date: 2017-09-25 ((2458022j,0s,0n),+0s,2299161j)>, @updated_at=#<Date: 2017-09-25 ((2458022j,0s,0n),+0s,2299161j)>>]
|
66
|
+
def self.all!
|
67
|
+
response = HTTP
|
68
|
+
.headers('Authorization' => "Token token=\"#{ENV['edools_token']}\"")
|
69
|
+
.get(COURSE_URL)
|
70
|
+
|
71
|
+
raise "invalid status code #{response.status}" if response.status >= 400 && response.status < 600
|
72
|
+
|
73
|
+
body = response.parse(:json)
|
74
|
+
|
75
|
+
body['courses'].map { |c| Course.parse_json(c) }
|
76
|
+
end
|
77
|
+
|
78
|
+
# Get all courses
|
79
|
+
#
|
80
|
+
# Example:
|
81
|
+
# >> Course.all!
|
82
|
+
# => [#<EdoolsSdk::Course:0x00000001aef0c8 @id=21530, @name="test 4", @description=nil, @image_url=nil, @duration=nil, @ready=nil, @path_ids=[], @forum_section_ids=[], @linear_requirements=nil, @library_resource={"id"=>1152227, "library"=>{"id"=>572}, "library_tags"=>[], "school_products"=>[]}, @created_at=#<Date: 2017-09-25 ((2458022j,0s,0n),+0s,2299161j)>, @updated_at=#<Date: 2017-09-25 ((2458022j,0s,0n),+0s,2299161j)>>]
|
83
|
+
def self.all
|
84
|
+
response = HTTP
|
85
|
+
.headers('Authorization' => "Token token=\"#{ENV['edools_token']}\"")
|
86
|
+
.get(COURSE_URL)
|
87
|
+
|
88
|
+
return response if response.status >= 400 && response.status < 600
|
89
|
+
|
90
|
+
body = response.parse(:json)
|
91
|
+
|
92
|
+
body['courses'].map { |c| Course.parse_json(c) }
|
93
|
+
end
|
94
|
+
|
95
|
+
# Save a course, if anything goes wrong an exception will be raised
|
96
|
+
#
|
97
|
+
# Example:
|
98
|
+
# >> course_instance.save!
|
99
|
+
# => #<EdoolsSdk::Course:0x00000001aef0c8 @id=21530, @name="test 4", @description=nil, @image_url=nil, @duration=nil, @ready=nil, @path_ids=[], @forum_section_ids=[], @linear_requirements=nil, @library_resource={"id"=>1152227, "library"=>{"id"=>572}, "library_tags"=>[], "school_products"=>[]}, @created_at=#<Date: 2017-09-25 ((2458022j,0s,0n),+0s,2299161j)>, @updated_at=#<Date: 2017-09-25 ((2458022j,0s,0n),+0s,2299161j)>>
|
100
|
+
def save!
|
101
|
+
response = HTTP
|
102
|
+
.headers('Authorization' => "Token token=\"#{ENV['edools_token']}\"")
|
103
|
+
.post(COURSE_URL, :json => self.to_h)
|
104
|
+
|
105
|
+
raise "invalid status code #{response.status}" if response.status != 201
|
106
|
+
|
107
|
+
body = response.parse(:json)
|
108
|
+
|
109
|
+
course_saved = Course.parse_json(body)
|
110
|
+
|
111
|
+
change_values(course_saved)
|
112
|
+
|
113
|
+
course_saved
|
114
|
+
end
|
115
|
+
|
116
|
+
# Save a course
|
117
|
+
#
|
118
|
+
# Example:
|
119
|
+
# >> course_instance.save
|
120
|
+
# => #<EdoolsSdk::Course:0x00000001aef0c8 @id=21530, @name="test 4", @description=nil, @image_url=nil, @duration=nil, @ready=nil, @path_ids=[], @forum_section_ids=[], @linear_requirements=nil, @library_resource={"id"=>1152227, "library"=>{"id"=>572}, "library_tags"=>[], "school_products"=>[]}, @created_at=#<Date: 2017-09-25 ((2458022j,0s,0n),+0s,2299161j)>, @updated_at=#<Date: 2017-09-25 ((2458022j,0s,0n),+0s,2299161j)>>
|
121
|
+
def save
|
122
|
+
response = HTTP
|
123
|
+
.headers('Authorization' => "Token token=\"#{ENV['edools_token']}\"")
|
124
|
+
.post(COURSE_URL, :json => self.to_h)
|
125
|
+
|
126
|
+
return response if response.status != 201
|
127
|
+
|
128
|
+
body = response.parse(:json)
|
129
|
+
|
130
|
+
course_saved = Course.parse_json(body)
|
131
|
+
|
132
|
+
change_values(course_saved)
|
133
|
+
|
134
|
+
course_saved
|
135
|
+
end
|
136
|
+
|
137
|
+
# Create a course, if anything goes wrong an exception will be raised
|
138
|
+
#
|
139
|
+
# Example:
|
140
|
+
# >> Course.create!("name" => "test")
|
141
|
+
# => #<EdoolsSdk::Course:0x00000001aef0c8 @id=21530, @name="test", @description=nil, @image_url=nil, @duration=nil, @ready=nil, @path_ids=[], @forum_section_ids=[], @linear_requirements=nil, @library_resource={"id"=>1152227, "library"=>{"id"=>572}, "library_tags"=>[], "school_products"=>[]}, @created_at=#<Date: 2017-09-25 ((2458022j,0s,0n),+0s,2299161j)>, @updated_at=#<Date: 2017-09-25 ((2458022j,0s,0n),+0s,2299161j)>>
|
142
|
+
def self.create!(props)
|
143
|
+
response = HTTP
|
144
|
+
.headers('Authorization' => "Token token=\"#{ENV['edools_token']}\"")
|
145
|
+
.post(COURSE_URL, :json => props)
|
146
|
+
|
147
|
+
raise "invalid status code #{response.status}" if response.status != 201
|
148
|
+
|
149
|
+
body = response.parse(:json)
|
150
|
+
|
151
|
+
Course.parse_json(body)
|
152
|
+
end
|
153
|
+
|
154
|
+
# Create a course
|
155
|
+
#
|
156
|
+
# Example:
|
157
|
+
# >> Course.create("name" => "test")
|
158
|
+
# => #<EdoolsSdk::Course:0x00000001aef0c8 @id=21530, @name="test", @description=nil, @image_url=nil, @duration=nil, @ready=nil, @path_ids=[], @forum_section_ids=[], @linear_requirements=nil, @library_resource={"id"=>1152227, "library"=>{"id"=>572}, "library_tags"=>[], "school_products"=>[]}, @created_at=#<Date: 2017-09-25 ((2458022j,0s,0n),+0s,2299161j)>, @updated_at=#<Date: 2017-09-25 ((2458022j,0s,0n),+0s,2299161j)>>
|
159
|
+
def self.create(props)
|
160
|
+
response = HTTP
|
161
|
+
.headers('Authorization' => "Token token=\"#{ENV['edools_token']}\"")
|
162
|
+
.post(COURSE_URL, :json => props)
|
163
|
+
|
164
|
+
return response if response.status != 201
|
165
|
+
|
166
|
+
body = response.parse(:json)
|
167
|
+
|
168
|
+
Course.parse_json(body)
|
169
|
+
end
|
170
|
+
|
171
|
+
private
|
172
|
+
|
173
|
+
def change_values(course)
|
174
|
+
@id = course.id
|
175
|
+
@name = course.name
|
176
|
+
@description = course.description
|
177
|
+
@image_url = course.image_url
|
178
|
+
@duration = course.duration
|
179
|
+
@ready = course.ready
|
180
|
+
@path_ids = course.path_ids
|
181
|
+
@forum_section_ids = course.forum_section_ids
|
182
|
+
@linear_requirements = course.linear_requirements
|
183
|
+
@library_resource = course.library_resource
|
184
|
+
@created_at = course.created_at
|
185
|
+
@updated_at = course.updated_at
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module EdoolsSdk
|
2
|
+
# Invitation class
|
3
|
+
class Invitation < EdoolsBase
|
4
|
+
attr_accessor(
|
5
|
+
:id,
|
6
|
+
:first_name,
|
7
|
+
:last_name,
|
8
|
+
:email,
|
9
|
+
:cpf,
|
10
|
+
:phone,
|
11
|
+
:skype,
|
12
|
+
:twitter,
|
13
|
+
:facebook,
|
14
|
+
:company_name,
|
15
|
+
:company_position,
|
16
|
+
:born_at,
|
17
|
+
:biography,
|
18
|
+
:cover_image_url
|
19
|
+
)
|
20
|
+
|
21
|
+
# Parse json to Invitation object
|
22
|
+
def self.parse_json(props)
|
23
|
+
invitation = Invitation.new
|
24
|
+
|
25
|
+
invitation.id = props['id']
|
26
|
+
invitation.first_name = props['first_name']
|
27
|
+
invitation.last_name = props['last_name']
|
28
|
+
invitation.email = props['email']
|
29
|
+
invitation.cpf = props['cpf']
|
30
|
+
invitation.phone = props['phone']
|
31
|
+
invitation.skype = props['skype']
|
32
|
+
invitation.twitter = props['twitter']
|
33
|
+
invitation.facebook = props['facebook']
|
34
|
+
invitation.company_name = props['company_name']
|
35
|
+
invitation.company_position = props['company_position']
|
36
|
+
invitation.born_at = props['born_at']
|
37
|
+
invitation.biography = props['biography']
|
38
|
+
invitation.cover_image_url = props['cover_image_url']
|
39
|
+
|
40
|
+
invitation
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
|
@@ -0,0 +1,262 @@
|
|
1
|
+
module EdoolsSdk
|
2
|
+
# Product class
|
3
|
+
class Product < EdoolsBase
|
4
|
+
attr_accessor(
|
5
|
+
:id,
|
6
|
+
:title,
|
7
|
+
:description,
|
8
|
+
:subtitle,
|
9
|
+
:logo,
|
10
|
+
:video_url,
|
11
|
+
:video_title,
|
12
|
+
:video_description,
|
13
|
+
:published,
|
14
|
+
:hidden,
|
15
|
+
:restricted,
|
16
|
+
:certification,
|
17
|
+
:classes_auto_generation,
|
18
|
+
:certification_min_progress,
|
19
|
+
:meta_title,
|
20
|
+
:meta_description,
|
21
|
+
:meta_keys,
|
22
|
+
:available_time_type,
|
23
|
+
:available_time_length,
|
24
|
+
:available_time_unit,
|
25
|
+
:expire_date,
|
26
|
+
:library_resource_id,
|
27
|
+
:max_attendance_type,
|
28
|
+
:max_attendance_length,
|
29
|
+
:allowed_emails,
|
30
|
+
:class_teacher_ids,
|
31
|
+
:category_ids,
|
32
|
+
:gallery_media_ids,
|
33
|
+
:created_at,
|
34
|
+
:updated_at
|
35
|
+
)
|
36
|
+
|
37
|
+
PRODUCT_URL = 'https://core.myedools.info/api/schools/'
|
38
|
+
PRODUCT_URL_WITHOUT_SCHOOL = 'https://core.myedools.info/api/school_products'
|
39
|
+
private_constant :PRODUCT_URL
|
40
|
+
|
41
|
+
def initialize
|
42
|
+
@id = nil
|
43
|
+
@title = nil
|
44
|
+
@description = nil
|
45
|
+
@subtitle = nil
|
46
|
+
@logo = nil
|
47
|
+
@video_url = nil
|
48
|
+
@video_title = nil
|
49
|
+
@video_description = nil
|
50
|
+
@published = nil
|
51
|
+
@hidden = nil
|
52
|
+
@restricted = nil
|
53
|
+
@certification = nil
|
54
|
+
@classes_auto_generation = nil
|
55
|
+
@certification_min_progress = nil
|
56
|
+
@meta_title = nil
|
57
|
+
@meta_description = nil
|
58
|
+
@meta_keys = nil
|
59
|
+
@available_time_type = nil
|
60
|
+
@available_time_length = nil
|
61
|
+
@available_time_unit = nil
|
62
|
+
@expire_date = nil
|
63
|
+
@library_resource_id = nil
|
64
|
+
@max_attendance_type = nil
|
65
|
+
@max_attendance_length = nil
|
66
|
+
@allowed_emails = nil
|
67
|
+
@class_teacher_ids = nil
|
68
|
+
@category_ids = nil
|
69
|
+
@gallery_media_ids = nil
|
70
|
+
@created_at = nil
|
71
|
+
@updated_at = nil
|
72
|
+
end
|
73
|
+
|
74
|
+
# Parse json to Product object
|
75
|
+
def self.parse_json(props)
|
76
|
+
product = Product.new
|
77
|
+
|
78
|
+
product.id = props['id']
|
79
|
+
product.title = props['title']
|
80
|
+
product.description = props['description']
|
81
|
+
product.subtitle = props['subtitle']
|
82
|
+
product.logo = props['logo']
|
83
|
+
product.video_url = props['video_url']
|
84
|
+
product.video_title = props['video_title']
|
85
|
+
product.video_description = props['video_description']
|
86
|
+
product.published = props['published']
|
87
|
+
product.hidden = props['hidden']
|
88
|
+
product.restricted = props['restricted']
|
89
|
+
product.certification = props['certification']
|
90
|
+
product.classes_auto_generation = props['classes_auto_generation']
|
91
|
+
product.certification_min_progress = props['certification_min_progress']
|
92
|
+
product.meta_title = props['meta_title']
|
93
|
+
product.meta_description = props['meta_description']
|
94
|
+
product.meta_keys = props['meta_keys']
|
95
|
+
product.available_time_type = props['available_time_type']
|
96
|
+
product.available_time_length = props['available_time_length']
|
97
|
+
product.available_time_unit = props['available_time_unit']
|
98
|
+
product.expire_date = props['expire_date']
|
99
|
+
product.library_resource_id = props['library_resource_id']
|
100
|
+
product.max_attendance_type = props['max_attendance_type']
|
101
|
+
product.max_attendance_length = props['max_attendance_length']
|
102
|
+
product.allowed_emails = props['allowed_emails']
|
103
|
+
product.class_teacher_ids = props['class_teacher_ids']
|
104
|
+
product.category_ids = props['category_ids']
|
105
|
+
product.gallery_media_ids = props['gallery_media_ids']
|
106
|
+
|
107
|
+
unless props['created_at'].nil?
|
108
|
+
product.created_at = Date.parse(props['created_at'])
|
109
|
+
end
|
110
|
+
unless props['updated_at'].nil?
|
111
|
+
product.updated_at = Date.parse(props['updated_at'])
|
112
|
+
end
|
113
|
+
|
114
|
+
product
|
115
|
+
end
|
116
|
+
|
117
|
+
# Get all products, if anything goes wrong an exception will be raised
|
118
|
+
#
|
119
|
+
# Example:
|
120
|
+
# >> Product.all!
|
121
|
+
# => [#<EdoolsSdk::Product:0x00000002bc4a88 @id=22395, @title="test product 1", @description=nil, @subtitle=nil, @logo=nil, @video_url=nil, @video_title=nil, @video_description=nil, @published=false, @hidden=false, @restricted=false, @certification=false, @classes_auto_generation=false, @certification_min_progress=nil, @meta_title=nil, @meta_description=nil, @meta_keys=nil, @available_time_type="indeterminate", @available_time_length=nil, @available_time_unit=nil, @expire_date=nil, @library_resource_id=nil, @max_attendance_type="indeterminate", @max_attendance_length=nil, @allowed_emails=[], @class_teacher_ids=nil, @category_ids=nil, @gallery_media_ids=nil, @created_at=#<Date: 2017-09-25 ((2458022j,0s,0n),+0s,2299161j)>, @updated_at=#<Date: 2017-09-25 ((2458022j,0s,0n),+0s,2299161j)>>]
|
122
|
+
def self.all!
|
123
|
+
response = HTTP
|
124
|
+
.headers('Authorization' => "Token token=\"#{ENV['edools_token']}\"")
|
125
|
+
.get(PRODUCT_URL_WITHOUT_SCHOOL)
|
126
|
+
|
127
|
+
raise "invalid status code #{response.status}" if response.status >= 400 && response.status < 600
|
128
|
+
|
129
|
+
body = response.parse(:json)
|
130
|
+
|
131
|
+
body['school_products'].map { |c| Product.parse_json(c) }
|
132
|
+
end
|
133
|
+
|
134
|
+
# Get all products
|
135
|
+
#
|
136
|
+
# Example:
|
137
|
+
# >> Product.all!
|
138
|
+
# => [#<EdoolsSdk::Product:0x00000002bc4a88 @id=22395, @title="test product 1", @description=nil, @subtitle=nil, @logo=nil, @video_url=nil, @video_title=nil, @video_description=nil, @published=false, @hidden=false, @restricted=false, @certification=false, @classes_auto_generation=false, @certification_min_progress=nil, @meta_title=nil, @meta_description=nil, @meta_keys=nil, @available_time_type="indeterminate", @available_time_length=nil, @available_time_unit=nil, @expire_date=nil, @library_resource_id=nil, @max_attendance_type="indeterminate", @max_attendance_length=nil, @allowed_emails=[], @class_teacher_ids=nil, @category_ids=nil, @gallery_media_ids=nil, @created_at=#<Date: 2017-09-25 ((2458022j,0s,0n),+0s,2299161j)>, @updated_at=#<Date: 2017-09-25 ((2458022j,0s,0n),+0s,2299161j)>>]
|
139
|
+
def self.all
|
140
|
+
response = HTTP
|
141
|
+
.headers('Authorization' => "Token token=\"#{ENV['edools_token']}\"")
|
142
|
+
.get(PRODUCT_URL_WITHOUT_SCHOOL)
|
143
|
+
|
144
|
+
return response if response.status >= 400 && response.status < 600
|
145
|
+
|
146
|
+
body = response.parse(:json)
|
147
|
+
|
148
|
+
body['school_products'].map { |c| Product.parse_json(c) }
|
149
|
+
end
|
150
|
+
|
151
|
+
# Save a product, if anything goes wrong an exception will be raised
|
152
|
+
#
|
153
|
+
# Example:
|
154
|
+
# >> product_instance.save(222)!
|
155
|
+
# => #<EdoolsSdk::Product:0x00000002bc4a88 @id=22395, @title="test product 1", @description=nil, @subtitle=nil, @logo=nil, @video_url=nil, @video_title=nil, @video_description=nil, @published=false, @hidden=false, @restricted=false, @certification=false, @classes_auto_generation=false, @certification_min_progress=nil, @meta_title=nil, @meta_description=nil, @meta_keys=nil, @available_time_type="indeterminate", @available_time_length=nil, @available_time_unit=nil, @expire_date=nil, @library_resource_id=nil, @max_attendance_type="indeterminate", @max_attendance_length=nil, @allowed_emails=[], @class_teacher_ids=nil, @category_ids=nil, @gallery_media_ids=nil, @created_at=#<Date: 2017-09-25 ((2458022j,0s,0n),+0s,2299161j)>, @updated_at=#<Date: 2017-09-25 ((2458022j,0s,0n),+0s,2299161j)>>
|
156
|
+
def save!(school_id)
|
157
|
+
response = HTTP
|
158
|
+
.headers('Authorization' => "Token token=\"#{ENV['edools_token']}\"")
|
159
|
+
.post("#{PRODUCT_URL}#{school_id}/school_products", :json => self.to_h)
|
160
|
+
|
161
|
+
raise "invalid status code #{response.status}" if response.status != 201
|
162
|
+
|
163
|
+
body = response.parse(:json)
|
164
|
+
|
165
|
+
product_saved = Product.parse_json(body)
|
166
|
+
|
167
|
+
change_values(product_saved)
|
168
|
+
|
169
|
+
product_saved
|
170
|
+
end
|
171
|
+
|
172
|
+
# Save a product
|
173
|
+
#
|
174
|
+
# Example:
|
175
|
+
# >> product_instance.save(222)
|
176
|
+
# => #<EdoolsSdk::Product:0x00000002bc4a88 @id=22395, @title="test product 1", @description=nil, @subtitle=nil, @logo=nil, @video_url=nil, @video_title=nil, @video_description=nil, @published=false, @hidden=false, @restricted=false, @certification=false, @classes_auto_generation=false, @certification_min_progress=nil, @meta_title=nil, @meta_description=nil, @meta_keys=nil, @available_time_type="indeterminate", @available_time_length=nil, @available_time_unit=nil, @expire_date=nil, @library_resource_id=nil, @max_attendance_type="indeterminate", @max_attendance_length=nil, @allowed_emails=[], @class_teacher_ids=nil, @category_ids=nil, @gallery_media_ids=nil, @created_at=#<Date: 2017-09-25 ((2458022j,0s,0n),+0s,2299161j)>, @updated_at=#<Date: 2017-09-25 ((2458022j,0s,0n),+0s,2299161j)>>
|
177
|
+
def save(school_id)
|
178
|
+
response = HTTP
|
179
|
+
.headers('Authorization' => "Token token=\"#{ENV['edools_token']}\"")
|
180
|
+
.post("#{PRODUCT_URL}#{school_id}/school_products", :json => self.to_h)
|
181
|
+
|
182
|
+
return response if response.status != 201
|
183
|
+
|
184
|
+
body = response.parse(:json)
|
185
|
+
|
186
|
+
product_saved = Product.parse_json(body)
|
187
|
+
|
188
|
+
change_values(product_saved)
|
189
|
+
|
190
|
+
product_saved
|
191
|
+
end
|
192
|
+
|
193
|
+
# Create a product, if anything goes wrong an exception will be raised
|
194
|
+
#
|
195
|
+
# Example:
|
196
|
+
# >> Product.create!(222, "title" => "test")
|
197
|
+
# => #<EdoolsSdk::Product:0x00000002bc4a88 @id=22395, @title="test product 1", @description=nil, @subtitle=nil, @logo=nil, @video_url=nil, @video_title=nil, @video_description=nil, @published=false, @hidden=false, @restricted=false, @certification=false, @classes_auto_generation=false, @certification_min_progress=nil, @meta_title=nil, @meta_description=nil, @meta_keys=nil, @available_time_type="indeterminate", @available_time_length=nil, @available_time_unit=nil, @expire_date=nil, @library_resource_id=nil, @max_attendance_type="indeterminate", @max_attendance_length=nil, @allowed_emails=[], @class_teacher_ids=nil, @category_ids=nil, @gallery_media_ids=nil, @created_at=#<Date: 2017-09-25 ((2458022j,0s,0n),+0s,2299161j)>, @updated_at=#<Date: 2017-09-25 ((2458022j,0s,0n),+0s,2299161j)>>
|
198
|
+
def self.create!(school_id, props)
|
199
|
+
response = HTTP
|
200
|
+
.headers('Authorization' => "Token token=\"#{ENV['edools_token']}\"")
|
201
|
+
.post("#{PRODUCT_URL}#{school_id}/school_products", :json => props)
|
202
|
+
|
203
|
+
raise "invalid status code #{response.status}" if response.status != 201
|
204
|
+
|
205
|
+
body = response.parse(:json)
|
206
|
+
|
207
|
+
Product.parse_json(body)
|
208
|
+
end
|
209
|
+
|
210
|
+
# Create a product
|
211
|
+
#
|
212
|
+
# Example:
|
213
|
+
# >> Product.create(222, "title" => "test")
|
214
|
+
# => #<EdoolsSdk::Product:0x00000002bc4a88 @id=22395, @title="test product 1", @description=nil, @subtitle=nil, @logo=nil, @video_url=nil, @video_title=nil, @video_description=nil, @published=false, @hidden=false, @restricted=false, @certification=false, @classes_auto_generation=false, @certification_min_progress=nil, @meta_title=nil, @meta_description=nil, @meta_keys=nil, @available_time_type="indeterminate", @available_time_length=nil, @available_time_unit=nil, @expire_date=nil, @library_resource_id=nil, @max_attendance_type="indeterminate", @max_attendance_length=nil, @allowed_emails=[], @class_teacher_ids=nil, @category_ids=nil, @gallery_media_ids=nil, @created_at=#<Date: 2017-09-25 ((2458022j,0s,0n),+0s,2299161j)>, @updated_at=#<Date: 2017-09-25 ((2458022j,0s,0n),+0s,2299161j)>>
|
215
|
+
def self.create(school_id, props)
|
216
|
+
response = HTTP
|
217
|
+
.headers('Authorization' => "Token token=\"#{ENV['edools_token']}\"")
|
218
|
+
.post("#{PRODUCT_URL}#{school_id}/school_products", :json => props)
|
219
|
+
|
220
|
+
return response if response.status != 201
|
221
|
+
|
222
|
+
body = response.parse(:json)
|
223
|
+
|
224
|
+
Product.parse_json(body)
|
225
|
+
end
|
226
|
+
|
227
|
+
private
|
228
|
+
|
229
|
+
def change_values(product)
|
230
|
+
@id = product.id
|
231
|
+
@title = product.title
|
232
|
+
@description = product.description
|
233
|
+
@subtitle = product.subtitle
|
234
|
+
@logo = product.logo
|
235
|
+
@video_url = product.video_url
|
236
|
+
@video_title = product.video_title
|
237
|
+
@video_description = product.video_description
|
238
|
+
@published = product.published
|
239
|
+
@hidden = product.hidden
|
240
|
+
@restricted = product.restricted
|
241
|
+
@certification = product.certification
|
242
|
+
@classes_auto_generation = product.classes_auto_generation
|
243
|
+
@certification_min_progress = product.certification_min_progress
|
244
|
+
@meta_title = product.meta_title
|
245
|
+
@meta_description = product.meta_description
|
246
|
+
@meta_keys = product.meta_keys
|
247
|
+
@available_time_type = product.available_time_type
|
248
|
+
@available_time_length = product.available_time_length
|
249
|
+
@available_time_unit = product.available_time_unit
|
250
|
+
@expire_date = product.expire_date
|
251
|
+
@library_resource_id = product.library_resource_id
|
252
|
+
@max_attendance_type = product.max_attendance_type
|
253
|
+
@max_attendance_length = product.max_attendance_length
|
254
|
+
@allowed_emails = product.allowed_emails
|
255
|
+
@class_teacher_ids = product.class_teacher_ids
|
256
|
+
@category_ids = product.category_ids
|
257
|
+
@gallery_media_ids = product.gallery_media_ids
|
258
|
+
@created_at = product.created_at
|
259
|
+
@updated_at = product.updated_at
|
260
|
+
end
|
261
|
+
end
|
262
|
+
end
|
@@ -0,0 +1,211 @@
|
|
1
|
+
module EdoolsSdk
|
2
|
+
# School class
|
3
|
+
class School < EdoolsBase
|
4
|
+
attr_accessor(
|
5
|
+
:id,
|
6
|
+
:credentials,
|
7
|
+
:name,
|
8
|
+
:password,
|
9
|
+
:subdomain,
|
10
|
+
:domains,
|
11
|
+
:rdstation_token,
|
12
|
+
:adroll_adv_id,
|
13
|
+
:adroll_pix_id,
|
14
|
+
:email,
|
15
|
+
:phone,
|
16
|
+
:cnpj,
|
17
|
+
:samba_key,
|
18
|
+
:samba_player_key,
|
19
|
+
:samba_access_token,
|
20
|
+
:samba_project_id,
|
21
|
+
:terms_of_use,
|
22
|
+
:facebook,
|
23
|
+
:twitter,
|
24
|
+
:linkedin,
|
25
|
+
:pinterest,
|
26
|
+
:google_plus,
|
27
|
+
:youtube,
|
28
|
+
:instagram,
|
29
|
+
:site,
|
30
|
+
:address,
|
31
|
+
:company_name,
|
32
|
+
:seo_title,
|
33
|
+
:seo_description,
|
34
|
+
:logo,
|
35
|
+
:metadata,
|
36
|
+
:meta_available_locales,
|
37
|
+
:event,
|
38
|
+
:created_at,
|
39
|
+
:updated_at
|
40
|
+
)
|
41
|
+
|
42
|
+
SCHOOL_URL_CREATE = 'https://core.myedools.info/api/schools/wizard'
|
43
|
+
SCHOOL_URL_UPDATE = 'https://core.myedools.info/api/schools/'
|
44
|
+
private_constant :SCHOOL_URL_CREATE, :SCHOOL_URL_UPDATE
|
45
|
+
|
46
|
+
def initialize
|
47
|
+
@id = nil
|
48
|
+
@credentials = nil
|
49
|
+
@name = nil
|
50
|
+
@password = nil
|
51
|
+
@subdomain = nil
|
52
|
+
@domains = nil
|
53
|
+
@rdstation_token = nil
|
54
|
+
@adroll_adv_id = nil
|
55
|
+
@adroll_pix_id = nil
|
56
|
+
@email = nil
|
57
|
+
@phone = nil
|
58
|
+
@cnpj = nil
|
59
|
+
@samba_key = nil
|
60
|
+
@samba_player_key = nil
|
61
|
+
@samba_access_token = nil
|
62
|
+
@samba_project_id = nil
|
63
|
+
@terms_of_use = nil
|
64
|
+
@adroll_adv_id = nil
|
65
|
+
@adroll_pix_id = nil
|
66
|
+
@facebook = nil
|
67
|
+
@twitter = nil
|
68
|
+
@linkedin = nil
|
69
|
+
@pinterest = nil
|
70
|
+
@google_plus = nil
|
71
|
+
@youtube = nil
|
72
|
+
@instagram = nil
|
73
|
+
@site = nil
|
74
|
+
@address = nil
|
75
|
+
@company_name = nil
|
76
|
+
@seo_title = nil
|
77
|
+
@seo_description = nil
|
78
|
+
@logo = nil
|
79
|
+
@metadata = nil
|
80
|
+
@meta_available_locales = nil
|
81
|
+
@event = nil
|
82
|
+
@created_at = nil
|
83
|
+
@updated_at = nil
|
84
|
+
end
|
85
|
+
|
86
|
+
# Parse json to School object
|
87
|
+
def self.parse_json(props)
|
88
|
+
school = School.new
|
89
|
+
|
90
|
+
school.id = props['id']
|
91
|
+
school.name = props['name']
|
92
|
+
school.password = props['password']
|
93
|
+
school.subdomain = props['subdomain']
|
94
|
+
school.domains = props['domains']
|
95
|
+
school.rdstation_token = props['rdstation_token']
|
96
|
+
school.adroll_adv_id = props['adroll_adv_id']
|
97
|
+
school.adroll_pix_id = props['adroll_pix_id']
|
98
|
+
school.email = props['email']
|
99
|
+
school.phone = props['phone']
|
100
|
+
school.cnpj = props['cnpj']
|
101
|
+
school.samba_key = props['samba_key']
|
102
|
+
school.samba_player_key = props['samba_player_key']
|
103
|
+
school.samba_access_token = props['samba_access_token']
|
104
|
+
school.samba_project_id = props['samba_project_id']
|
105
|
+
school.terms_of_use = props['terms_of_use']
|
106
|
+
school.adroll_adv_id = props['adroll_adv_id']
|
107
|
+
school.adroll_pix_id = props['adroll_pix_id']
|
108
|
+
school.facebook = props['facebook']
|
109
|
+
school.twitter = props['twitter']
|
110
|
+
school.linkedin = props['linkedin']
|
111
|
+
school.pinterest = props['pinterest']
|
112
|
+
school.google_plus = props['google_plus']
|
113
|
+
school.youtube = props['youtube']
|
114
|
+
school.instagram = props['instagram']
|
115
|
+
school.site = props['site']
|
116
|
+
school.address = props['address']
|
117
|
+
school.company_name = props['company_name']
|
118
|
+
school.seo_title = props['seo_title']
|
119
|
+
school.seo_description = props['seo_description']
|
120
|
+
school.logo = props['logo']
|
121
|
+
school.metadata = props['metadata']
|
122
|
+
school.meta_available_locales = props['meta_available_locales']
|
123
|
+
school.event = props['event']
|
124
|
+
|
125
|
+
unless props['created_at'].nil?
|
126
|
+
school.created_at = Date.parse(props['created_at'])
|
127
|
+
end
|
128
|
+
unless props['updated_at'].nil?
|
129
|
+
school.updated_at = Date.parse(props['updated_at'])
|
130
|
+
end
|
131
|
+
|
132
|
+
school
|
133
|
+
end
|
134
|
+
|
135
|
+
# Parse created json to School object
|
136
|
+
def self.parse_json_created(props)
|
137
|
+
school = School.new
|
138
|
+
|
139
|
+
school.id = props['school']['id']
|
140
|
+
school.credentials = props['admin']['credentials']
|
141
|
+
|
142
|
+
school
|
143
|
+
end
|
144
|
+
|
145
|
+
# Create a School, if anything goes wrong an exception will be raised
|
146
|
+
# Just id and name are populated after create
|
147
|
+
#
|
148
|
+
# Example:
|
149
|
+
# >> School.create!(token, "name" => "test")
|
150
|
+
# => #<EdoolsSdk::School:0x0000000234d350 @id=nil, @credentials=nil, @name="test", @password=nil, @subdomain=nil, @domains=nil, @rdstation_token=nil, @adroll_adv_id=nil, @adroll_pix_id=nil, @email=nil, @phone=nil, @cnpj=nil, @samba_key=nil, @samba_player_key=nil, @samba_access_token=nil, @samba_project_id=nil, @terms_of_use=nil, @facebook=nil, @twitter=nil, @linkedin=nil, @pinterest=nil, @google_plus=nil, @youtube=nil, @instagram=nil, @site=nil, @address=nil, @company_name=nil, @seo_title=nil, @seo_description=nil, @logo=nil, @metadata=nil, @meta_available_locales=nil, @event=nil, @created_at=nil, @updated_at=nil>
|
151
|
+
def self.create!(token, props)
|
152
|
+
response = HTTP
|
153
|
+
.headers('Authorization' => "Token token=\"#{token}\"")
|
154
|
+
.post(SCHOOL_URL_CREATE, :json => props)
|
155
|
+
|
156
|
+
raise "invalid status code #{response.status}" if response.status != 201
|
157
|
+
|
158
|
+
body = response.parse(:json)
|
159
|
+
|
160
|
+
School.parse_json_created(body)
|
161
|
+
end
|
162
|
+
|
163
|
+
# Create a School
|
164
|
+
# Just id and name are populated after create
|
165
|
+
#
|
166
|
+
# Example:
|
167
|
+
# >> School.create(token, "name" => "test")
|
168
|
+
# => #<EdoolsSdk::School:0x0000000234d350 @id=nil, @credentials=nil, @name="test", @password=nil, @subdomain=nil, @domains=nil, @rdstation_token=nil, @adroll_adv_id=nil, @adroll_pix_id=nil, @email=nil, @phone=nil, @cnpj=nil, @samba_key=nil, @samba_player_key=nil, @samba_access_token=nil, @samba_project_id=nil, @terms_of_use=nil, @facebook=nil, @twitter=nil, @linkedin=nil, @pinterest=nil, @google_plus=nil, @youtube=nil, @instagram=nil, @site=nil, @address=nil, @company_name=nil, @seo_title=nil, @seo_description=nil, @logo=nil, @metadata=nil, @meta_available_locales=nil, @event=nil, @created_at=nil, @updated_at=nil>
|
169
|
+
def self.create(token, props)
|
170
|
+
response = HTTP
|
171
|
+
.headers('Authorization' => "Token token=\"#{token}\"")
|
172
|
+
.post(SCHOOL_URL_CREATE, :json => props)
|
173
|
+
|
174
|
+
return response if response.status != 201
|
175
|
+
|
176
|
+
body = response.parse(:json)
|
177
|
+
|
178
|
+
School.parse_json_created(body)
|
179
|
+
end
|
180
|
+
|
181
|
+
# Update School by id
|
182
|
+
#
|
183
|
+
# Example:
|
184
|
+
# >> School.update_by_id(22, "name" => "test")
|
185
|
+
# => #<EdoolsSdk::School:0x0000000234d350 @id=nil, @credentials=nil, @name="test", @password=nil, @subdomain=nil, @domains=nil, @rdstation_token=nil, @adroll_adv_id=nil, @adroll_pix_id=nil, @email=nil, @phone=nil, @cnpj=nil, @samba_key=nil, @samba_player_key=nil, @samba_access_token=nil, @samba_project_id=nil, @terms_of_use=nil, @facebook=nil, @twitter=nil, @linkedin=nil, @pinterest=nil, @google_plus=nil, @youtube=nil, @instagram=nil, @site=nil, @address=nil, @company_name=nil, @seo_title=nil, @seo_description=nil, @logo=nil, @metadata=nil, @meta_available_locales=nil, @event=nil, @created_at=nil, @updated_at=nil>
|
186
|
+
def self.update_by_id(id, props)
|
187
|
+
response = HTTP
|
188
|
+
.headers('Authorization' => "Token token=\"#{ENV['edools_token']}\"")
|
189
|
+
.put("#{SCHOOL_URL_UPDATE}#{id}", :json => props)
|
190
|
+
|
191
|
+
return response if response.status != 204
|
192
|
+
|
193
|
+
School.parse_json(props)
|
194
|
+
end
|
195
|
+
|
196
|
+
# Update School by id, if anything goes wrong an exception will be raised
|
197
|
+
#
|
198
|
+
# Example:
|
199
|
+
# >> School.update_by_id!(22, "name" => "test")
|
200
|
+
# => #<EdoolsSdk::School:0x0000000234d350 @id=nil, @credentials=nil, @name="test", @password=nil, @subdomain=nil, @domains=nil, @rdstation_token=nil, @adroll_adv_id=nil, @adroll_pix_id=nil, @email=nil, @phone=nil, @cnpj=nil, @samba_key=nil, @samba_player_key=nil, @samba_access_token=nil, @samba_project_id=nil, @terms_of_use=nil, @facebook=nil, @twitter=nil, @linkedin=nil, @pinterest=nil, @google_plus=nil, @youtube=nil, @instagram=nil, @site=nil, @address=nil, @company_name=nil, @seo_title=nil, @seo_description=nil, @logo=nil, @metadata=nil, @meta_available_locales=nil, @event=nil, @created_at=nil, @updated_at=nil>
|
201
|
+
def self.update_by_id!(id, props)
|
202
|
+
response = HTTP
|
203
|
+
.headers('Authorization' => "Token token=\"#{ENV['edools_token']}\"")
|
204
|
+
.put("#{SCHOOL_URL_UPDATE}#{id}", :json => props)
|
205
|
+
|
206
|
+
raise "invalid status code #{response.status}" if response.status != 204
|
207
|
+
|
208
|
+
School.parse_json(props)
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
@@ -0,0 +1,167 @@
|
|
1
|
+
module EdoolsSdk
|
2
|
+
# Student class
|
3
|
+
class Student
|
4
|
+
attr_accessor(
|
5
|
+
:id,
|
6
|
+
:first_name,
|
7
|
+
:last_name,
|
8
|
+
:email,
|
9
|
+
:password_digest,
|
10
|
+
:cpf,
|
11
|
+
:phone,
|
12
|
+
:skype,
|
13
|
+
:company_name,
|
14
|
+
:company_position,
|
15
|
+
:born_at,
|
16
|
+
:biography,
|
17
|
+
:cover_image_url,
|
18
|
+
:created_at,
|
19
|
+
:updated_at
|
20
|
+
)
|
21
|
+
|
22
|
+
STUDENT_URL = 'https://core.myedools.info/api/students'
|
23
|
+
INVITATION_URL = 'https://core.myedools.info/api/invitations'
|
24
|
+
private_constant :STUDENT_URL, :INVITATION_URL
|
25
|
+
|
26
|
+
# Parse json to Student object
|
27
|
+
def self.parse_json(props)
|
28
|
+
student = Student.new
|
29
|
+
student.id = props['id']
|
30
|
+
student.first_name = props['first_name']
|
31
|
+
student.last_name = props['last_name']
|
32
|
+
student.email = props['email']
|
33
|
+
student.password_digest = props['password_digest']
|
34
|
+
student.cpf = props['cpf']
|
35
|
+
student.phone = props['phone']
|
36
|
+
student.skype = props['skype']
|
37
|
+
student.company_name = props['company_name']
|
38
|
+
student.company_position = props['company_position']
|
39
|
+
student.born_at = props['born_at']
|
40
|
+
student.biography = props['biography']
|
41
|
+
student.cover_image_url = props['cover_image_url']
|
42
|
+
|
43
|
+
unless props['created_at'].nil?
|
44
|
+
student.created_at = Date.parse(props['created_at'])
|
45
|
+
end
|
46
|
+
unless props['updated_at'].nil?
|
47
|
+
student.updated_at = Date.parse(props['updated_at'])
|
48
|
+
end
|
49
|
+
|
50
|
+
student
|
51
|
+
end
|
52
|
+
|
53
|
+
# Get all students
|
54
|
+
#
|
55
|
+
# Example:
|
56
|
+
# >> Student.all
|
57
|
+
# => [#<EdoolsSdk::Student:0x0000000262e1a0 @id=588417, @first_name="test", @last_name=nil, @email="test@test.com", @password_digest=nil, @cpf=nil, @phone=nil, @skype=nil, @company_name=nil, @company_position=nil, @born_at=nil, @biography=nil, @cover_image_url="https://cdn.edools.com/assets/images/users/default.jpeg", @created_at=#<Date: 2017-09-26 ((2458023j,0s,0n),+0s,2299161j)>, @updated_at=#<Date: 2017-09-26 ((2458023j,0s,0n),+0s,2299161j)>>]
|
58
|
+
def self.all
|
59
|
+
response = HTTP
|
60
|
+
.headers('Authorization' => "Token token=\"#{ENV['edools_token']}\"")
|
61
|
+
.get(STUDENT_URL)
|
62
|
+
|
63
|
+
return response if response.status >= 400 && response.status < 600
|
64
|
+
|
65
|
+
body = response.parse(:json)
|
66
|
+
|
67
|
+
body['students'].map { |c| Student.parse_json(c) }
|
68
|
+
end
|
69
|
+
|
70
|
+
# Get all students, if anything goes wrong an exception will be raised
|
71
|
+
#
|
72
|
+
# Example:
|
73
|
+
# >> Student.all
|
74
|
+
# => [#<EdoolsSdk::Student:0x0000000262e1a0 @id=588417, @first_name="test", @last_name=nil, @email="test@test.com", @password_digest=nil, @cpf=nil, @phone=nil, @skype=nil, @company_name=nil, @company_position=nil, @born_at=nil, @biography=nil, @cover_image_url="https://cdn.edools.com/assets/images/users/default.jpeg", @created_at=#<Date: 2017-09-26 ((2458023j,0s,0n),+0s,2299161j)>, @updated_at=#<Date: 2017-09-26 ((2458023j,0s,0n),+0s,2299161j)>>]
|
75
|
+
def self.all!
|
76
|
+
response = HTTP
|
77
|
+
.headers('Authorization' => "Token token=\"#{ENV['edools_token']}\"")
|
78
|
+
.get(STUDENT_URL)
|
79
|
+
|
80
|
+
raise "invalid status code #{response.status}" if response.status >= 400 && response.status < 600
|
81
|
+
|
82
|
+
body = response.parse(:json)
|
83
|
+
|
84
|
+
body['students'].map { |c| Student.parse_json(c) }
|
85
|
+
end
|
86
|
+
|
87
|
+
# Get all students by Product id
|
88
|
+
#
|
89
|
+
# Example:
|
90
|
+
# >> Student.all_by_product_id
|
91
|
+
# => [#<EdoolsSdk::Student:0x0000000262e1a0 @id=588417, @first_name="test", @last_name=nil, @email="test@test.com", @password_digest=nil, @cpf=nil, @phone=nil, @skype=nil, @company_name=nil, @company_position=nil, @born_at=nil, @biography=nil, @cover_image_url="https://cdn.edools.com/assets/images/users/default.jpeg", @created_at=#<Date: 2017-09-26 ((2458023j,0s,0n),+0s,2299161j)>, @updated_at=#<Date: 2017-09-26 ((2458023j,0s,0n),+0s,2299161j)>>]
|
92
|
+
def self.all_by_product_id(id)
|
93
|
+
response = HTTP
|
94
|
+
.headers('Authorization' => "Token token=\"#{ENV['edools_token']}\"")
|
95
|
+
.get("#{STUDENT_URL}?school_product_id=#{id}")
|
96
|
+
|
97
|
+
return response if response.status >= 400 && response.status < 600
|
98
|
+
|
99
|
+
body = response.parse(:json)
|
100
|
+
|
101
|
+
body['students'].map { |c| Student.parse_json(c) }
|
102
|
+
end
|
103
|
+
|
104
|
+
# Get all students by Product id, if anything goes wrong an exception will be raised
|
105
|
+
#
|
106
|
+
# Example:
|
107
|
+
# >> Student.all_by_product_id
|
108
|
+
# => [#<EdoolsSdk::Student:0x0000000262e1a0 @id=588417, @first_name="test", @last_name=nil, @email="test@test.com", @password_digest=nil, @cpf=nil, @phone=nil, @skype=nil, @company_name=nil, @company_position=nil, @born_at=nil, @biography=nil, @cover_image_url="https://cdn.edools.com/assets/images/users/default.jpeg", @created_at=#<Date: 2017-09-26 ((2458023j,0s,0n),+0s,2299161j)>, @updated_at=#<Date: 2017-09-26 ((2458023j,0s,0n),+0s,2299161j)>>]
|
109
|
+
def self.all_by_product_id!(id)
|
110
|
+
response = HTTP
|
111
|
+
.headers('Authorization' => "Token token=\"#{ENV['edools_token']}\"")
|
112
|
+
.get("#{STUDENT_URL}?school_product_id=#{id}")
|
113
|
+
|
114
|
+
raise "invalid status code #{response.status}" if response.status >= 400 && response.status < 600
|
115
|
+
|
116
|
+
body = response.parse(:json)
|
117
|
+
|
118
|
+
body['students'].map { |c| Student.parse_json(c) }
|
119
|
+
end
|
120
|
+
|
121
|
+
# Self invite Student, if anything goes wrong an exception will be raised
|
122
|
+
#
|
123
|
+
# Example:
|
124
|
+
# >> Student.self_invite!
|
125
|
+
# => #<EdoolsSdk::Invitation>
|
126
|
+
def self_invite!(password, confirm_password)
|
127
|
+
response = HTTP
|
128
|
+
.headers('Authorization' => "Token token=\"#{ENV['edools_token']}\"")
|
129
|
+
.post(INVITATION_URL, :json => {
|
130
|
+
'first_name' => @first_name,
|
131
|
+
'last_name' => @last_name,
|
132
|
+
'email' => @email,
|
133
|
+
'password' => password,
|
134
|
+
'confirm_password' => confirm_password,
|
135
|
+
})
|
136
|
+
|
137
|
+
raise "invalid status code #{response.status}" if response.status >= 400 && response.status < 600
|
138
|
+
|
139
|
+
body = response.parse(:json)
|
140
|
+
|
141
|
+
Invitation.parse_json(body)
|
142
|
+
end
|
143
|
+
|
144
|
+
# Self invite Student
|
145
|
+
#
|
146
|
+
# Example:
|
147
|
+
# >> Student.self_invite
|
148
|
+
# => #<EdoolsSdk::Invitation>
|
149
|
+
def self_invite(password, confirm_password)
|
150
|
+
response = HTTP
|
151
|
+
.headers('Authorization' => "Token token=\"#{ENV['edools_token']}\"")
|
152
|
+
.post(INVITATION_URL, :json => {
|
153
|
+
'first_name' => @first_name,
|
154
|
+
'last_name' => @last_name,
|
155
|
+
'email' => @email,
|
156
|
+
'password' => password,
|
157
|
+
'confirm_password' => confirm_password,
|
158
|
+
})
|
159
|
+
|
160
|
+
return response if response.status >= 400 && response.status < 600
|
161
|
+
|
162
|
+
body = response.parse(:json)
|
163
|
+
|
164
|
+
Invitation.parse_json(body)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: edools_sdk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lucas Vieira
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: http
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.2'
|
27
|
+
description: A simple sdk to access edools platform.
|
28
|
+
email: lucasvieira.dev@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/edools_sdk.rb
|
34
|
+
- lib/edools_sdk/course.rb
|
35
|
+
- lib/edools_sdk/edools_base.rb
|
36
|
+
- lib/edools_sdk/invitation.rb
|
37
|
+
- lib/edools_sdk/product.rb
|
38
|
+
- lib/edools_sdk/school.rb
|
39
|
+
- lib/edools_sdk/student.rb
|
40
|
+
homepage: http://rubygems.org/gems/edools_sdk
|
41
|
+
licenses:
|
42
|
+
- MIT
|
43
|
+
metadata: {}
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 2.5.2
|
61
|
+
signing_key:
|
62
|
+
specification_version: 4
|
63
|
+
summary: SDK for edools platform.
|
64
|
+
test_files: []
|