Sha256: 1b31d38fd10ab703eac464bc32ee093ea83680c9a688cab826905c1fc070bc97

Contents?: true

Size: 1.38 KB

Versions: 9

Compression:

Stored size: 1.38 KB

Contents

module Chargify
  class Allocation < Base
    self.prefix = "/subscriptions/:subscription_id/components/:component_id/"

    def self.bulk_create_prefix(opts = {})
      subscription_id = opts[:subscription_id]
      raise ArgumentError, 'subscription_id required' if subscription_id.nil?

      "/subscriptions/#{subscription_id}/allocations.#{format.extension}"
    end

    def self.bulk_create(opts = {})
      return [] if opts[:allocations].blank?

      subscription_id = opts.delete(:subscription_id)
      raise ArgumentError, 'subscription_id required' if subscription_id.nil?

      with_json_format do |format|
        response = connection.post(
          bulk_create_prefix(subscription_id: subscription_id),
          format.encode(opts),
          headers
        )
        instantiate_collection(format.decode(response.body))
      end
    end

    def self.with_json_format(&block)
      # Force json processing for this api request
      json_format = ActiveResource::Formats[:json]
      orig_format = connection.format
      begin
        connection.format = json_format
        block.call(json_format)
      ensure
        connection.format = orig_format
      end
    end

    # Needed to avoid ActiveResource using Chargify::Payment
    # when there is a Payment inside an Allocation.
    # This Payment is an output-only attribute of an Allocation.
    class Payment < Base
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
chargify_api_ares-1.4.15 lib/chargify_api_ares/resources/allocation.rb
chargify_api_ares-1.4.14 lib/chargify_api_ares/resources/allocation.rb
chargify_api_ares-1.4.13 lib/chargify_api_ares/resources/allocation.rb
chargify_api_ares-1.4.11 lib/chargify_api_ares/resources/allocation.rb
chargify_api_ares-1.4.10 lib/chargify_api_ares/resources/allocation.rb
chargify_api_ares-1.4.7 lib/chargify_api_ares/resources/allocation.rb
chargify_api_ares-1.4.6 lib/chargify_api_ares/resources/allocation.rb
chargify_api_ares-1.4.5 lib/chargify_api_ares/resources/allocation.rb
chargify_api_ares-1.4.4 lib/chargify_api_ares/resources/allocation.rb