Sha256: 90611c54e1dce0de3b6652fd063d2c3503a59bf35fbddac372c7c5b871fb7307
Contents?: true
Size: 1.2 KB
Versions: 1
Compression:
Stored size: 1.2 KB
Contents
module Moip2 class TransferApi attr_reader :client def initialize(client) @client = client end def create(transfer) Resource::Transfer.new client.post(base_path, transfer) end def show(transfers_id) Resource::Transfer.new client.get("#{base_path}/#{transfers_id}") end def find_all(limit: nil, offset: nil, filters: nil, status: nil) response = client.get(uri_encode(limit, offset, filters, status)) Resource::Transfer.new json_to_object(response) end def reverse(transfers_id) Resource::Transfer.new client.post("#{base_path}/#{transfers_id}/reverse", nil) end private def base_path "/v2/transfers" end def uri_encode(limit, offset, filters, status) encoded_filters = Moip2::Util::FiltersEncoder.encode(filters) params = { limit: limit, offset: offset, filters: encoded_filters, status: status, }.reject { |_, value| value.nil? } query_string = URI.encode_www_form(params) path = "#{base_path}?#{query_string}" end def json_to_object(json) json.transfers.map! { |transfer| Resource::Transfer.new transfer } json end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
moip2-1.3.1 | lib/moip2/transfer_api.rb |