Class: ThreeScaleToolbox::Entities::Account
- Inherits:
-
Object
- Object
- ThreeScaleToolbox::Entities::Account
- Includes:
- Entity
- Defined in:
- lib/3scale_toolbox/entities/account.rb
Constant Summary collapse
- PRINTABLE_VARS =
%w[id org_name].freeze
- VERBOSE_PRINTABLE_VARS =
%w[ id org_name created_at updated_at admin_domain domain from_email support_email finance_support_email monthly_billing_enabled monthly_charging_enabled ].freeze
Instance Attribute Summary
Attributes included from Entity
Class Method Summary collapse
- .find(remote:, ref:) ⇒ Object
- .find_by_email(remote, email) ⇒ Object
- .find_by_provider_or_service_token(remote, text) ⇒ Object
-
.find_by_text(ref, remote) ⇒ Object
ref can be * Email of the account user.
- .find_by_user_id(remote, user_id) ⇒ Object
- .find_by_username(remote, username) ⇒ Object
- .generic_find(remote, criteria) ⇒ Object
Instance Method Summary collapse
Methods included from Entity
Class Method Details
.find(remote:, ref:) ⇒ Object
17 18 19 20 21 |
# File 'lib/3scale_toolbox/entities/account.rb', line 17 def find(remote:, ref:) new(id: ref, remote: remote).tap(&:attrs) rescue ThreeScale::API::HttpClient::NotFoundError find_by_text(ref, remote) end |
.find_by_email(remote, email) ⇒ Object
48 49 50 |
# File 'lib/3scale_toolbox/entities/account.rb', line 48 def find_by_email(remote, email) generic_find(remote, email: email) end |
.find_by_provider_or_service_token(remote, text) ⇒ Object
60 61 62 |
# File 'lib/3scale_toolbox/entities/account.rb', line 60 def find_by_provider_or_service_token(remote, text) generic_find(remote, buyer_provider_key: text, buyer_service_token: text) end |
.find_by_text(ref, remote) ⇒ Object
ref can be
-
Email of the account user.
-
Username of the account user.
-
ID of the account user.
- Master API
-
Provider key of the account
- Master API
-
Service token of the account service.
email, username or user_id fields search with AND logic. Therefore separate requests. buyer_provider_key, buyer_service_token fields search with OR logic. Same request.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/3scale_toolbox/entities/account.rb', line 32 def find_by_text(ref, remote) account = find_by_email(remote, ref) return account unless account.nil? account = find_by_username(remote, ref) return account unless account.nil? account = find_by_user_id(remote, ref) return account unless account.nil? account = find_by_provider_or_service_token(remote, ref) return account unless account.nil? nil end |
.find_by_user_id(remote, user_id) ⇒ Object
56 57 58 |
# File 'lib/3scale_toolbox/entities/account.rb', line 56 def find_by_user_id(remote, user_id) generic_find(remote, user_id: user_id) end |
.find_by_username(remote, username) ⇒ Object
52 53 54 |
# File 'lib/3scale_toolbox/entities/account.rb', line 52 def find_by_username(remote, username) generic_find(remote, username: username) end |
.generic_find(remote, criteria) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/3scale_toolbox/entities/account.rb', line 64 def generic_find(remote, criteria) account = remote.find_account(criteria) if (errors = account['errors']) raise ThreeScaleToolbox::ThreeScaleApiError.new( 'Account find returned errors', errors ) end new(id: account['id'], remote: remote, attrs: account) rescue ThreeScale::API::HttpClient::NotFoundError nil end |
Instance Method Details
#applications ⇒ Object
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/3scale_toolbox/entities/account.rb', line 81 def applications app_attrs_list = remote.list_account_applications(id) if app_attrs_list.respond_to?(:has_key?) && (errors = app_attrs_list['errors']) raise ThreeScaleToolbox::ThreeScaleApiError.new('Account applications not read', errors) end app_attrs_list.map do |app_attrs| Entities::Application.new(id: app_attrs.fetch('id'), remote: remote, attrs: app_attrs) end end |
#attrs ⇒ Object
77 78 79 |
# File 'lib/3scale_toolbox/entities/account.rb', line 77 def attrs @attrs ||= account_attrs end |