Method: Hachi::Clients::Base#post
- Defined in:
- lib/hachi/clients/base.rb
#post(path, params: {}, json: {}, &block) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/hachi/clients/base.rb', line 26 def post(path, params: {}, json: {}, &block) url = url_for(path) url.query = URI.encode_www_form(params) unless params.empty? post = Net::HTTP::Post.new(url) post.body = json.is_a?(Hash) ? json.to_json : json.to_s post.add_field "Content-Type", "application/json" post.add_field "Authorization", "Bearer #{api_key}" request(post, &block) end |