Class: Kele

Inherits:
Object
  • Object
show all
Includes:
HTTParty, Roadmap
Defined in:
lib/kele_wyll.rb

Instance Method Summary collapse

Methods included from Roadmap

#get_checkpoint, #get_roadmap

Constructor Details

#initialize(email, password) ⇒ Kele

Returns a new instance of Kele.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/kele_wyll.rb', line 11

def initialize(email, password)
  @email = email
  
  response = self.class.post('/sessions', body: {
    email: @email, 
    password: password
  })
  
  if response.success?
    @auth_token = response['auth_token']
    @enrollment_id = get_me["current_enrollment"]["id"]
    @mentor_id = get_me["current_enrollment"]["mentor_id"]
  else
    raise "Invalid username or password. Please try again"
  end
end

Instance Method Details

#create_message(subject, text, recipient = @mentor_id) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/kele_wyll.rb', line 64

def create_message(subject, text, recipient=@mentor_id)
  response = self.class.post("/messages", headers: { "authorization" => @auth_token }, body: { 
    "sender" => @email,
    "recipient_id" => recipient,
    "subject" => subject,
    "stripped-text" => text
  }) 
  
  if response.success?
    "Message sent." 
  else
    raise "There was and error sending the message. Please try again."
  end
end

#create_submission(checkpoint_id, assignment_branch, assignment_commit_link, comment) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/kele_wyll.rb', line 79

def create_submission(checkpoint_id, assignment_branch, assignment_commit_link, comment)
  response = self.class.post("/checkpoint_submissions", headers: { "authorization" => @auth_token }, body: { 
    "checkpoint_id" => checkpoint_id,
    "assignment_branch" => assignment_branch,
    "assignment_commit_link" => assignment_commit_link,
    "comment" => comment,
    "enrollment_id" => @enrollment_id
  }) 
  
  if response.success?
    "Checkpoint submitted." 
  else
    raise "There was and error submitting the checkpoint. Please try again."
  end
end

#get_meObject



28
29
30
31
32
33
34
35
36
# File 'lib/kele_wyll.rb', line 28

def get_me
  response = self.class.get('/users/me', headers: { "authorization" => @auth_token })
  
  if response.success?
    JSON.parse(response.body)
  else
    raise response.response
  end
end

#get_mentor_availabilityObject



38
39
40
41
42
43
44
45
46
# File 'lib/kele_wyll.rb', line 38

def get_mentor_availability
  response = self.class.get("/mentors/#{@mentor_id}/student_availability", headers: { "authorization" => @auth_token })
  
  if response.success?
    JSON.parse(response.body)
  else
    raise response.response
  end
end

#get_messages(page_number = 0) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/kele_wyll.rb', line 48

def get_messages(page_number=0)
  if page_number == 0
    url = "/message_threads"
    response = self.class.get(url, headers: { "authorization" => @auth_token })
  else
    url = "/message_threads?page=#{page_number}"
    response = self.class.get(url, headers: { "authorization" => @auth_token }, body: { page: page_number }) 
  end
  
  if response.success?
    JSON.parse(response.body)
  else
    raise response.response
  end
end