A Ruby client for the Charging REST API
<img src=“https://badge.fury.io/rb/charging-client.png” alt=“Gem Version” /> <img src=“https://travis-ci.org/myfreecomm/charging-client-ruby.png?branch=master” alt=“Build Status” /> <img src=“https://coveralls.io/repos/myfreecomm/charging-client-ruby/badge.png?branch=master” alt=“Coverage Status” /> <img src=“https://codeclimate.com/github/myfreecomm/charging-client-ruby.png” alt=“Code Climate Status” />
Charging API docs: ???
charging-client-ruby RDoc documentation: rubydoc.info/github/myfreecomm/charging-client-ruby/frames/
The RDoc is the best place to learn how to use this client. A few example uses are listed below. See the mapping of API endpoints to this client code below as well to find what you need.
Add this line to your application’s Gemfile:
gem 'charging-client', :require => 'charging'
And then execute:
$ bundle
Or install it yourself as:
$ gem install charging-client
TODO
require "charging" Charging.configure do |c| # You application token at Charging Service # Required c.application_token = 'YourApptoken==' # URL for request data. # Default: 'https://charging.finnanceconnect.com.br' c.url = 'http://sandbox.charging.financeconnect.com.br' # User agent to identify the http request on Charing. # Default: 'Charging Ruby Client v0.0.1' c.user_agent = 'My App v1.0' end
account = Charging::ServiceAccount.current account.name # => 'Your App Name on Charging' account.last_response # a success RestClient::Response instance account.last_response.code # => 200 begin account = Charging::ServiceAccount.current rescue Charging::Http::LastResponseError => exception exception.last_response # an unauthorized RestClient::Response instance exception.last_response.code # 401 end
domains = Charging::Domain.find_all(account)
attributes = { :supplier_name => 'Myfreecomm', :address => 'Rua do Carmo, 43', :city_state => 'Rio de Janeiro/RJ', :zipcode => '20011-020', national_identifier => '37.818.380/0001-86', description => 'A Myfreecomm é uma empresa moderna...' } new_domain = Charging::Domain.new(attributes, account) new_domain.persisted? # => false new_domain.create! new_domain.persisted? # => true
domain = Charging::Domain.find_by_uuid(account, 'supposed-uuid-for-domain') domain.persisted? # => true
Pending
Pending
domain.destroy! domain.deleted? # => true domain.persisted? # => false
domain = Charging::Domain.find_by_token('domain-token')
attributes = { :bank => '237', :name => 'Conta de Cobrança no Bradesco', :agreement_code => '1234', :portifolio_code => '25' :agency => {:number => '1234'}, :account => {:number => '12345', :digit => '6'} } new_charge_account = Charging::ChargeAccount.new(attributes, domain) new_charge_account.persisted? # => false new_charge_account.create! new_charge_account.persisted? # => true
charge_accountes = ChargeAccount::ChargeAccount.find_all(domain)
charge_account = ChargeAccount::ChargeAccount.find_by_uuid(domain, 'supposed-uuid-for-charge-account') charge_account.persisted? # => true
Pending
Pending
charge_account.update_attribute! :address, 'Novo Endereço'
charge_account.update_attributes! address: 'Novo Endereço', city_state: 'Cidade/UF'
Note: This will execute charge_account#update_attribute!
for each attribute. If something wrong, updated attributes will not get back old values.
charge_account.destroy!
Invoice.kinds(domain) # => [{"acronym"=>"DM", "itau_code"=>1, "code"=>2, "name"=>"Duplicata Mercantil"}, ...] Invoice.kinds(domain)
attributes = { :kind => 1, :amount => 123.45, :document_number => '123456789012345', :due_date => '2015-12-31' :drawee => { :name => 'Fulano de Tal', :address => 'Rua do Carmo, 43', :city_state => 'Rio de Janeiro/RJ', :zipcode => '20011-020', :national_identifier => '43.055.679/0001-29' } } new_invoice = Charging::Invoice.new(attributes, domain, charge_account) new_invoice.persisted? # => false new_invoice.create! new_invoice.persisted? # => true
invoice = Charging::Invoice.find_by_uuid(domain, 'supposed-uuid-for-invoice') invoice.persisted? # => true
invoice.billet_url # => 'https://charging.financeconnect.com.br/billets/6a60.../ff01.../'
invoice.destroy! invoice.deleted? # => true invoice.persisted? # => false
invoice.pay! invoice.paid # => invoice.amount invoice.pay!({ :amount => invoice.amount, # default :date => Time.now.strftime('%Y-%m-%d'), #default :note => 'some important note about this payment' })
invoice.payments
Pending
-
Fork it
-
Create your feature branch (‘git checkout -b my-new-feature`)
-
Commit your changes (‘git commit -am ’Add some feature’‘)
-
Push to the branch (‘git push origin my-new-feature`)
-
Create new Pull Request