Class: Clowk::SDK::Client
- Inherits:
-
Object
- Object
- Clowk::SDK::Client
show all
- Defined in:
- lib/clowk/sdk/client.rb
Instance Method Summary
collapse
-
#delete(path, body = nil, headers: {}) ⇒ Object
-
#get(path, headers: {}) ⇒ Object
-
#head(path, headers: {}) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
-
#method_missing(method_name) ⇒ Object
-
#options(path, headers: {}) ⇒ Object
-
#patch(path, body = {}, headers: {}) ⇒ Object
-
#post(path, body = {}, headers: {}) ⇒ Object
-
#put(path, body = {}, headers: {}) ⇒ Object
-
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
8
9
10
11
12
|
# File 'lib/clowk/sdk/client.rb', line 8
def initialize(options = {})
@api_base_url = options.fetch(:api_base_url, nil).presence || Clowk.config.api_base_url
@secret_key = options.fetch(:secret_key, Clowk.config.secret_key)
@publishable_key = options.fetch(:publishable_key, Clowk.config.publishable_key)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/clowk/sdk/client.rb', line 14
def method_missing(method_name, *, **, &)
resource_class_name = ActiveSupport::Inflector.camelize(
ActiveSupport::Inflector.singularize(method_name.to_s)
)
return super unless Clowk::SDK.const_defined?(resource_class_name)
resource_ivar = :"@#{resource_class_name}"
return instance_variable_get(resource_ivar) if instance_variable_defined?(resource_ivar)
resource_class = Clowk::SDK.const_get(resource_class_name)
instance_variable_set(resource_ivar, resource_class.new(self))
end
|
Instance Method Details
#delete(path, body = nil, headers: {}) ⇒ Object
36
37
38
|
# File 'lib/clowk/sdk/client.rb', line 36
def delete(path, body = nil, headers: {})
http.delete(path, body, headers:)
end
|
#get(path, headers: {}) ⇒ Object
44
45
46
|
# File 'lib/clowk/sdk/client.rb', line 44
def get(path, headers: {})
http.get(path, headers:)
end
|
#head(path, headers: {}) ⇒ Object
56
57
58
|
# File 'lib/clowk/sdk/client.rb', line 56
def head(path, headers: {})
http.head(path, headers:)
end
|
#options(path, headers: {}) ⇒ Object
60
61
62
|
# File 'lib/clowk/sdk/client.rb', line 60
def options(path, headers: {})
http.options(path, headers:)
end
|
#patch(path, body = {}, headers: {}) ⇒ Object
40
41
42
|
# File 'lib/clowk/sdk/client.rb', line 40
def patch(path, body = {}, headers: {})
http.patch(path, body, headers:)
end
|
#post(path, body = {}, headers: {}) ⇒ Object
48
49
50
|
# File 'lib/clowk/sdk/client.rb', line 48
def post(path, body = {}, headers: {})
http.post(path, body, headers:)
end
|
#put(path, body = {}, headers: {}) ⇒ Object
52
53
54
|
# File 'lib/clowk/sdk/client.rb', line 52
def put(path, body = {}, headers: {})
http.put(path, body, headers:)
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
28
29
30
31
32
33
34
|
# File 'lib/clowk/sdk/client.rb', line 28
def respond_to_missing?(method_name, include_private = false)
resource_class_name = ActiveSupport::Inflector.camelize(
ActiveSupport::Inflector.singularize(method_name.to_s)
)
Clowk::SDK.const_defined?(resource_class_name) || super
end
|