Sha256: 7a84a22353d63df27bcb685773f71ca0c3ad09f11f2c0e89416ab86c74abfbaf

Contents?: true

Size: 1.99 KB

Versions: 17

Compression:

Stored size: 1.99 KB

Contents

module Octobat
  class Invoice < APIResource
    extend Octobat::APIOperations::List
    include Octobat::APIOperations::Create
    include Octobat::APIOperations::Update
    
    
    def self.pdf_export(params = {}, opts={})
      api_key, headers = Util.parse_opts(opts)
      api_key ||= @api_key
      opts[:api_key] = api_key

      instance = self.new(nil, opts)

      response, api_key = Octobat.request(:post, url + '/pdf_export', api_key, params)
      return true
    end
    
    def self.csv_export(params = {}, opts={})
      api_key, headers = Util.parse_opts(opts)
      api_key ||= @api_key
      opts[:api_key] = api_key

      instance = self.new(nil, opts)

      response, api_key = Octobat.request(:post, url + '/csv_export', api_key, params)
      return true
    end
    

    def send_by_email(email_data = {})
      response, api_key = Octobat.request(:post, send_url, @api_key, email_data)
      refresh_from(response, api_key)
    end

    def confirm(confirmation_data = {})
      response, api_key = Octobat.request(:patch, confirm_url, @api_key, confirmation_data)
      refresh_from(response, api_key)
    end

    def cancel
      response, api_key = Octobat.request(:patch, cancel_url, @api_key)
      refresh_from(response, api_key)
    end

    def cancel_and_replace
      response, api_key = Octobat.request(:patch, cancel_and_replace_url, @api_key)
      refresh_from(response, api_key)
    end

    def delete
      response, api_key = Octobat.request(:delete, url, @api_key)
      refresh_from(response, api_key)
    end

    def items(params = {})
      Item.list(params.merge({ :invoice => id }), @api_key)
    end

    def transactions(params = {})
      Transaction.list(params.merge(invoice: id), @api_key)
    end


    private

      def send_url
        url + '/send'
      end

      def confirm_url
        url + '/confirm'
      end

      def cancel_url
        url + '/cancel'
      end

      def cancel_and_replace_url
        url + '/cancel_and_replace'
      end

  end


end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
octobat-2.0.18 lib/octobat/invoice.rb
octobat-2.0.17 lib/octobat/invoice.rb
octobat-2.0.16 lib/octobat/invoice.rb
octobat-2.0.15 lib/octobat/invoice.rb
octobat-2.0.14 lib/octobat/invoice.rb
octobat-2.0.12 lib/octobat/invoice.rb
octobat-2.0.11 lib/octobat/invoice.rb
octobat-2.0.10 lib/octobat/invoice.rb
octobat-2.0.9 lib/octobat/invoice.rb
octobat-2.0.8 lib/octobat/invoice.rb
octobat-2.0.7 lib/octobat/invoice.rb
octobat-2.0.6 lib/octobat/invoice.rb
octobat-2.0.5 lib/octobat/invoice.rb
octobat-2.0.4 lib/octobat/invoice.rb
octobat-2.0.3 lib/octobat/invoice.rb
octobat-2.0.2 lib/octobat/invoice.rb
octobat-2.0.1 lib/octobat/invoice.rb