Class: Craigslist::API::Resources::Billing

Inherits:
Base
  • Object
show all
Defined in:
lib/craigslist/api/resources/billing.rb

Overview

Account credit, prepaid posting blocks, pricing, and invoicing.

Constant Summary

Constants inherited from Base

Craigslist::API::Resources::Base::BASE_PATH, Craigslist::API::Resources::Base::RESERVED

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Craigslist::API::Resources::Base

Instance Method Details

#create_invoiceArray<String>

Invoices everything not yet invoiced, ahead of the normal cycle.

Returns:

  • (Array<String>)

    ids of the invoices created



40
41
42
43
# File 'lib/craigslist/api/resources/billing.rb', line 40

def create_invoice
  data = transport.post(path("account", "billing", "make-invoice")).data || {}
  Array(data["invoiceIDs"]).map(&:to_s)
end

#creditCreditSummary

Returns:



9
10
11
# File 'lib/craigslist/api/resources/billing.rb', line 9

def credit
  CreditSummary.from(transport.get(path("account", "billing", "credit")).data)
end

#posting_blocksArray<PostingBlock>

Prepaid blocks still available, per area and product.

Returns:



16
17
18
19
# File 'lib/craigslist/api/resources/billing.rb', line 16

def posting_blocks
  Array(transport.get(path("account", "billing", "posting-block-balances")).data)
    .map { |entry| PostingBlock.from(entry) }
end

#pricing(area:, category:) ⇒ Money?

Current cost of posting in an area and category.

Prices can change without notice, so treat the result as a quote rather than something to cache.

Parameters:

  • area (String)

    area abbreviation, e.g. "sfo"

  • category (String)

    category abbreviation, e.g. "ofc"

Returns:



29
30
31
32
33
34
35
# File 'lib/craigslist/api/resources/billing.rb', line 29

def pricing(area:, category:)
  data = transport.get(
    path("account", "billing", "current-pricing", "area", area, "category", category)
  ).data || {}

  Money.from(data["currentPricing"])
end