class Internal::Edfi::StashService < Internal::ApplicationService
  def initialize(school, id, method, target, options={})
    @school = school
    @id = id
    @method = method
    @target = target
    @options = options
  end

  def call
    RestClient.patch(endpoint, params, headers)
  rescue RestClient::Exception => e
    Rails.logger.info JSON.parse(e.response.body)
    false
  end

  private
    def params
      @options.merge(method: @method, target: @target).to_json
    end

    def endpoint
      "#{base_url}/EdFi/Stash/#{@id}"
    end
end
