Class: Asana::Resources::Portfolio
- Inherits:
-
PortfoliosBase
- Object
- Resource
- PortfoliosBase
- Asana::Resources::Portfolio
- Defined in:
- lib/asana/resources/portfolio.rb
Overview
A portfolio gives a high-level overview of the status of multiple initiatives in Asana. Portfolios provide a dashboard overview of the state of multiple items, including a progress report and the most recent [project status](/developers/api-reference/project_statuses) update.
Portfolios have some restrictions on size. Each portfolio has a maximum of 250 items and, like projects, a maximum of 20 custom fields.
Instance Attribute Summary collapse
- #color ⇒ Object readonly
- #created_at ⇒ Object readonly
- #created_by ⇒ Object readonly
-
#custom_field_settings(options: {}) ⇒ Object
readonly
Get the custom field settings on a portfolio.
- #gid ⇒ Object readonly
- #members ⇒ Object readonly
- #name ⇒ Object readonly
- #owner ⇒ Object readonly
- #resource_type ⇒ Object readonly
- #workspace ⇒ Object readonly
Class Method Summary collapse
-
.create(client, workspace: required("workspace"), name: required("name"), color: nil, options: {}, **data) ⇒ Object
Creates a new portfolio in the given workspace with the supplied name.
-
.find_all(client, workspace: required("workspace"), owner: required("owner"), per_page: 20, options: {}) ⇒ Object
Returns a list of the portfolios in compact representation that are owned by the current API user.
-
.find_by_id(client, id, options: {}) ⇒ Object
Returns the complete record for a single portfolio.
-
.plural_name ⇒ Object
Returns the plural name of the resource.
Instance Method Summary collapse
-
#add_custom_field_setting(custom_field: required("custom_field"), is_important: nil, insert_before: nil, insert_after: nil, options: {}, **data) ⇒ Object
Create a new custom field setting on the portfolio.
-
#add_item(item: required("item"), insert_before: nil, insert_after: nil, options: {}, **data) ⇒ Object
Add an item to a portfolio.
-
#add_members(members: required("members"), options: {}, **data) ⇒ Object
Adds the specified list of users as members of the portfolio.
-
#delete ⇒ Object
An existing portfolio can be deleted by making a DELETE request on the URL for that portfolio.
-
#get_items(options: {}) ⇒ Object
Get a list of the items in compact form in a portfolio.
-
#remove_custom_field_setting(custom_field: required("custom_field"), options: {}, **data) ⇒ Object
Remove a custom field setting on the portfolio.
-
#remove_item(item: required("item"), options: {}, **data) ⇒ Object
Remove an item to a portfolio.
-
#remove_members(members: required("members"), options: {}, **data) ⇒ Object
Removes the specified list of members from the portfolio.
-
#update(options: {}, **data) ⇒ Object
An existing portfolio can be updated by making a PUT request on the URL for that portfolio.
Methods inherited from PortfoliosBase
add_custom_field_setting_for_portfolio, add_item_for_portfolio, add_members_for_portfolio, create_portfolio, delete_portfolio, get_items_for_portfolio, get_portfolio, get_portfolios, inherited, remove_custom_field_setting_for_portfolio, remove_item_for_portfolio, remove_members_for_portfolio, update_portfolio
Methods inherited from Resource
#initialize, #method_missing, #refresh, #respond_to_missing?, #to_h, #to_s
Methods included from ResponseHelper
Constructor Details
This class inherits a constructor from Asana::Resources::Resource
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Asana::Resources::Resource
Instance Attribute Details
#color ⇒ Object (readonly)
29 30 31 |
# File 'lib/asana/resources/portfolio.rb', line 29 def color @color end |
#created_at ⇒ Object (readonly)
23 24 25 |
# File 'lib/asana/resources/portfolio.rb', line 23 def created_at @created_at end |
#created_by ⇒ Object (readonly)
25 26 27 |
# File 'lib/asana/resources/portfolio.rb', line 25 def created_by @created_by end |
#custom_field_settings(options: {}) ⇒ Object (readonly)
Get the custom field settings on a portfolio.
166 167 168 |
# File 'lib/asana/resources/portfolio.rb', line 166 def custom_field_settings @custom_field_settings end |
#gid ⇒ Object (readonly)
15 16 17 |
# File 'lib/asana/resources/portfolio.rb', line 15 def gid @gid end |
#members ⇒ Object (readonly)
33 34 35 |
# File 'lib/asana/resources/portfolio.rb', line 33 def members @members end |
#name ⇒ Object (readonly)
19 20 21 |
# File 'lib/asana/resources/portfolio.rb', line 19 def name @name end |
#owner ⇒ Object (readonly)
21 22 23 |
# File 'lib/asana/resources/portfolio.rb', line 21 def owner @owner end |
#resource_type ⇒ Object (readonly)
17 18 19 |
# File 'lib/asana/resources/portfolio.rb', line 17 def resource_type @resource_type end |
#workspace ⇒ Object (readonly)
31 32 33 |
# File 'lib/asana/resources/portfolio.rb', line 31 def workspace @workspace end |
Class Method Details
.create(client, workspace: required("workspace"), name: required("name"), color: nil, options: {}, **data) ⇒ Object
Creates a new portfolio in the given workspace with the supplied name.
Note that portfolios created in the Asana UI may have some state (like the “Priority” custom field) which is automatically added to the portfolio when it is created. Portfolios created via our API will not be created with the same initial state to allow integrations to create their own starting state on a portfolio.
54 55 56 57 |
# File 'lib/asana/resources/portfolio.rb', line 54 def create(client, workspace: required("workspace"), name: required("name"), color: nil, options: {}, **data) with_params = data.merge(workspace: workspace, name: name, color: color).reject { |_,v| v.nil? || Array(v).empty? } self.new(parse(client.post("/portfolios", body: with_params, options: )).first, client: client) end |
.find_all(client, workspace: required("workspace"), owner: required("owner"), per_page: 20, options: {}) ⇒ Object
Returns a list of the portfolios in compact representation that are owned by the current API user.
77 78 79 80 |
# File 'lib/asana/resources/portfolio.rb', line 77 def find_all(client, workspace: required("workspace"), owner: required("owner"), per_page: 20, options: {}) params = { workspace: workspace, owner: owner, limit: per_page }.reject { |_,v| v.nil? || Array(v).empty? } Collection.new(parse(client.get("/portfolios", params: params, options: )), type: self, client: client) end |
.find_by_id(client, id, options: {}) ⇒ Object
Returns the complete record for a single portfolio.
63 64 65 66 |
# File 'lib/asana/resources/portfolio.rb', line 63 def find_by_id(client, id, options: {}) self.new(parse(client.get("/portfolios/#{id}", options: )).first, client: client) end |
.plural_name ⇒ Object
Returns the plural name of the resource.
37 38 39 |
# File 'lib/asana/resources/portfolio.rb', line 37 def plural_name 'portfolios' end |
Instance Method Details
#add_custom_field_setting(custom_field: required("custom_field"), is_important: nil, insert_before: nil, insert_after: nil, options: {}, **data) ⇒ Object
Create a new custom field setting on the portfolio. Returns the full record for the new custom field setting.
185 186 187 188 |
# File 'lib/asana/resources/portfolio.rb', line 185 def add_custom_field_setting(custom_field: required("custom_field"), is_important: nil, insert_before: nil, insert_after: nil, options: {}, **data) with_params = data.merge(custom_field: custom_field, is_important: is_important, insert_before: insert_before, insert_after: insert_after).reject { |_,v| v.nil? || Array(v).empty? } Resource.new(parse(client.post("/portfolios/#{gid}/addCustomFieldSetting", body: with_params, options: )).first, client: client) end |
#add_item(item: required("item"), insert_before: nil, insert_after: nil, options: {}, **data) ⇒ Object
Add an item to a portfolio.
126 127 128 129 |
# File 'lib/asana/resources/portfolio.rb', line 126 def add_item(item: required("item"), insert_before: nil, insert_after: nil, options: {}, **data) with_params = data.merge(item: item, insert_before: insert_before, insert_after: insert_after).reject { |_,v| v.nil? || Array(v).empty? } client.post("/portfolios/#{gid}/addItem", body: with_params, options: ) && true end |
#add_members(members: required("members"), options: {}, **data) ⇒ Object
Adds the specified list of users as members of the portfolio. Returns the updated portfolio record.
148 149 150 151 |
# File 'lib/asana/resources/portfolio.rb', line 148 def add_members(members: required("members"), options: {}, **data) with_params = data.merge(members: members).reject { |_,v| v.nil? || Array(v).empty? } refresh_with(parse(client.post("/portfolios/#{gid}/addMembers", body: with_params, options: )).first) end |
#delete ⇒ Object
An existing portfolio can be deleted by making a DELETE request on the URL for that portfolio.
100 101 102 103 |
# File 'lib/asana/resources/portfolio.rb', line 100 def delete() client.delete("/portfolios/#{gid}") && true end |
#get_items(options: {}) ⇒ Object
Get a list of the items in compact form in a portfolio.
108 109 110 111 |
# File 'lib/asana/resources/portfolio.rb', line 108 def get_items(options: {}) Collection.new(parse(client.get("/portfolios/#{gid}/items", options: )), type: Resource, client: client) end |
#remove_custom_field_setting(custom_field: required("custom_field"), options: {}, **data) ⇒ Object
Remove a custom field setting on the portfolio. Returns an empty data block.
196 197 198 199 |
# File 'lib/asana/resources/portfolio.rb', line 196 def remove_custom_field_setting(custom_field: required("custom_field"), options: {}, **data) with_params = data.merge(custom_field: custom_field).reject { |_,v| v.nil? || Array(v).empty? } client.post("/portfolios/#{gid}/removeCustomFieldSetting", body: with_params, options: ) && true end |
#remove_item(item: required("item"), options: {}, **data) ⇒ Object
Remove an item to a portfolio.
138 139 140 141 |
# File 'lib/asana/resources/portfolio.rb', line 138 def remove_item(item: required("item"), options: {}, **data) with_params = data.merge(item: item).reject { |_,v| v.nil? || Array(v).empty? } client.post("/portfolios/#{gid}/removeItem", body: with_params, options: ) && true end |
#remove_members(members: required("members"), options: {}, **data) ⇒ Object
Removes the specified list of members from the portfolio. Returns the updated portfolio record.
158 159 160 161 |
# File 'lib/asana/resources/portfolio.rb', line 158 def remove_members(members: required("members"), options: {}, **data) with_params = data.merge(members: members).reject { |_,v| v.nil? || Array(v).empty? } refresh_with(parse(client.post("/portfolios/#{gid}/removeMembers", body: with_params, options: )).first) end |
#update(options: {}, **data) ⇒ Object
An existing portfolio can be updated by making a PUT request on the URL for that portfolio. Only the fields provided in the ‘data` block will be updated; any unspecified fields will remain unchanged.
91 92 93 94 |
# File 'lib/asana/resources/portfolio.rb', line 91 def update(options: {}, **data) refresh_with(parse(client.put("/portfolios/#{gid}", body: data, options: )).first) end |