Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Representation support #55

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/boxr/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Client
METADATA_TEMPLATES_URI = "#{API_URI}/metadata_templates"
EVENTS_URI = "#{API_URI}/events"
WEB_LINKS_URI = "#{API_URI}/web_links"
INTEGRATION = "#{API_URI}/app_integration_assignments"


DEFAULT_LIMIT = 100
Expand Down Expand Up @@ -90,14 +91,15 @@ def initialize( access_token=ENV['BOX_DEVELOPER_TOKEN'],

private

def get(uri, query: nil, success_codes: [200], process_response: true, if_match: nil, box_api_header: nil, follow_redirect: true)
def get(uri, query: nil, success_codes: [200], process_response: true, if_match: nil, box_api_header: nil, follow_redirect: true, x_rep_hints: nil)
uri = Addressable::URI.encode(uri)

res = with_auto_token_refresh do
headers = standard_headers
headers['If-Match'] = if_match unless if_match.nil?
headers['BoxApi'] = box_api_header unless box_api_header.nil?

headers['x-rep-hints'] = x_rep_hints unless x_rep_hints.nil?

BOX_CLIENT.get(uri, query: query, header: headers, follow_redirect: follow_redirect)
end

Expand Down
4 changes: 2 additions & 2 deletions lib/boxr/collaborations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ def folder_collaborations(folder, fields: [])
collaborations['entries']
end

def add_collaboration(folder, accessible_by, role, fields: [], notify: nil)
def add_collaboration(folder, accessible_by, role, can_view_path,fields: [], notify: nil)
folder_id = ensure_id(folder)
query = build_fields_query(fields, COLLABORATION_FIELDS_QUERY)
query[:notify] = :notify unless notify.nil?

attributes = {item: {id: folder_id, type: :folder}}
attributes[:accessible_by] = accessible_by
attributes[:role] = validate_role(role)

attributes[:can_view_path] = can_view_path
collaboration, response = post(COLLABORATIONS_URI, attributes, query: query)
collaboration
end
Expand Down
16 changes: 16 additions & 0 deletions lib/boxr/files.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
module Boxr
class Client

def assign(user,id)
attributes = {}

attributes[:assignee] = {type: "user", id: user}
attributes[:app_integration] = {type: "app_integration", id: id}
assignment_info, response = post(INTEGRATION, attributes)
assignment_info
end

def file_from_path(path)
if(path.start_with?('/'))
path = path.slice(1..-1)
Expand Down Expand Up @@ -190,6 +199,13 @@ def copy_file(file, parent, name: nil)
new_file, res = post(uri, attributes)
new_file
end

def representations(file_id,representation)
file_id = ensure_id(file_id)
uri = "#{FILES_URI}/#{file_id}?fields=representations"
file, response = get(uri, x_rep_hints: "#{representation}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to interpolate the string here? I don't see anything being added to it

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest it's been a while since I wrote this and don't remember exactly why I implemented this this way. With that in mind which string value are you referencing?

Also, this method doesn't return the actual representation file, it only returns Representation Info
I've seen other SDK's that return the actual file, should we do the same?

https://github.com/box/box-node-sdk/blob/1d51f676b1323135891a70d470e2c9de97be9437/docs/files.md#get-representation-content

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant that

x_rep_hints: "#{representation}"

could just be

x_rep_hints: representation

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for the representation content, I agree we should add it to the library. It should be a separate action where you have to specify the representation type, and we can use the identifiers Box has for these representations.

As for the method you've already implemented, I think it's still good since there's a separate endpoint to fetch a list of the representations.

If we want to fill out the feature, it seems we'll also want a method to hit the info.url in order to manually generate representations that were not automatically generated.

I'm fine breaking down this feature into multiple smaller parts, however.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah... good point. I don't know why I added the additional string. I'll fix the code and also add tests.
We should probable breakdown the method to get the info.url endpoint.

file
end

def thumbnail(file, min_height: nil, min_width: nil, max_height: nil, max_width: nil)
file_id = ensure_id(file)
Expand Down
12 changes: 12 additions & 0 deletions lib/boxr/intergations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Boxr
class Client

def assign(user,id)
attributes = {assignee: {type: "user", id: user},app_integration: {type: "app_integration", id: id}}
body = {JSON.dump(attributes)}

assignment_info, response post(INTEGRATION, attributes)
assignment_info.entries[0]
end
end
end