Class: ThreeScale::Backend::Transactor::Status
- Inherits:
-
Object
- Object
- ThreeScale::Backend::Transactor::Status
- Defined in:
- lib/3scale/backend/transactor/status.rb,
lib/3scale/backend/transactor/usage_report.rb
Defined Under Namespace
Classes: UsageReport
Instance Attribute Summary collapse
-
#application ⇒ Object
readonly
Returns the value of attribute application.
-
#oauth ⇒ Object
readonly
Returns the value of attribute oauth.
-
#redirect_uri_field ⇒ Object
Returns the value of attribute redirect_uri_field.
-
#rejection_reason_code ⇒ Object
readonly
Returns the value of attribute rejection_reason_code.
-
#rejection_reason_text ⇒ Object
readonly
Returns the value of attribute rejection_reason_text.
-
#service_id ⇒ Object
readonly
Returns the value of attribute service_id.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#values ⇒ Object
Returns the value of attribute values.
Instance Method Summary collapse
-
#actual_or_predicted_usage ⇒ Object
Returns the actual usage.
- #application_usage_reports ⇒ Object
- #authorized? ⇒ Boolean
- #flat_usage ⇒ Object
-
#hierarchy ⇒ Object
provides a hierarchy hash with metrics as symbolic names.
-
#initialize(attributes) ⇒ Status
constructor
A new instance of Status.
- #limit_headers(now = Time.now.utc) ⇒ Object
- #plan_name ⇒ Object
-
#predicted_usage ⇒ Object
Returns the predicted usage of an authorize request.
- #reject!(error) ⇒ Object
- #to_xml(options = {}) ⇒ Object
-
#usage ⇒ Object
Returns the usage to be reported in an authrep request.
- #value_for_usage_limit(usage_limit) ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Status
Returns a new instance of Status.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/3scale/backend/transactor/status.rb', line 17 def initialize(attributes) @service_id = attributes[:service_id] @application = attributes[:application] @oauth = attributes[:oauth] @usage = attributes[:usage] @predicted_usage = attributes[:predicted_usage] @values = filter_values(attributes[:values] || {}) @timestamp = attributes[:timestamp] || Time.now.getutc @hierarchy_ext = attributes[:hierarchy] @flat_usage_ext = attributes[:flat_usage] @list_app_keys_ext = attributes[:list_app_keys] raise 'service_id not specified' if @service_id.nil? raise ':application is required' if @application.nil? @redirect_uri_field = REDIRECT_URI_FIELD @authorized = true end |
Instance Attribute Details
#application ⇒ Object (readonly)
Returns the value of attribute application.
37 38 39 |
# File 'lib/3scale/backend/transactor/status.rb', line 37 def application @application end |
#oauth ⇒ Object (readonly)
Returns the value of attribute oauth.
38 39 40 |
# File 'lib/3scale/backend/transactor/status.rb', line 38 def oauth @oauth end |
#redirect_uri_field ⇒ Object
Returns the value of attribute redirect_uri_field.
39 40 41 |
# File 'lib/3scale/backend/transactor/status.rb', line 39 def redirect_uri_field @redirect_uri_field end |
#rejection_reason_code ⇒ Object (readonly)
Returns the value of attribute rejection_reason_code.
53 54 55 |
# File 'lib/3scale/backend/transactor/status.rb', line 53 def rejection_reason_code @rejection_reason_code end |
#rejection_reason_text ⇒ Object (readonly)
Returns the value of attribute rejection_reason_text.
54 55 56 |
# File 'lib/3scale/backend/transactor/status.rb', line 54 def rejection_reason_text @rejection_reason_text end |
#service_id ⇒ Object (readonly)
Returns the value of attribute service_id.
36 37 38 |
# File 'lib/3scale/backend/transactor/status.rb', line 36 def service_id @service_id end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
52 53 54 |
# File 'lib/3scale/backend/transactor/status.rb', line 52 def @timestamp end |
#values ⇒ Object
Returns the value of attribute values.
40 41 42 |
# File 'lib/3scale/backend/transactor/status.rb', line 40 def values @values end |
Instance Method Details
#actual_or_predicted_usage ⇒ Object
Returns the actual usage. If there isn’t one, returns the predicted usage. If there isn’t an actual or predicted usage, returns nil.
68 69 70 |
# File 'lib/3scale/backend/transactor/status.rb', line 68 def actual_or_predicted_usage usage || predicted_usage end |
#application_usage_reports ⇒ Object
80 81 82 |
# File 'lib/3scale/backend/transactor/status.rb', line 80 def application_usage_reports @usage_report ||= load_usage_reports @application end |
#authorized? ⇒ Boolean
72 73 74 |
# File 'lib/3scale/backend/transactor/status.rb', line 72 def @authorized end |
#flat_usage ⇒ Object
42 43 44 |
# File 'lib/3scale/backend/transactor/status.rb', line 42 def flat_usage @flat_usage_ext end |
#hierarchy ⇒ Object
provides a hierarchy hash with metrics as symbolic names
90 91 92 |
# File 'lib/3scale/backend/transactor/status.rb', line 90 def hierarchy @hierarchy ||= Metric.hierarchy service_id end |
#limit_headers(now = Time.now.utc) ⇒ Object
94 95 96 97 |
# File 'lib/3scale/backend/transactor/status.rb', line 94 def limit_headers(now = Time.now.utc) # maybe filter by exceeded reports if not authorized LimitHeaders.get(reports_to_calculate_limit_headers, now) end |
#plan_name ⇒ Object
76 77 78 |
# File 'lib/3scale/backend/transactor/status.rb', line 76 def plan_name @application.plan_name unless @application.nil? end |
#predicted_usage ⇒ Object
Returns the predicted usage of an authorize request.
62 63 64 |
# File 'lib/3scale/backend/transactor/status.rb', line 62 def predicted_usage @predicted_usage ? @usage : nil end |
#reject!(error) ⇒ Object
46 47 48 49 50 |
# File 'lib/3scale/backend/transactor/status.rb', line 46 def reject!(error) @authorized = false @rejection_reason_code ||= error.code @rejection_reason_text ||= error. end |
#to_xml(options = {}) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/3scale/backend/transactor/status.rb', line 99 def to_xml( = {}) xml = '' xml << '<?xml version="1.0" encoding="UTF-8"?>'.freeze unless [:skip_instruct] xml << '<status>'.freeze (xml) if oauth add_application_section(xml) end hierarchy_reports = [] if @hierarchy_ext if !@application.nil? add_plan_section(xml, 'plan'.freeze, plan_name) add_reports_section(xml, application_usage_reports) hierarchy_reports.concat application_usage_reports if hierarchy_reports add_app_keys_section xml if @list_app_keys_ext end if hierarchy_reports add_hierarchy_section(xml, hierarchy_reports) end xml << '</status>'.freeze end |
#usage ⇒ Object
Returns the usage to be reported in an authrep request.
57 58 59 |
# File 'lib/3scale/backend/transactor/status.rb', line 57 def usage @predicted_usage ? nil : @usage end |
#value_for_usage_limit(usage_limit) ⇒ Object
84 85 86 87 |
# File 'lib/3scale/backend/transactor/status.rb', line 84 def value_for_usage_limit(usage_limit) values = @values[usage_limit.period] values && values[usage_limit.metric_id] || 0 end |