Skip to content

Commit

Permalink
Merge pull request #72 from Asana/rossgrambo-gid-fix
Browse files Browse the repository at this point in the history
Functions use gids instead of ids
  • Loading branch information
rossgrambo-zz committed Aug 12, 2019
2 parents 8f83be3 + f28ca34 commit 1191c97
Show file tree
Hide file tree
Showing 29 changed files with 156 additions and 147 deletions.
1 change: 0 additions & 1 deletion asana.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ Gem::Specification.new do |spec|
spec.add_dependency "faraday_middleware", "~> 0.9"
spec.add_dependency "faraday_middleware-multi_json", "~> 0.0"

spec.add_development_dependency "bundler", "~> 1.7"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rspec", "~> 3.2"
spec.add_development_dependency 'appraisal', '~> 2.1', '>= 2.1'
Expand Down
2 changes: 1 addition & 1 deletion lib/asana/resource_includes/attachment_uploading.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def attach(filename: required('filename'),
raise ArgumentError, "file #{filename} doesn't exist"
end
upload = Faraday::UploadIO.new(path, mime)
response = client.post("/#{self.class.plural_name}/#{id}/attachments",
response = client.post("/#{self.class.plural_name}/#{gid}/attachments",
body: data,
upload: upload,
options: options)
Expand Down
2 changes: 1 addition & 1 deletion lib/asana/resource_includes/event_subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Resources
module EventSubscription
# Public: Returns an infinite collection of events on the resource.
def events(wait: 1, options: {})
Events.new(resource: id, client: client, wait: wait, options: options)
Events.new(resource: gid, client: client, wait: wait, options: options)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/asana/resource_includes/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def initialize(data, client: required('client'))
def refresh
raise "#{self.class.name} does not respond to #find_by_id" unless \
self.class.respond_to?(:find_by_id)
self.class.find_by_id(client, id)
self.class.find_by_id(client, gid)
end

# Internal: Proxies method calls to the data, wrapping it accordingly and
Expand Down
4 changes: 2 additions & 2 deletions lib/asana/resources/custom_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def insert_enum_option(client, custom_field: required("custom_field"), enum_opti
# data - [Hash] the attributes to post.
def update(options: {}, **data)

refresh_with(parse(client.put("/custom_fields/#{id}", body: data, options: options)).first)
refresh_with(parse(client.put("/custom_fields/#{gid}", body: data, options: options)).first)
end

# A specific, existing custom field can be deleted by making a DELETE request on the URL for that custom field.
Expand All @@ -144,7 +144,7 @@ def update(options: {}, **data)
# Returns an empty data record.
def delete()

client.delete("/custom_fields/#{id}") && true
client.delete("/custom_fields/#{gid}") && true
end

# Updates an existing enum option. Enum custom fields require at least one enabled enum option.
Expand Down
20 changes: 10 additions & 10 deletions lib/asana/resources/portfolio.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def find_all(client, workspace: required("workspace"), owner: required("owner"),
# data - [Hash] the attributes to post.
def update(options: {}, **data)

refresh_with(parse(client.put("/portfolios/#{id}", body: data, options: options)).first)
refresh_with(parse(client.put("/portfolios/#{gid}", body: data, options: options)).first)
end

# An existing portfolio can be deleted by making a DELETE request
Expand All @@ -102,15 +102,15 @@ def update(options: {}, **data)
# Returns an empty data record.
def delete()

client.delete("/portfolios/#{id}") && true
client.delete("/portfolios/#{gid}") && true
end

# Get a list of the items in compact form in a portfolio.
#
# options - [Hash] the request I/O options.
def get_items(options: {})

Collection.new(parse(client.get("/portfolios/#{id}/items", options: options)), type: self, client: client)
Collection.new(parse(client.get("/portfolios/#{gid}/items", options: options)), type: self, client: client)
end

# Add an item to a portfolio.
Expand All @@ -128,7 +128,7 @@ def get_items(options: {})
# data - [Hash] the attributes to post.
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/#{id}/addItem", body: with_params, options: options) && true
client.post("/portfolios/#{gid}/addItem", body: with_params, options: options) && true
end

# Remove an item to a portfolio.
Expand All @@ -140,7 +140,7 @@ def add_item(item: required("item"), insert_before: nil, insert_after: nil, opti
# data - [Hash] the attributes to post.
def remove_item(item: required("item"), options: {}, **data)
with_params = data.merge(item: item).reject { |_,v| v.nil? || Array(v).empty? }
client.post("/portfolios/#{id}/removeItem", body: with_params, options: options) && true
client.post("/portfolios/#{gid}/removeItem", body: with_params, options: options) && true
end

# Adds the specified list of users as members of the portfolio. Returns the updated portfolio record.
Expand All @@ -150,7 +150,7 @@ def remove_item(item: required("item"), options: {}, **data)
# data - [Hash] the attributes to post.
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/#{id}/addMembers", body: with_params, options: options)).first)
refresh_with(parse(client.post("/portfolios/#{gid}/addMembers", body: with_params, options: options)).first)
end

# Removes the specified list of members from the portfolio. Returns the updated portfolio record.
Expand All @@ -160,15 +160,15 @@ def add_members(members: required("members"), options: {}, **data)
# data - [Hash] the attributes to post.
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/#{id}/removeMembers", body: with_params, options: options)).first)
refresh_with(parse(client.post("/portfolios/#{gid}/removeMembers", body: with_params, options: options)).first)
end

# Get the custom field settings on a portfolio.
#
# options - [Hash] the request I/O options.
def custom_field_settings(options: {})

Collection.new(parse(client.get("/portfolios/#{id}/custom_field_settings", options: options)), type: self, client: client)
Collection.new(parse(client.get("/portfolios/#{gid}/custom_field_settings", options: options)), type: self, client: client)
end

# Create a new custom field setting on the portfolio. Returns the full
Expand All @@ -187,7 +187,7 @@ def custom_field_settings(options: {})
# data - [Hash] the attributes to post.
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/#{id}/addCustomFieldSetting", body: with_params, options: options)).first, client: client)
Resource.new(parse(client.post("/portfolios/#{gid}/addCustomFieldSetting", body: with_params, options: options)).first, client: client)
end

# Remove a custom field setting on the portfolio. Returns an empty data
Expand All @@ -198,7 +198,7 @@ def add_custom_field_setting(custom_field: required("custom_field"), is_importan
# data - [Hash] the attributes to post.
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/#{id}/removeCustomFieldSetting", body: with_params, options: options) && true
client.post("/portfolios/#{gid}/removeCustomFieldSetting", body: with_params, options: options) && true
end

end
Expand Down
20 changes: 10 additions & 10 deletions lib/asana/resources/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def find_by_team(client, team: required("team"), is_template: nil, archived: nil
# data - [Hash] the attributes to post.
def update(options: {}, **data)

refresh_with(parse(client.put("/projects/#{id}", body: data, options: options)).first)
refresh_with(parse(client.put("/projects/#{gid}", body: data, options: options)).first)
end

# A specific, existing project can be deleted by making a DELETE request
Expand All @@ -199,7 +199,7 @@ def update(options: {}, **data)
# Returns an empty data record.
def delete()

client.delete("/projects/#{id}") && true
client.delete("/projects/#{gid}") && true
end

# Creates and returns a job that will asynchronously handle the duplication.
Expand All @@ -223,7 +223,7 @@ def delete()
# data - [Hash] the attributes to post.
def duplicate_project(name: required("name"), team: nil, include: nil, schedule_dates: nil, options: {}, **data)
with_params = data.merge(name: name, team: team, include: include, schedule_dates: schedule_dates).reject { |_,v| v.nil? || Array(v).empty? }
Resource.new(parse(client.post("/projects/#{id}/duplicate", body: with_params, options: options)).first, client: client)
Resource.new(parse(client.post("/projects/#{gid}/duplicate", body: with_params, options: options)).first, client: client)
end

# Returns the compact task records for all tasks within the given project,
Expand All @@ -233,7 +233,7 @@ def duplicate_project(name: required("name"), team: nil, include: nil, schedule_
# options - [Hash] the request I/O options.
def tasks(per_page: 20, options: {})
params = { limit: per_page }.reject { |_,v| v.nil? || Array(v).empty? }
Collection.new(parse(client.get("/projects/#{id}/tasks", params: params, options: options)), type: Task, client: client)
Collection.new(parse(client.get("/projects/#{gid}/tasks", params: params, options: options)), type: Task, client: client)
end

# Adds the specified list of users as followers to the project. Followers are a subset of members, therefore if
Expand All @@ -245,7 +245,7 @@ def tasks(per_page: 20, options: {})
# data - [Hash] the attributes to post.
def add_followers(followers: required("followers"), options: {}, **data)
with_params = data.merge(followers: followers).reject { |_,v| v.nil? || Array(v).empty? }
refresh_with(parse(client.post("/projects/#{id}/addFollowers", body: with_params, options: options)).first)
refresh_with(parse(client.post("/projects/#{gid}/addFollowers", body: with_params, options: options)).first)
end

# Removes the specified list of users from following the project, this will not affect project membership status.
Expand All @@ -256,7 +256,7 @@ def add_followers(followers: required("followers"), options: {}, **data)
# data - [Hash] the attributes to post.
def remove_followers(followers: required("followers"), options: {}, **data)
with_params = data.merge(followers: followers).reject { |_,v| v.nil? || Array(v).empty? }
refresh_with(parse(client.post("/projects/#{id}/removeFollowers", body: with_params, options: options)).first)
refresh_with(parse(client.post("/projects/#{gid}/removeFollowers", body: with_params, options: options)).first)
end

# Adds the specified list of users as members of the project. Returns the updated project record.
Expand All @@ -266,7 +266,7 @@ def remove_followers(followers: required("followers"), options: {}, **data)
# data - [Hash] the attributes to post.
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("/projects/#{id}/addMembers", body: with_params, options: options)).first)
refresh_with(parse(client.post("/projects/#{gid}/addMembers", body: with_params, options: options)).first)
end

# Removes the specified list of members from the project. Returns the updated project record.
Expand All @@ -276,7 +276,7 @@ def add_members(members: required("members"), options: {}, **data)
# data - [Hash] the attributes to post.
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("/projects/#{id}/removeMembers", body: with_params, options: options)).first)
refresh_with(parse(client.post("/projects/#{gid}/removeMembers", body: with_params, options: options)).first)
end

# Create a new custom field setting on the project.
Expand All @@ -294,7 +294,7 @@ def remove_members(members: required("members"), options: {}, **data)
# data - [Hash] the attributes to post.
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("/projects/#{id}/addCustomFieldSetting", body: with_params, options: options)).first, client: client)
Resource.new(parse(client.post("/projects/#{gid}/addCustomFieldSetting", body: with_params, options: options)).first, client: client)
end

# Remove a custom field setting on the project.
Expand All @@ -304,7 +304,7 @@ def add_custom_field_setting(custom_field: required("custom_field"), is_importan
# data - [Hash] the attributes to post.
def remove_custom_field_setting(custom_field: nil, options: {}, **data)
with_params = data.merge(custom_field: custom_field).reject { |_,v| v.nil? || Array(v).empty? }
Resource.new(parse(client.post("/projects/#{id}/removeCustomFieldSetting", body: with_params, options: options)).first, client: client)
Resource.new(parse(client.post("/projects/#{gid}/removeCustomFieldSetting", body: with_params, options: options)).first, client: client)
end

end
Expand Down
2 changes: 1 addition & 1 deletion lib/asana/resources/project_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def find_by_id(client, id, options: {})
# Returns an empty data record.
def delete()

client.delete("/project_statuses/#{id}") && true
client.delete("/project_statuses/#{gid}") && true
end

end
Expand Down
4 changes: 2 additions & 2 deletions lib/asana/resources/section.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def add_task(client, task: required("task"), insert_before: nil, insert_after: n
# data - [Hash] the attributes to post.
def update(options: {}, **data)

refresh_with(parse(client.put("/sections/#{id}", body: data, options: options)).first)
refresh_with(parse(client.put("/sections/#{gid}", body: data, options: options)).first)
end

# A specific, existing section can be deleted by making a DELETE request
Expand All @@ -104,7 +104,7 @@ def update(options: {}, **data)
# Returns an empty data block.
def delete()

client.delete("/sections/#{id}") && true
client.delete("/sections/#{gid}") && true
end

# Move sections relative to each other in a board view. One of
Expand Down
4 changes: 2 additions & 2 deletions lib/asana/resources/story.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ def create_on_task(client, task: required("task"), text: required("text"), optio
# data - [Hash] the attributes to post.
def update(text: nil, html_text: nil, is_pinned: nil, options: {}, **data)
with_params = data.merge(text: text, html_text: html_text, is_pinned: is_pinned).reject { |_,v| v.nil? || Array(v).empty? }
refresh_with(parse(client.put("/stories/#{id}", body: with_params, options: options)).first)
refresh_with(parse(client.put("/stories/#{gid}", body: with_params, options: options)).first)
end

# Deletes a story. A user can only delete stories they have created. Returns an empty data record.
def delete()

client.delete("/stories/#{id}") && true
client.delete("/stories/#{gid}") && true
end

end
Expand Down
6 changes: 3 additions & 3 deletions lib/asana/resources/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def find_by_workspace(client, workspace: required("workspace"), per_page: 20, op
# data - [Hash] the attributes to post.
def update(options: {}, **data)

refresh_with(parse(client.put("/tags/#{id}", body: data, options: options)).first)
refresh_with(parse(client.put("/tags/#{gid}", body: data, options: options)).first)
end

# A specific, existing tag can be deleted by making a DELETE request
Expand All @@ -126,7 +126,7 @@ def update(options: {}, **data)
# Returns an empty data record.
def delete()

client.delete("/tags/#{id}") && true
client.delete("/tags/#{gid}") && true
end

# Returns the compact task records for all tasks with the given tag.
Expand All @@ -136,7 +136,7 @@ def delete()
# options - [Hash] the request I/O options.
def get_tasks_with_tag(per_page: 20, options: {})
params = { limit: per_page }.reject { |_,v| v.nil? || Array(v).empty? }
Collection.new(parse(client.get("/tags/#{id}/tasks", params: params, options: options)), type: Task, client: client)
Collection.new(parse(client.get("/tags/#{gid}/tasks", params: params, options: options)), type: Task, client: client)
end

end
Expand Down
Loading

0 comments on commit 1191c97

Please sign in to comment.