Class: Bloc::Client::Enrollment

Inherits:
Object
  • Object
show all
Defined in:
lib/bloc/client/enrollment.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Enrollment

Returns a new instance of Enrollment.



16
17
18
# File 'lib/bloc/client/enrollment.rb', line 16

def initialize(attributes)
  @attributes = attributes
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/bloc/client/enrollment.rb', line 29

def method_missing(method)
  method = method.to_s

  if @attributes[method]
    return @attributes[method]
  else
    super(method)
  end
end

Class Method Details

.create(attributes) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/bloc/client/enrollment.rb', line 4

def self.create(attributes)
  raise "Must Provide a Course Id" unless attributes[:course_id]
  course_id = attributes.delete(:course_id)

  response = RestClient.post("http://www.trybloc.com/api/v1/courses/#{course_id}/enrollments", {
    :enrollment => attributes,
    :api_key => Bloc::Client.credentials["api_key"]
  })

  self.new JSON.parse(response.body)
end

Instance Method Details

#update(attributes) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/bloc/client/enrollment.rb', line 20

def update(attributes)
  response = RestClient.put("http://www.trybloc.com/api/v1/courses/#{course_id}/enrollments/#{id}",  {
    :enrollment => attributes,
    :api_key => Bloc::Client.credentials["api_key"]
  })

  @attributes = JSON.parse(response.body)
end