# This file was auto-generated by lib/generators/tasks/generate.rb

module Slack
  module Endpoint
    module <%= group.capitalize %>
<% names.each do |name, data| %>
      #
<% data["desc"].lines.each do |l| %>
      # <%= l.strip %>
<% end %>
      #
<% data["args"].reject{|k, v| k=="token"}.each do |arg_name, arg_v| %>
      # @option options [<%= arg_v["type"] %>] :<%= arg_name %>
<% arg_v["desc"].lines.each do |l| %>
      #   <%= l.strip %>
<% end %>
<% end %>
      # @see https://api.slack.com/methods/<%= group %>.<%= name %>
      # @see https://github.com/aki017/slack-api-docs/blob/master/methods/<%= group %>.<%= name %>.md
      # @see https://github.com/aki017/slack-api-docs/blob/master/methods/<%= group %>.<%= name %>.json
      def <%= group %>_<%= name.gsub(".", "_") %>(options={})
<% data["args"].reject{|k, v| k=="token"}.select{|k,v| v["required"]}.each do |arg_name, arg_v| %>
<% if group == "chat" && name == "postMessage" && arg_name == "text" %>
        throw ArgumentError.new("Required arguments :text or :attachments missing") if options[:<%= arg_name %>].nil? && options[:attachments].nil?
<% next %>
<% end %>
        throw ArgumentError.new("Required arguments :<%= arg_name %> missing") if options[:<%= arg_name %>].nil?
<% end %>
<% if data["args"].key? "attachments" %>
        options[:attachments] = options[:attachments].to_json if options[:attachments].is_a?(Array) || options[:attachments].is_a?(Hash)
<% end %>
        post("<%= group %>.<%= name %>", options)
      end

<% end %>
    end
  end
end
