Skip to content

Commit

Permalink
Support trashed web links API (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-nakamura145 authored Dec 26, 2020
1 parent 87a4f70 commit ae9d58b
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lib/boxr/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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']


Expand Down
2 changes: 1 addition & 1 deletion lib/boxr/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Boxr
VERSION = "1.15.0".freeze
VERSION = "1.16.0".freeze
end
25 changes: 25 additions & 0 deletions lib/boxr/web_links.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions spec/boxr/web_links_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ae9d58b

Please sign in to comment.