Sha256: 7ac695c02e24ec1a7ce4a74355f8164bf729fea8940cf7b9d8adba5ccb7c3f41

Contents?: true

Size: 1.17 KB

Versions: 27

Compression:

Stored size: 1.17 KB

Contents

require "cobrato/resources/hooks"

module Cobrato
  module Resources
    class RemittanceCnab < Base
      crud :show, :list, :destroy

      def create(params)
        deprecate(params, %w[charge_ids charge_config_ids])
        http.post(resource_base_path, { body: params }) do |response|
          respond_with_collection(response)
        end
      end

      def file(id)
        http.get("#{resource_base_path}/#{id}/file") do |response|
          respond_with_openstruct(response)
        end
      end

      def charges(id)
        puts "Warning: The 'charges' endpoint is deprecated. Use 'items' endpoint instead."
        http.get("#{resource_base_path}/#{id}/charges") do |response|
          respond_with_collection(response, 'Charge')
        end
      end

      def items(id)
        http.get("#{resource_base_path}/#{id}/items") do |response|
          hash            = parsed_body(response)
          collection_name = hash.keys.first
          class_name      = collection_name.gsub(/(.)(.*)s/) { "#{$1.upcase}#{$2}" }
          naked_klass     = entity_klass(class_name)

          hash[collection_name].map { |item| naked_klass.new(item) }
        end
      end

    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
cobrato-client-1.1.7 lib/cobrato/resources/remittance_cnab.rb
cobrato-client-1.1.6 lib/cobrato/resources/remittance_cnab.rb
cobrato-client-1.1.5 lib/cobrato/resources/remittance_cnab.rb
cobrato-client-1.1.4 lib/cobrato/resources/remittance_cnab.rb
cobrato-client-1.1.3 lib/cobrato/resources/remittance_cnab.rb
cobrato-client-1.1.2 lib/cobrato/resources/remittance_cnab.rb
cobrato-client-1.1.1 lib/cobrato/resources/remittance_cnab.rb
cobrato-client-1.1.0 lib/cobrato/resources/remittance_cnab.rb
cobrato-client-1.0.1 lib/cobrato/resources/remittance_cnab.rb
cobrato-client-1.0.0 lib/cobrato/resources/remittance_cnab.rb
cobrato-client-0.27.0 lib/cobrato/resources/remittance_cnab.rb
cobrato-client-0.26.0 lib/cobrato/resources/remittance_cnab.rb
cobrato-client-0.25.0 lib/cobrato/resources/remittance_cnab.rb
cobrato-client-0.24.1 lib/cobrato/resources/remittance_cnab.rb
cobrato-client-0.24.0 lib/cobrato/resources/remittance_cnab.rb
cobrato-client-0.23.0 lib/cobrato/resources/remittance_cnab.rb
cobrato-client-0.23.0.beta12 lib/cobrato/resources/remittance_cnab.rb
cobrato-client-0.23.0.beta11 lib/cobrato/resources/remittance_cnab.rb
cobrato-client-0.23.0.beta10 lib/cobrato/resources/remittance_cnab.rb
cobrato-client-0.23.0.beta9 lib/cobrato/resources/remittance_cnab.rb