Class: Attio::Meta
- Inherits:
-
APIResource
- Object
- APIResource
- Attio::Meta
- Defined in:
- lib/attio/resources/meta.rb
Overview
Provides metadata about the current API token and workspace
Constant Summary
Constants inherited from APIResource
Instance Attribute Summary
Attributes inherited from APIResource
Class Method Summary collapse
-
.identify(**opts) ⇒ Object
(also: self, current)
Get information about the current token and workspace.
-
.resource_path ⇒ Object
Meta only supports the identify endpoint (no CRUD operations).
Instance Method Summary collapse
-
#actor ⇒ Object
Build actor object from flat attributes.
-
#can_read?(resource) ⇒ Boolean
Check read/write permissions.
- #can_write?(resource) ⇒ Boolean
-
#destroy(**opts) ⇒ Object
Override destroy to raise error since meta is read-only.
-
#has_scope?(scope) ⇒ Boolean
Check if token has a specific scope.
-
#immutable? ⇒ Boolean
Meta is read-only.
- #inspect ⇒ Object
-
#save(**opts) ⇒ Object
Override save to raise error since meta is read-only.
-
#scopes ⇒ Array<String>
Get the token's OAuth scopes.
- #to_h ⇒ Object
-
#token ⇒ Object
Build token object from flat attributes.
-
#token_id ⇒ Object
Convenience methods for token info.
-
#token_name ⇒ String?
Get the token name.
-
#token_type ⇒ String?
Get the token type.
-
#workspace ⇒ Object
Build workspace object from flat attributes.
-
#workspace_id ⇒ Object
Convenience methods for workspace info.
-
#workspace_name ⇒ String?
Get the workspace name.
-
#workspace_slug ⇒ String?
Get the workspace slug.
Methods inherited from APIResource
#==, #[], #[]=, api_operations, attr_attio, #changed, #changed?, #changed_attributes, #changes, #each, execute_request, #fetch, #hash, id_param_name, #initialize, #key?, #keys, #persisted?, prepare_params_for_create, prepare_params_for_update, #reset_changes!, resource_name, #resource_path, #revert!, #to_json, #update_attributes, #update_from, validate_id!, #values
Constructor Details
This class inherits a constructor from Attio::APIResource
Class Method Details
.identify(**opts) ⇒ Object Also known as: self, current
Get information about the current token and workspace
15 16 17 18 |
# File 'lib/attio/resources/meta.rb', line 15 def self.identify(**opts) response = execute_request(:GET, resource_path, {}, opts) new(response["data"] || response, opts) end |
.resource_path ⇒ Object
Meta only supports the identify endpoint (no CRUD operations)
10 11 12 |
# File 'lib/attio/resources/meta.rb', line 10 def self.resource_path "self" end |
Instance Method Details
#actor ⇒ Object
Build actor object from flat attributes
50 51 52 53 54 55 56 57 |
# File 'lib/attio/resources/meta.rb', line 50 def actor return nil unless self[:authorized_by_workspace_member_id] { type: "workspace-member", id: self[:authorized_by_workspace_member_id] } end |
#can_read?(resource) ⇒ Boolean
Check read/write permissions
107 108 109 |
# File 'lib/attio/resources/meta.rb', line 107 def can_read?(resource) has_scope?("#{resource}:read") || has_scope?("#{resource}:read-write") end |
#can_write?(resource) ⇒ Boolean
111 112 113 |
# File 'lib/attio/resources/meta.rb', line 111 def can_write?(resource) has_scope?("#{resource}:write") || has_scope?("#{resource}:read-write") end |
#destroy(**opts) ⇒ Object
Override destroy to raise error since meta is read-only
126 127 128 |
# File 'lib/attio/resources/meta.rb', line 126 def destroy(**opts) raise InvalidRequestError, "Meta information is read-only" end |
#has_scope?(scope) ⇒ Boolean
Check if token has a specific scope
101 102 103 104 |
# File 'lib/attio/resources/meta.rb', line 101 def has_scope?(scope) scope_str = scope.to_s.tr("_", ":") scopes.include?(scope_str) end |
#immutable? ⇒ Boolean
Meta is read-only
116 117 118 |
# File 'lib/attio/resources/meta.rb', line 116 def immutable? true end |
#inspect ⇒ Object
138 139 140 |
# File 'lib/attio/resources/meta.rb', line 138 def inspect "#<#{self.class.name}:#{object_id} workspace=#{workspace_slug.inspect} token=#{token_name.inspect}>" end |
#save(**opts) ⇒ Object
Override save to raise error since meta is read-only
121 122 123 |
# File 'lib/attio/resources/meta.rb', line 121 def save(**opts) raise InvalidRequestError, "Meta information is read-only" end |
#scopes ⇒ Array<String>
Get the token's OAuth scopes
95 96 97 98 |
# File 'lib/attio/resources/meta.rb', line 95 def scopes return [] unless self[:scope] self[:scope].split(" ") end |
#to_h ⇒ Object
130 131 132 133 134 135 136 |
# File 'lib/attio/resources/meta.rb', line 130 def to_h { workspace: workspace, token: token, actor: actor }.compact end |
#token ⇒ Object
Build token object from flat attributes
39 40 41 42 43 44 45 46 47 |
# File 'lib/attio/resources/meta.rb', line 39 def token return nil unless self[:client_id] { id: self[:client_id], type: self[:token_type] || "Bearer", scope: self[:scope] }.compact end |
#token_id ⇒ Object
Convenience methods for token info
77 78 79 |
# File 'lib/attio/resources/meta.rb', line 77 def token_id self[:client_id] end |
#token_name ⇒ String?
Get the token name
83 84 85 |
# File 'lib/attio/resources/meta.rb', line 83 def token_name nil end |
#token_type ⇒ String?
Get the token type
89 90 91 |
# File 'lib/attio/resources/meta.rb', line 89 def token_type self[:token_type] end |
#workspace ⇒ Object
Build workspace object from flat attributes
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/attio/resources/meta.rb', line 27 def workspace return nil unless self[:workspace_id] { id: self[:workspace_id], name: self[:workspace_name], slug: self[:workspace_slug], logo_url: self[:workspace_logo_url] }.compact end |
#workspace_id ⇒ Object
Convenience methods for workspace info
60 61 62 |
# File 'lib/attio/resources/meta.rb', line 60 def workspace_id self[:workspace_id] end |
#workspace_name ⇒ String?
Get the workspace name
66 67 68 |
# File 'lib/attio/resources/meta.rb', line 66 def workspace_name self[:workspace_name] end |
#workspace_slug ⇒ String?
Get the workspace slug
72 73 74 |
# File 'lib/attio/resources/meta.rb', line 72 def workspace_slug self[:workspace_slug] end |