class ThreeScaleToolbox::Entities::Account
Constants
- PRINTABLE_VARS
- VERBOSE_PRINTABLE_VARS
Public Class Methods
find(remote:, ref:)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
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.
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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
Public Instance Methods
applications()
click to toggle source
# 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()
click to toggle source
# File lib/3scale_toolbox/entities/account.rb, line 77 def attrs @attrs ||= account_attrs end
Private Instance Methods
account_attrs()
click to toggle source
# File lib/3scale_toolbox/entities/account.rb, line 94 def account_attrs remote.show_account(id).tap do |account| if (errors = account['errors']) raise ThreeScaleToolbox::ThreeScaleApiError.new('Account attrs not read', errors) end end end