Class: Cobrato::Resources::Base
- Inherits:
-
Object
- Object
- Cobrato::Resources::Base
show all
- Extended by:
- Hooks
- Includes:
- Wisper::Publisher
- Defined in:
- lib/cobrato/resources/base.rb
Direct Known Subclasses
BankAccount, Charge, ChargeConfig, ChargeTemplate, ChargingType, CreditCard, Payee, Payer, Payment, PaymentConfig, PaymentMethod, Person, RegressCnab, RemittanceCnab, Webhook
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Hooks
notify
Constructor Details
#initialize(http) ⇒ Base
Returns a new instance of Base.
14
15
16
|
# File 'lib/cobrato/resources/base.rb', line 14
def initialize(http)
@http = http
end
|
Instance Attribute Details
#http ⇒ Object
Returns the value of attribute http.
8
9
10
|
# File 'lib/cobrato/resources/base.rb', line 8
def http
@http
end
|
Class Method Details
.crud(*args) ⇒ Object
10
11
12
|
# File 'lib/cobrato/resources/base.rb', line 10
def self.crud(*args)
@crud ||= args
end
|
Instance Method Details
#collection_name ⇒ Object
18
19
20
|
# File 'lib/cobrato/resources/base.rb', line 18
def collection_name
@collection_name ||= underscore_pluralized(base_klass)
end
|
#create(params) ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/cobrato/resources/base.rb', line 28
def create(params)
crud_request do
http.post(resource_base_path, body: params) do |response|
respond_with_entity(response)
end
end
end
|
#destroy(id) ⇒ Object
52
53
54
55
56
57
58
|
# File 'lib/cobrato/resources/base.rb', line 52
def destroy(id)
crud_request do
http.delete("#{resource_base_path}/#{id}") do |response|
response.code == 204
end
end
end
|
#list(params = {}) ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/cobrato/resources/base.rb', line 44
def list(params={})
crud_request do
http.get(resource_base_path, params: params) do |response|
respond_with_collection(response)
end
end
end
|
#parsed_body(response) ⇒ Object
22
23
24
25
26
|
# File 'lib/cobrato/resources/base.rb', line 22
def parsed_body(response)
MultiJson.load(response.body)
rescue MultiJson::ParseError
{}
end
|
#show(id) ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/cobrato/resources/base.rb', line 36
def show(id)
crud_request do
http.get("#{resource_base_path}/#{id}") do |response|
respond_with_entity(response)
end
end
end
|
#update(id, params) ⇒ Object
60
61
62
63
64
65
66
|
# File 'lib/cobrato/resources/base.rb', line 60
def update(id, params)
crud_request do
http.put("#{resource_base_path}/#{id}", body: params) do |response|
respond_with_entity(response)
end
end
end
|