Class: EdoolsSdk::Student

Inherits:
Object
  • Object
show all
Defined in:
lib/edools_sdk/student.rb

Overview

Student class

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#biographyObject

Returns the value of attribute biography.



4
5
6
# File 'lib/edools_sdk/student.rb', line 4

def biography
  @biography
end

#born_atObject

Returns the value of attribute born_at.



4
5
6
# File 'lib/edools_sdk/student.rb', line 4

def born_at
  @born_at
end

#company_nameObject

Returns the value of attribute company_name.



4
5
6
# File 'lib/edools_sdk/student.rb', line 4

def company_name
  @company_name
end

#company_positionObject

Returns the value of attribute company_position.



4
5
6
# File 'lib/edools_sdk/student.rb', line 4

def company_position
  @company_position
end

#cover_image_urlObject

Returns the value of attribute cover_image_url.



4
5
6
# File 'lib/edools_sdk/student.rb', line 4

def cover_image_url
  @cover_image_url
end

#cpfObject

Returns the value of attribute cpf.



4
5
6
# File 'lib/edools_sdk/student.rb', line 4

def cpf
  @cpf
end

#created_atObject

Returns the value of attribute created_at.



4
5
6
# File 'lib/edools_sdk/student.rb', line 4

def created_at
  @created_at
end

#emailObject

Returns the value of attribute email.



4
5
6
# File 'lib/edools_sdk/student.rb', line 4

def email
  @email
end

#first_nameObject

Returns the value of attribute first_name.



4
5
6
# File 'lib/edools_sdk/student.rb', line 4

def first_name
  @first_name
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/edools_sdk/student.rb', line 4

def id
  @id
end

#last_nameObject

Returns the value of attribute last_name.



4
5
6
# File 'lib/edools_sdk/student.rb', line 4

def last_name
  @last_name
end

#password_digestObject

Returns the value of attribute password_digest.



4
5
6
# File 'lib/edools_sdk/student.rb', line 4

def password_digest
  @password_digest
end

#phoneObject

Returns the value of attribute phone.



4
5
6
# File 'lib/edools_sdk/student.rb', line 4

def phone
  @phone
end

#skypeObject

Returns the value of attribute skype.



4
5
6
# File 'lib/edools_sdk/student.rb', line 4

def skype
  @skype
end

#updated_atObject

Returns the value of attribute updated_at.



4
5
6
# File 'lib/edools_sdk/student.rb', line 4

def updated_at
  @updated_at
end

Class Method Details

.allObject

Get all students

Example:

>> Student.all
=> [#<EdoolsSdk::Student:0x0000000262e1a0 @id=588417, @first_name="test", @last_name=nil, @email="[email protected]", @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
59
60
61
62
63
64
65
66
67
68
# File 'lib/edools_sdk/student.rb', line 58

def self.all
  response = HTTP
    .headers('Authorization' => "Token token=\"#{ENV['edools_token']}\"")
    .get(STUDENT_URL)

  return response if response.status >= 400 && response.status < 600

  body = response.parse(:json)

  body['students'].map { |c| Student.parse_json(c) }
end

.all!Object

Get all students, if anything goes wrong an exception will be raised

Example:

>> Student.all
=> [#<EdoolsSdk::Student:0x0000000262e1a0 @id=588417, @first_name="test", @last_name=nil, @email="[email protected]", @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
76
77
78
79
80
81
82
83
84
85
# File 'lib/edools_sdk/student.rb', line 75

def self.all!
  response = HTTP
    .headers('Authorization' => "Token token=\"#{ENV['edools_token']}\"")
    .get(STUDENT_URL)

  raise "invalid status code #{response.status}" if response.status >= 400 && response.status < 600

  body = response.parse(:json)

  body['students'].map { |c| Student.parse_json(c) }
end

.all_by_product_id(id) ⇒ Object

Get all students by Product id

Example:

>> Student.all_by_product_id
=> [#<EdoolsSdk::Student:0x0000000262e1a0 @id=588417, @first_name="test", @last_name=nil, @email="[email protected]", @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
93
94
95
96
97
98
99
100
101
102
# File 'lib/edools_sdk/student.rb', line 92

def self.all_by_product_id(id)
  response = HTTP
    .headers('Authorization' => "Token token=\"#{ENV['edools_token']}\"")
    .get("#{STUDENT_URL}?school_product_id=#{id}")

  return response if response.status >= 400 && response.status < 600

  body = response.parse(:json)

  body['students'].map { |c| Student.parse_json(c) }
end

.all_by_product_id!(id) ⇒ Object

Get all students by Product id, if anything goes wrong an exception will be raised

Example:

>> Student.all_by_product_id
=> [#<EdoolsSdk::Student:0x0000000262e1a0 @id=588417, @first_name="test", @last_name=nil, @email="[email protected]", @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
110
111
112
113
114
115
116
117
118
119
# File 'lib/edools_sdk/student.rb', line 109

def self.all_by_product_id!(id)
  response = HTTP
    .headers('Authorization' => "Token token=\"#{ENV['edools_token']}\"")
    .get("#{STUDENT_URL}?school_product_id=#{id}")

  raise "invalid status code #{response.status}" if response.status >= 400 && response.status < 600

  body = response.parse(:json)

  body['students'].map { |c| Student.parse_json(c) }
end

.parse_json(props) ⇒ Object

Parse json to Student object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/edools_sdk/student.rb', line 27

def self.parse_json(props)
  student = Student.new
  student.id = props['id']
  student.first_name = props['first_name']
  student.last_name = props['last_name']
  student.email = props['email']
  student.password_digest = props['password_digest']
  student.cpf = props['cpf']
  student.phone = props['phone']
  student.skype = props['skype']
  student.company_name = props['company_name']
  student.company_position = props['company_position']
  student.born_at = props['born_at']
  student.biography = props['biography']
  student.cover_image_url = props['cover_image_url']

  unless props['created_at'].nil?
    student.created_at = Date.parse(props['created_at'])
  end
  unless props['updated_at'].nil?
    student.updated_at = Date.parse(props['updated_at'])
  end

  student
end

Instance Method Details

#self_invite(password, confirm_password) ⇒ Object

Self invite Student

Example:

>> Student.self_invite
=> #<EdoolsSdk::Invitation>


149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/edools_sdk/student.rb', line 149

def self_invite(password, confirm_password)
  response = HTTP
    .headers('Authorization' => "Token token=\"#{ENV['edools_token']}\"")
    .post(INVITATION_URL, :json => {
      'first_name' => @first_name, 
      'last_name' => @last_name, 
      'email' => @email,
      'password' => password,
      'confirm_password' => confirm_password,
    })

  return response if response.status >= 400 && response.status < 600

  body = response.parse(:json)

  Invitation.parse_json(body)
end

#self_invite!(password, confirm_password) ⇒ Object

Self invite Student, if anything goes wrong an exception will be raised

Example:

>> Student.self_invite!
=> #<EdoolsSdk::Invitation>


126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/edools_sdk/student.rb', line 126

def self_invite!(password, confirm_password)
  response = HTTP
    .headers('Authorization' => "Token token=\"#{ENV['edools_token']}\"")
    .post(INVITATION_URL, :json => {
      'first_name' => @first_name, 
      'last_name' => @last_name, 
      'email' => @email,
      'password' => password,
      'confirm_password' => confirm_password,
    })

  raise "invalid status code #{response.status}" if response.status >= 400 && response.status < 600

  body = response.parse(:json)

  Invitation.parse_json(body)
end