Module: Beze
- Defined in:
- lib/beze/client.rb,
lib/beze.rb,
lib/beze/version.rb,
lib/beze/http_client.rb
Overview
Ruby gem that helps you work with Bezefy API.
Defined Under Namespace
Classes: Client, HttpClient
Constant Summary
collapse
- BASE_URL =
ENV.fetch('API_BASE_URL') || "http://localhost:3000"
- VERSION =
"0.1.0"
Class Method Summary
collapse
-
.configuration ⇒ Object
-
.configure {|configuration| ... } ⇒ Object
-
.create_resource(resource, payload, options) ⇒ Object
-
.delete_resource(resource, payload, options) ⇒ Object
-
.get_resource(resource, payload, options) ⇒ Object
-
.hash_or_array(val) ⇒ Object
-
.list_resource(resource, payload, options) ⇒ Object
-
.patch_resource(resource, payload, options) ⇒ Object
-
.to_ostruct(input) ⇒ Object
-
.update_resource(resource, payload, options) ⇒ Object
Class Method Details
.configuration ⇒ Object
16
17
18
|
# File 'lib/beze.rb', line 16
def self.configuration
@configuration ||= OpenStruct.new(api_version: nil, app_email: nil, app_password: nil)
end
|
12
13
14
|
# File 'lib/beze.rb', line 12
def self.configure
yield configuration
end
|
.create_resource(resource, payload, options) ⇒ Object
20
21
22
|
# File 'lib/beze.rb', line 20
def self.create_resource(resource, payload, options)
Beze::Client.call(resource: resource, payload: payload, options: options, method: :post)
end
|
.delete_resource(resource, payload, options) ⇒ Object
40
41
42
|
# File 'lib/beze.rb', line 40
def self.delete_resource(resource, payload, options)
Beze::Client.call(resource: resource, payload: payload, options: options, method: :delete)
end
|
.get_resource(resource, payload, options) ⇒ Object
24
25
26
|
# File 'lib/beze.rb', line 24
def self.get_resource(resource, payload, options)
Beze::Client.call(resource: resource, payload: payload, options: options, method: :get)
end
|
.hash_or_array(val) ⇒ Object
68
69
70
|
# File 'lib/beze.rb', line 68
def self.hash_or_array(val)
val.is_a?(Hash) || val.is_a?(Array)
end
|
.list_resource(resource, payload, options) ⇒ Object
28
29
30
|
# File 'lib/beze.rb', line 28
def self.list_resource(resource, payload, options)
Beze::Client.call(resource: resource, payload: payload, options: options, method: :get)
end
|
.patch_resource(resource, payload, options) ⇒ Object
36
37
38
|
# File 'lib/beze.rb', line 36
def self.patch_resource(resource, payload, options)
Beze::Client.call(resource: resource, payload: payload, options: options, method: :patch)
end
|
.to_ostruct(input) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/beze.rb', line 44
def self.to_ostruct(input)
result = {}
if input.is_a?(Hash)
result["type"] = input.class
result["keys"] = input.keys
input.each do |key, value|
result[key] = hash_or_array(value) ? to_ostruct(value) : OpenStruct.new(value: value, type: value.class)
end
end
if input.is_a?(Array)
result["type"] = input.class
result["size"] = input.size
input.each.with_index do |value, index|
result["value_at_#{index}"] = hash_or_array(value) ? to_ostruct(value) : OpenStruct.new(value: value, type: value.class)
end
end
OpenStruct.new(result)
end
|
.update_resource(resource, payload, options) ⇒ Object
32
33
34
|
# File 'lib/beze.rb', line 32
def self.update_resource(resource, payload, options)
Beze::Client.call(resource: resource, payload: payload, options: options, method: :put)
end
|