Skip to content

Commit c30b363

Browse files
author
Tomáš Polívka
committed
Fixed bad merge
1 parent 90f775f commit c30b363

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

lib/kosapi_client/api_client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ def find_builder_class(builder_name)
3737
end
3838

3939
end
40-
end
40+
end

lib/kosapi_client/kosapi_client.rb

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,45 @@
11
module KOSapiClient
22

3-
DEFAULT_KOSAPI_BASE_URL = 'https://kosapi.fit.cvut.cz/api/3'
4-
53
singleton_class.class_eval do
64

7-
attr_reader :client
8-
9-
alias_method :to_str, :to_s
10-
11-
def new(credentials, base_url = DEFAULT_KOSAPI_BASE_URL)
12-
http_adapter = OAuth2HttpAdapter.new(credentials, base_url)
13-
http_client = HTTPClient.new(http_adapter)
14-
ApiClient.new(http_client, base_url)
5+
def new(options = {})
6+
ApiClient.new(Configuration.new(options))
157
end
168

179
def configure
18-
config = Configuration.new
10+
reset
1911
yield config
20-
@client = new(config.credentials)
12+
self
13+
end
14+
15+
def client
16+
@client ||= ApiClient.new(config)
2117
end
2218

2319
# Calling this method clears stored ApiClient instance
2420
# if configured previously.
2521
def reset
22+
@config = nil
2623
@client = nil
2724
end
2825

2926
def method_missing(method, *args, &block)
30-
if @client.nil?
31-
raise "Client not configured. Either you forgot to call configure or you have typo in method name '#{method}'."
32-
end
33-
if @client.respond_to?(method)
34-
@client.send(method, *args, &block)
27+
if client.respond_to?(method)
28+
client.send(method, *args, &block)
3529
else
3630
super
3731
end
3832
end
3933

4034
def respond_to_missing?(method_name, include_private = false)
41-
@client.respond_to?(method_name, include_private)
35+
client.respond_to?(method_name, include_private)
4236
end
37+
38+
private
39+
def config
40+
@config ||= Configuration.new
41+
end
42+
4343
end
44-
end
44+
45+
end

0 commit comments

Comments
 (0)