Sha256: 51f89f3998cd33f6acf4c4bdae4006d27d5c119115709f6738fabcc1541bb9aa

Contents?: true

Size: 898 Bytes

Versions: 4

Compression:

Stored size: 898 Bytes

Contents

# frozen_string_literal: true

class <%= "#{class_name}ApiClient" %> < ::ApplicationApiClient
  endpoint '<%= options[:endpoint] %>'

  # error_handling json: { '$.errors.code': 10 } do |params, logger|
  #   # Behavior when detected an error.
  # end

  def initialize
  end

<% yeild_request_arguments do |action, http_method, pathname| -%>
  # <%= "#{http_method.upcase} #{pathname}" %>
  #
  # @return [Sawyer::Resource] Description of the API response
  # @raise [MyApiClient::Error] Description of the error
  # @see Reference of the API
  def <%= action %>
<% if http_method == 'get' -%>
    query = {}
    <%= http_method %> '<%= pathname %>', query: query, headers: headers
<% else -%>
    body = {}
    <%= http_method %> '<%= pathname %>', body: body, headers: headers
<% end -%>
  end
<% end -%>

  private

  def headers
    {
      'Content-Type': 'application/json',
    }
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
my_api_client-0.21.0 lib/generators/rails/templates/api_client.rb.erb
my_api_client-0.20.0 lib/generators/rails/templates/api_client.rb.erb
my_api_client-0.19.0 lib/generators/rails/templates/api_client.rb.erb
my_api_client-0.18.0 lib/generators/rails/templates/api_client.rb.erb