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 support for the OPTIONS verb #470

Merged
merged 3 commits into from
Nov 4, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
25 changes: 16 additions & 9 deletions lib/her/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,26 @@ def request(opts={})
path = opts.delete(:_path)
headers = opts.delete(:_headers)
opts.delete_if { |key, value| key.to_s =~ /^_/ } # Remove all internal parameters
response = @connection.send method do |request|
# Faraday doesn't support the OPTIONS verb because of a name collision with an internal options method
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we want to put these comments underneath if method == :options like we do for if method == :get?

# so we need to call run_request directly.
if method == :options
request.headers.merge!(headers) if headers
if method == :get
# For GET requests, treat additional parameters as querystring data
request.url path, opts
else
# For POST, PUT and DELETE requests, treat additional parameters as request body
request.url path
request.body = opts
response = @connection.run_request method, path, opts, headers
else
response = @connection.send method do |request|
request.headers.merge!(headers) if headers
if method == :get
# For GET requests, treat additional parameters as querystring data
request.url path, opts
else
# For POST, PUT and DELETE requests, treat additional parameters as request body
request.url path
request.body = opts
end
end
end

{ :parsed_data => response.env[:body], :response => response }

end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/her/model/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Model
# This module interacts with Her::API to fetch HTTP data
module HTTP
extend ActiveSupport::Concern
METHODS = [:get, :post, :put, :patch, :delete]
METHODS = [:get, :post, :put, :patch, :delete, :options]

# For each HTTP method, define these class methods:
#
Expand Down