Module: BadBill::Resource

Included in:
BaseResource, BaseResource
Defined in:
lib/badbill/resource.rb

Overview

Forward requests to the underlying connection object.

This module is included in BadBill::BaseResource.

Instance Method Summary collapse

Instance Method Details

#call(resource, id = '', options = nil, method = :get) ⇒ Object

Parameters:

  • resource (String)

    The String resource name (gets prepended with /api/).

  • id (String, Integer) (defaults to: '')

    The ID for the resource.

  • options (Hash) (defaults to: nil)

    All parameters for this request. Exact parameters depend on the resource.

  • method (Symbol) (defaults to: :get)

    One of ALLOWED_METHODS.

Raises:



29
30
31
32
# File 'lib/badbill/resource.rb', line 29

def call resource, id='', options=nil, method=:get
  raise BadBill::NoConnection, "No connection. Use BadBill.new first." if BadBill.connection.nil?
  BadBill.connection.call resource, id, options, method
end

#delete(resource, id = '', options = nil) ⇒ Object

Parameters:

  • resource (String)

    The String resource name (gets prepended with /api/).

  • id (String, Integer) (defaults to: '')

    The ID for the resource.

  • options (Hash) (defaults to: nil)

    All parameters for this request. Exact parameters depend on the resource.

  • method (Symbol)

    One of ALLOWED_METHODS.



24
25
26
# File 'lib/badbill/resource.rb', line 24

def delete resource, id='', options=nil
  call resource, id, options, :delete
end

#get(resource, id = '', options = nil) ⇒ Object

Parameters:

  • resource (String)

    The String resource name (gets prepended with /api/).

  • id (String, Integer) (defaults to: '')

    The ID for the resource.

  • options (Hash) (defaults to: nil)

    All parameters for this request. Exact parameters depend on the resource.

  • method (Symbol)

    One of ALLOWED_METHODS.



9
10
11
# File 'lib/badbill/resource.rb', line 9

def get resource, id='', options=nil
  call resource, id, options, :get
end

#post(resource, id = '', options = nil) ⇒ Object

Parameters:

  • resource (String)

    The String resource name (gets prepended with /api/).

  • id (String, Integer) (defaults to: '')

    The ID for the resource.

  • options (Hash) (defaults to: nil)

    All parameters for this request. Exact parameters depend on the resource.

  • method (Symbol)

    One of ALLOWED_METHODS.



14
15
16
# File 'lib/badbill/resource.rb', line 14

def post resource, id='', options=nil
  call resource, id, options, :post
end

#put(resource, id = '', options = nil) ⇒ Object

Parameters:

  • resource (String)

    The String resource name (gets prepended with /api/).

  • id (String, Integer) (defaults to: '')

    The ID for the resource.

  • options (Hash) (defaults to: nil)

    All parameters for this request. Exact parameters depend on the resource.

  • method (Symbol)

    One of ALLOWED_METHODS.



19
20
21
# File 'lib/badbill/resource.rb', line 19

def put resource, id='', options=nil
  call resource, id, options, :put
end