Module: Yext::Api::Concerns::AccountChild
- Extended by:
- ActiveSupport::Concern
- Included in:
- AdministrativeApi::AddRequest, AdministrativeApi::Service, KnowledgeApi::AccountSettings::Role, KnowledgeApi::AccountSettings::User, KnowledgeApi::KnowledgeManager::Location, KnowledgeApi::OptimizationTasks::OptimizationLink, KnowledgeApi::OptimizationTasks::OptimizationTask, KnowledgeApi::Powerlistings::Listing, KnowledgeApi::Powerlistings::Publisher, LiveApi::Location
- Defined in:
- lib/yext/api/concerns/account_child.rb
Overview
This concern prepends the ‘accounts/:account_id/` path to the URI for classes which require it.
The account_id can be set in the following ways:
* Global configuration:
* Yext::Api.configuration.account_id = new_account_id
* For an individual call:
* SpykeClass.account(new_account_id)
* SpykeClass.where(account_id: new_account_id)
NOTE: This will not work if the DefaultParameters middleware is not being used.
If the class that this is included in uses a custom URI, the ‘uri` call must be made before this module is included.
Class Method Summary collapse
- .association_name(klass) ⇒ Object
- .ensure_relation(klass) ⇒ Object
- .with_account_path(path) ⇒ Object
Instance Method Summary collapse
-
#accountId=(value) ⇒ Object
Yext field names don’t match the Ruby naming standard, this is the field name they use.
Class Method Details
.association_name(klass) ⇒ Object
41 42 43 44 45 |
# File 'lib/yext/api/concerns/account_child.rb', line 41 def association_name(klass) association_name = klass.parents.include?(Yext::Api::LiveApi) ? "live_" : "" association_name + klass.model_name.element.pluralize end |
.ensure_relation(klass) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/yext/api/concerns/account_child.rb', line 27 def ensure_relation(klass) %w[Yext::Api::KnowledgeApi::AccountSettings::Account Yext::Api::AdministrativeApi::Account].each do |account_class_name| account_class = account_class_name.constantize next if account_class.association?(klass) klass_uri = klass.instance_variable_get(:@uri) klass_uri ||= klass.send(:default_uri) helper_warnings(account_class, klass, klass_uri) add_has_many_relation(account_class, klass, klass_uri) end end |
.with_account_path(path) ⇒ Object
23 24 25 |
# File 'lib/yext/api/concerns/account_child.rb', line 23 def with_account_path(path) File.join("accounts/:account_id", path) end |
Instance Method Details
#accountId=(value) ⇒ Object
Yext field names don’t match the Ruby naming standard, this is the field name they use. Because I use ‘account_id` in the route, I need that attribute defined. Because Yext uses accountId, when it is set, I need to set `account_id` so they will match.
130 131 132 133 |
# File 'lib/yext/api/concerns/account_child.rb', line 130 def accountId=(value) super attributes[:account_id] = value end |