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 file upload #169

Merged
merged 2 commits into from
Sep 12, 2023
Merged

Add file upload #169

merged 2 commits into from
Sep 12, 2023

Conversation

cdccollins
Copy link
Contributor

Allow members of the public to attach files to their responses

)
end

def construct_response(params)
tags = params[:tags].scan(/[a-z]+[_[a-z]]*/)

tags.map do |tag|
"#{tag.to_s.humanize}: #{params[:"#{tag}"]}\n"
"#{tag.to_s.humanize}: #{params[:"#{tag.strip}"]}\n"
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't we just do:

Suggested change
"#{tag.to_s.humanize}: #{params[:"#{tag.strip}"]}\n"
"#{tag.to_s.humanize}: #{params[tag.strip.to_sym]}\n"

Comment on lines 23 to 36
def http_party(endpoint, method, params)
if method.to_s == "post"
HTTParty.post(
"#{api_base_url}#{endpoint}",
headers: { Authorization: authorization_header },
body: params.merge(file_params_body(params))
)
else
HTTParty.patch(
"#{api_base_url}#{endpoint}",
headers: { Authorization: authorization_header },
body: file_params_body(params)
)
end
Copy link
Contributor

Choose a reason for hiding this comment

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

We could do this all in one call, I think:

Suggested change
def http_party(endpoint, method, params)
if method.to_s == "post"
HTTParty.post(
"#{api_base_url}#{endpoint}",
headers: { Authorization: authorization_header },
body: params.merge(file_params_body(params))
)
else
HTTParty.patch(
"#{api_base_url}#{endpoint}",
headers: { Authorization: authorization_header },
body: file_params_body(params)
)
end
def http_party(endpoint, method, params)
HTTParty.send(method
"#{api_base_url}#{endpoint}",
headers: { Authorization: authorization_header },
body: method == :post ? params.merge(file_params_body(params)) : file_params_body(params)
)

Or if not then I think we still don't need to convert the symbol to a string

Suggested change
def http_party(endpoint, method, params)
if method.to_s == "post"
HTTParty.post(
"#{api_base_url}#{endpoint}",
headers: { Authorization: authorization_header },
body: params.merge(file_params_body(params))
)
else
HTTParty.patch(
"#{api_base_url}#{endpoint}",
headers: { Authorization: authorization_header },
body: file_params_body(params)
)
end
def http_party(endpoint, method, params)
if method == :post
HTTParty.post(
"#{api_base_url}#{endpoint}",
headers: { Authorization: authorization_header },
body: params.merge(file_params_body(params))
)
else
HTTParty.patch(
"#{api_base_url}#{endpoint}",
headers: { Authorization: authorization_header },
body: file_params_body(params)
)
end

@cdccollins cdccollins merged commit bc9a55e into main Sep 12, 2023
14 checks passed
@cdccollins cdccollins deleted the add-file-upload branch September 12, 2023 09:33
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