Class: Billimatic::Resources::Base
- Inherits:
-
Object
- Object
- Billimatic::Resources::Base
show all
- Extended by:
- Hooks
- Includes:
- Wisper::Publisher
- Defined in:
- lib/billimatic/resources/base.rb
Direct Known Subclasses
Company, Contract, EmailTemplate, InvoiceRule, InvoiceTemplate, Organization, Person, Plan, ServiceItem, Subscription, 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/billimatic/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/billimatic/resources/base.rb', line 8
def http
@http
end
|
Class Method Details
.crud(*args) ⇒ Object
10
11
12
|
# File 'lib/billimatic/resources/base.rb', line 10
def self.crud(*args)
@crud ||= args
end
|
Instance Method Details
#collection_name ⇒ Object
18
19
20
|
# File 'lib/billimatic/resources/base.rb', line 18
def collection_name
@collection_name ||= underscore_pluralized_klass_name
end
|
#create(params) ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/billimatic/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
64
65
66
67
68
69
70
|
# File 'lib/billimatic/resources/base.rb', line 64
def destroy(id)
crud_request do
http.delete("#{resource_base_path}/#{id}") do |response|
response.code == 204
end
end
end
|
#list ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/billimatic/resources/base.rb', line 44
def list
crud_request do
http.get(resource_base_path) do |response|
respond_with_collection(response)
end
end
end
|
#list_by_organization(id) ⇒ Object
52
53
54
55
56
|
# File 'lib/billimatic/resources/base.rb', line 52
def list_by_organization(id)
http.get("/organizations/#{id}#{resource_base_path}") do |response|
respond_with_collection response
end
end
|
#parsed_body(response) ⇒ Object
22
23
24
25
26
|
# File 'lib/billimatic/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/billimatic/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
|
#show_by_organization(organization_id, entity_id) ⇒ Object
58
59
60
61
62
|
# File 'lib/billimatic/resources/base.rb', line 58
def show_by_organization(organization_id, entity_id)
http.get(
"/organizations/#{organization_id}#{resource_base_path}/#{entity_id}"
) { |response| respond_with_entity response }
end
|
#update(id, params) ⇒ Object
72
73
74
75
76
77
78
|
# File 'lib/billimatic/resources/base.rb', line 72
def update(id, params)
crud_request do
http.put("#{resource_base_path}/#{id}", { body: params }) do |response|
respond_with_entity(response)
end
end
end
|