-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathapi_client.rb
40 lines (33 loc) · 985 Bytes
/
api_client.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
module KOSapiClient
class ApiClient
include ResourceMapper
# accessible resources definition
resource :courses
resource :course_events
resource :parallels
resource :exams
attr_reader :http_client
##
# Creates a new KOSapi client.
#
def initialize(config)
http_adapter = OAuth2HttpAdapter.new(config.credentials, config.base_url)
@http_client = HTTPClient.new(http_adapter)
end
def create_builder(resource_name)
builder_name = "#{resource_name}_builder".camelize.to_sym
builder_class = find_builder_class(builder_name)
builder_class.new(resource_name.to_s.camelize(:lower), @http_client)
end
private
def find_builder_class(builder_name)
KOSapiClient::Resource.constants.each do |m|
constant = KOSapiClient::Resource.const_get(m)
if constant.is_a?(Class) && m == builder_name
return constant
end
end
RequestBuilder
end
end
end