Class: ThreeScaleToolbox::Entities::Limit
- Inherits:
-
Object
- Object
- ThreeScaleToolbox::Entities::Limit
show all
- Includes:
- CRD::Limit
- Defined in:
- lib/3scale_toolbox/entities/limit.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from CRD::Limit
#metric_system_name, #to_cr
Constructor Details
#initialize(id:, plan:, metric_id:, attrs:) ⇒ Limit
Returns a new instance of Limit.
19
20
21
22
23
24
25
|
# File 'lib/3scale_toolbox/entities/limit.rb', line 19
def initialize(id:, plan:, metric_id:, attrs:)
@id = id.to_i
@plan = plan
@remote = plan.remote
@metric_id = metric_id
@attrs = attrs
end
|
Instance Attribute Details
#attrs ⇒ Object
Returns the value of attribute attrs.
17
18
19
|
# File 'lib/3scale_toolbox/entities/limit.rb', line 17
def attrs
@attrs
end
|
#id ⇒ Object
Returns the value of attribute id.
17
18
19
|
# File 'lib/3scale_toolbox/entities/limit.rb', line 17
def id
@id
end
|
#metric_id ⇒ Object
Returns the value of attribute metric_id.
17
18
19
|
# File 'lib/3scale_toolbox/entities/limit.rb', line 17
def metric_id
@metric_id
end
|
#plan ⇒ Object
Returns the value of attribute plan.
17
18
19
|
# File 'lib/3scale_toolbox/entities/limit.rb', line 17
def plan
@plan
end
|
#remote ⇒ Object
Returns the value of attribute remote.
17
18
19
|
# File 'lib/3scale_toolbox/entities/limit.rb', line 17
def remote
@remote
end
|
Class Method Details
.create(plan:, metric_id:, attrs:) ⇒ Object
7
8
9
10
11
12
13
14
|
# File 'lib/3scale_toolbox/entities/limit.rb', line 7
def create(plan:, metric_id:, attrs:)
resp_attrs = plan.remote.create_application_plan_limit plan.id, metric_id, attrs
if (errors = resp_attrs['errors'])
raise ThreeScaleToolbox::ThreeScaleApiError.new('Limit has not been created', errors)
end
new(id: resp_attrs.fetch('id'), plan: plan, metric_id: metric_id, attrs: resp_attrs)
end
|
Instance Method Details
#delete ⇒ Object
55
56
57
|
# File 'lib/3scale_toolbox/entities/limit.rb', line 55
def delete
remote.delete_application_plan_limit plan.id, metric_id, id
end
|
#links ⇒ Object
35
36
37
|
# File 'lib/3scale_toolbox/entities/limit.rb', line 35
def links
attrs['links'] || []
end
|
#metric_link ⇒ Object
39
40
41
|
# File 'lib/3scale_toolbox/entities/limit.rb', line 39
def metric_link
links.find { |link| link['rel'] == 'metric' }
end
|
#period ⇒ Object
27
28
29
|
# File 'lib/3scale_toolbox/entities/limit.rb', line 27
def period
attrs['period']
end
|
#update(new_limit_attrs) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/3scale_toolbox/entities/limit.rb', line 43
def update(new_limit_attrs)
new_attrs = remote.update_application_plan_limit(plan.id, metric_id, id, new_limit_attrs)
if (errors = new_attrs['errors'])
raise ThreeScaleToolbox::ThreeScaleApiError.new('Limit has not been updated', errors)
end
@attrs = new_attrs
new_attrs
end
|
#value ⇒ Object
31
32
33
|
# File 'lib/3scale_toolbox/entities/limit.rb', line 31
def value
attrs['value']
end
|