From ae9d58b7c98d801dd4fca2cdb0a98f0048ee9207 Mon Sep 17 00:00:00 2001 From: Masato Nakamura Date: Sun, 27 Dec 2020 06:16:19 +0900 Subject: [PATCH] Support trashed web links API (#97) --- README.md | 6 ++++++ lib/boxr/client.rb | 4 ++++ lib/boxr/version.rb | 2 +- lib/boxr/web_links.rb | 25 +++++++++++++++++++++++++ spec/boxr/web_links_spec.rb | 13 +++++++++++++ 5 files changed, 49 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 98d0a56..8a40638 100644 --- a/README.md +++ b/README.md @@ -289,6 +289,12 @@ get_web_link(web_link) update_web_link(web_link, url: nil, parent: nil, name: nil, description: nil) delete_web_link(web_link) + +trashed_web_link(web_link, fields: []) + +delete_trashed_web_link(web_link) + +restore_trashed_web_link(web_link, name: nil, parent: nil) ``` #### [Comments](https://developer.box.com/en/reference/resources/comment/) ```ruby diff --git a/lib/boxr/client.rb b/lib/boxr/client.rb index 61effd7..9baf188 100644 --- a/lib/boxr/client.rb +++ b/lib/boxr/client.rb @@ -59,6 +59,10 @@ class Client GROUP_FIELDS = [:type, :id, :name, :created_at, :modified_at] GROUP_FIELDS_QUERY = GROUP_FIELDS.join(',') + WEB_LINK_FIELDS = [:type, :id, :created_at, :created_by, :description, :etag, :item_status, :modified_at, :modified_by, + :name, :owned_by, :parent, :path_collection, :purged_at, :sequence_id, :shared_link, :trashed_at, :url] + WEB_LINK_FIELDS_QUERY = WEB_LINK_FIELDS.join(',') + VALID_COLLABORATION_ROLES = ['editor','viewer','previewer','uploader','previewer uploader','viewer uploader','co-owner','owner'] diff --git a/lib/boxr/version.rb b/lib/boxr/version.rb index de46f60..456be28 100644 --- a/lib/boxr/version.rb +++ b/lib/boxr/version.rb @@ -1,3 +1,3 @@ module Boxr - VERSION = "1.15.0".freeze + VERSION = "1.16.0".freeze end diff --git a/lib/boxr/web_links.rb b/lib/boxr/web_links.rb index e5308f2..db7dc2e 100644 --- a/lib/boxr/web_links.rb +++ b/lib/boxr/web_links.rb @@ -51,6 +51,31 @@ def delete_web_link(web_link) result end + def trashed_web_link(web_link, fields: []) + web_link_id = ensure_id(web_link) + uri = "#{WEB_LINKS_URI}/#{web_link_id}/trash" + query = build_fields_query(fields, WEB_LINK_FIELDS_QUERY) + + web_link, response = get(uri, query: query) + web_link + end + alias :get_trashed_web_link :trashed_web_link + + def delete_trashed_web_link(web_link) + web_link_id = ensure_id(web_link) + uri = "#{WEB_LINKS_URI}/#{web_link_id}/trash" + result, response = delete(uri) + result + end + + def restore_trashed_web_link(web_link, name: nil, parent: nil) + web_link_id = ensure_id(web_link) + parent_id = ensure_id(parent) + + uri = "#{WEB_LINKS_URI}/#{web_link_id}" + restore_trashed_item(uri, name, parent_id) + end + private def verify_url(item) diff --git a/spec/boxr/web_links_spec.rb b/spec/boxr/web_links_spec.rb index 56e9815..23d61ee 100644 --- a/spec/boxr/web_links_spec.rb +++ b/spec/boxr/web_links_spec.rb @@ -16,5 +16,18 @@ puts "delete web link" result = BOX_CLIENT.delete_web_link(web_link) expect(result).to eq({}) + + puts "get trashed web link" + trashed_web_link = BOX_CLIENT.trashed_web_link(web_link) + expect(trashed_web_link.item_status).to eq("trashed") + + puts "restore trashed web link" + restored_web_link = BOX_CLIENT.restore_trashed_web_link(web_link) + expect(restored_web_link.item_status).to eq("active") + + puts "trash and permanently delete web link" + BOX_CLIENT.delete_web_link(web_link) + result = BOX_CLIENT.delete_trashed_web_link(web_link) + expect(result).to eq({}) end end