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

Add multipart file upload to PostAgent #1690

Merged
merged 1 commit into from
Sep 19, 2016

Conversation

dsander
Copy link
Collaborator

@dsander dsander commented Sep 16, 2016

This allows the PostAgent to receive file_pointer events and upload the data to a website.

@@ -113,6 +113,7 @@ def faraday
unless boolify(interpolated['disable_redirect_follow'])
builder.use FaradayMiddleware::FollowRedirects
end
builder.request :multipart
Copy link
Member

Choose a reason for hiding this comment

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

Will this affect existing users even if they're not uploading files?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It shouldn't the middleware only is called when one of the parameter responds to content_type.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, interesting. Okay!

@@ -162,22 +171,29 @@ def normalize_response_headers(headers)
}
end

def handle(data, payload = {}, headers)
url = interpolated(payload)[:post_url]
def handle(data, event = Event.new, headers)
Copy link
Member

Choose a reason for hiding this comment

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

Sidenote: it's odd that we have a middle parameter with a default. I wonder if we ever use that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

True, I guess the headers parameter was added as a third when the Agent got support for specifying the headers. check is calling handle with only two parameters.


case method
when 'get', 'delete'
params, body = data, nil
when 'post', 'put', 'patch'
params = nil

case (content_type = interpolated(payload)['content_type'])
content_type = if has_file_pointer?(event)
Copy link
Member

Choose a reason for hiding this comment

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

I think this would be slightly more readable as:

if has_file_pointer?(event)
  data[interpolated(event.payload)['upload_key'].presence || 'file'] = get_upload_io(event)
  content_type = nil
else
  content_type = interpolated(event.payload)['content_type']
end

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's the complete opposite for me, I don't like the assignment to be "hidden" in the conditional :)

The bbatsov style guide suggest:

content_type =
  if has_file_pointer?(event)
    data[interpolated(event.payload)['upload_key'].presence || 'file'] = get_upload_io(event)
    nil
  else
    interpolated(event.payload)['content_type']
  end

Copy link
Member

Choose a reason for hiding this comment

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

Hah. I don't feel strongly, go with whichever you prefer. Personally, I find it confusing that the if has both a side effect (assigning into data) and is also being used for assignment itself. The new one is fine too.

@cantino
Copy link
Member

cantino commented Sep 16, 2016

Nice!

@cantino
Copy link
Member

cantino commented Sep 16, 2016

LGTM :)

This allows the PostAgent to receive `file_pointer` events and upload the data to a website.
@dsander dsander merged commit 2e4c851 into huginn:master Sep 19, 2016
@dsander
Copy link
Collaborator Author

dsander commented Sep 19, 2016

Thanks 😄

@dsander dsander deleted the post-agent-file-upload branch September 19, 2016 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants