Sha256: 6748659416537f51e00d69c457d2fb5fd190da8b4d41b0ad3386452ef3b37075

Contents?: true

Size: 921 Bytes

Versions: 1

Compression:

Stored size: 921 Bytes

Contents

# frozen_string_literal: true

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

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

  def initialize
  end

<% requests.each do |request| -%>
<% action, http_method, pathname = request.separate(':') -%>
  # <%= "#{http_method.upcase} #{endpoint}/#{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 %> '<%= path %>', query: query, headers: headers
<% else -%>
    body = {}
    <%= http_method %> '<%= path %>', body: body, headers: headers
<% end -%>
  end
<% end -%>

  private

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
my_api_client-0.1.1 lib/generators/rails/templates/api_client.rb.erb