Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add company to client #79

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ client = Cobrato.client("YOUR_TOKEN_HERE")

Now you have acess to every API endpoint:

* [Payees API](http://docs.cobrato.com/#benefici-rio)
* [Companies API](http://docs.cobrato.com/#estabelecimento)
* [Payees API](http://docs.cobrato.com/#benefici-rio) (DEPRECATED)
* [Bank Accounts API](http://docs.cobrato.com/#conta-banc-ria)
* [People API](http://docs.cobrato.com/#pessoa)
* [Payers API](http://docs.cobrato.com/#pagador) (DEPRECATED)
Expand All @@ -69,7 +70,17 @@ Now you have acess to every API endpoint:

## Endpoints

#### [Payees](http://docs.cobrato.com/#benefici-rio)
#### [Companies](http://docs.cobrato.com/#estabelecimento)

| HTTP method | Endpoint | Client method |
| ----------- | -----------------------------------------------------------------------------| -------------------------|
| POST | [api/v1/companies](http://docs.cobrato.com/#cria-o-de-benefici-rio) | client.companies.create |
| GET | [api/v1/companies](http://docs.cobrato.com/#lista-de-todos-os-benefici-rios) | client.companies.list |
| GET | [api/v1/companies/:id](http://docs.cobrato.com/#informa-es-do-benefici-rio) | client.companies.show |
| PUT | [api/v1/companies/:id](http://docs.cobrato.com/#atualiza-o-de-benefici-rio) | client.companies.update |
| DELETE | [api/v1/companies/:id](http://docs.cobrato.com/#exclus-o-de-benefici-rio) | client.companies.destroy |

#### [Payees](http://docs.cobrato.com/#benefici-rio) # DEPRECATED

| HTTP method | Endpoint | Client method |
| ----------- | ------------------------------------------------------------------------- | --------------------- |
Expand Down Expand Up @@ -271,6 +282,9 @@ When you call `client.payees.destroy(1)`, an event `cobrato.payees.destroy` will

#### Available hooks

* companies
- cobrato.companies.create
- cobrato.companies.destroy
* payees
- cobrato.payees.create
- cobrato.payees.destroy
Expand All @@ -293,7 +307,7 @@ When you call `client.payees.destroy(1)`, an event `cobrato.payees.destroy` will
- cobrato.charge_templates.create
- cobrato.charge_templates.destroy

## Release
## Release
To release a new version, update the version number in `lib/cobrato/version.rb`, add the version in `CHANGELOG.md`, run `bundle install` and commit & push the changes to the repository.

If this is your first time publishing a RubyGem in your local device, you will have to download your credentials. To do this, follow the instructions in your [profile page in RubyGems](https://rubygems.org/profile/edit) or just type the following in your command line, replacing `$username` with your RubyGems username.
Expand Down
2 changes: 2 additions & 0 deletions lib/cobrato.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

require "cobrato/entities/base"
require "cobrato/entities/cnab"
require "cobrato/entities/company"
require "cobrato/entities/payee"
require "cobrato/entities/payer"
require "cobrato/entities/person"
Expand All @@ -27,6 +28,7 @@
require "cobrato/entities/charge_template"

require "cobrato/resources/base"
require "cobrato/resources/company"
require "cobrato/resources/payee"
require "cobrato/resources/payer"
require "cobrato/resources/person"
Expand Down
4 changes: 4 additions & 0 deletions lib/cobrato/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def authenticated?
false
end

def companies
Resources::Company.new(http)
end

def payees
Resources::Payee.new(http)
end
Expand Down
8 changes: 7 additions & 1 deletion lib/cobrato/entities/bank_account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@ module Cobrato
module Entities
class BankAccount < Base
attribute :id, Integer
attribute :payee_id, Integer
attribute :company_id, Integer
attribute :payee_id, Integer # DEPRECATED
attribute :bank_code, String
attribute :agency, String
attribute :agency_digit, String
attribute :account, String
attribute :account_digit, String

def payee_id
puts "Warning: 'payee_id' is deprecated. Use 'company_id' instead."
super
end
end
end
end
6 changes: 6 additions & 0 deletions lib/cobrato/entities/charge_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class ChargeConfig < Base
attribute :name, String
attribute :type, String
attribute :status, String
attribute :company_id, String
attribute :payee_id, String
attribute :available_charge_types, Array
attribute :deactivated_at, DateTime
Expand Down Expand Up @@ -37,6 +38,11 @@ class ChargeConfig < Base
attribute :use_avs, Boolean
attribute :logo, Hash
attribute :logo_url, String

def payee_id
puts "Warning: 'payee_id' is deprecated. Use 'company_id' instead."
super
end
end
end
end
19 changes: 19 additions & 0 deletions lib/cobrato/entities/company.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module Cobrato

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/FrozenStringLiteralComment: Missing magic comment # frozen_string_literal: true.

module Entities
class Company < Base
attribute :id, Integer
attribute :national_identifier_type, String
attribute :national_identifier, String
attribute :name, String
attribute :zipcode, String
attribute :city, String
attribute :state, String
attribute :neighbourhood, String
attribute :number, String
attribute :complement, String
attribute :street, String
end
end
end
30 changes: 27 additions & 3 deletions lib/cobrato/entities/payment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Payment < Base
attribute :registration_status, String
attribute :note, String
attribute :payee_name, String
attribute :company_name, String # DEPRECATED

# Shared with some
attribute :due_date, Date
Expand All @@ -32,9 +33,12 @@ class Payment < Base
attribute :account_digit, String
attribute :agency, String
attribute :bank_code, String
attribute :payee_id, Integer
attribute :payee_document_type, String
attribute :payee_document, String
attribute :company_id, Integer
attribute :company_document_type, String
attribute :company_document, String
attribute :payee_id, Integer # DEPRECATED
attribute :payee_document_type, String # DEPRECATED
attribute :payee_document, String # DEPRECATED
attribute :doc_goal, String
attribute :ted_goal, String

Expand Down Expand Up @@ -64,6 +68,26 @@ class Payment < Base
# FGTS specific
attribute :taxpayer_document, String
attribute :taxpayer_document_type, String

def payee_id
puts "Warning: 'payee_id' is deprecated. Use 'company_id' instead."
super
end

def payee_name
puts "Warning: 'payee_name' is deprecated. Use 'company_name' instead."
super
end

def payee_document
puts "Warning: 'payee_document' is deprecated. Use 'company_document' instead."
super
end

def payee_document_type
puts "Warning: 'payee_document_type' is deprecated. Use 'company_document_type' instead."
super
end
end
end
end
15 changes: 15 additions & 0 deletions lib/cobrato/resources/company.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module Cobrato

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/FrozenStringLiteralComment: Missing magic comment # frozen_string_literal: true.

module Resources
class Company < Base
crud :all

protected

def irregular_resource_name
"companies"
end
end
end
end
6 changes: 6 additions & 0 deletions spec/cobrato/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
end
end

describe "#companies" do
it "returns an instance of Cobrato::Resources::Company" do
expect(subject.companies).to be_a(Cobrato::Resources::Company)
end
end

describe "#payees" do
it "returns an instance of Cobrato::Resources::Payee" do
expect(subject.payees).to be_a(Cobrato::Resources::Payee)
Expand Down
11 changes: 10 additions & 1 deletion spec/cobrato/entities/bank_account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
describe Cobrato::Entities::BankAccount do
let(:attributes) do
{
company_id: "1",
payee_id: "1",
bank_code: "001",
agency: "1606",
Expand All @@ -14,5 +15,13 @@

subject { described_class.new(attributes) }

it_behaves_like "entity_attributes", [:id, :payee_id, :bank_code, :agency_digit, :agency, :account, :account_digit]
describe '#payee_id' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

it 'print a deprecation warning' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

expect {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/BlockDelimiters: Avoid using {...} for multi-line blocks.

subject.payee_id
}.to output("Warning: 'payee_id' is deprecated. Use 'company_id' instead.\n").to_stdout
end
end

it_behaves_like "entity_attributes", [:id, :payee_id, :company_id, :bank_code, :agency_digit, :agency, :account, :account_digit]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/SymbolArray: Use %i or %I for an array of symbols.
Metrics/LineLength: Line is too long. [130/120]

end
13 changes: 11 additions & 2 deletions spec/cobrato/entities/charge_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
describe Cobrato::Entities::ChargeConfig do
let(:attributes) do
{
payee_id: 1,
company_id: 1,
payee_id: 1, # DEPRECATED
bank_account_id: 1,
type: "billet",
portfolio_code: "17",
Expand All @@ -29,9 +30,17 @@

subject { described_class.new(attributes) }

describe '#payee_id' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

it 'print a deprecation warning' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

expect do
subject.payee_id
end.to output("Warning: 'payee_id' is deprecated. Use 'company_id' instead.\n").to_stdout
end
end

it_behaves_like "entity_attributes", [
# common
:id, :type, :name, :status, :payee_id, :available_charge_types, :deactivated_at, :timezone,
:id, :type, :name, :status, :payee_id, :company_id, :available_charge_types, :deactivated_at, :timezone,
# billet specifics
:bank_account_id, :portfolio_code, :agreement_code, :agreement_code_digit, :initial_number, :next_number,
:end_number, :registered_charges, :remittance_agreement_code, :initial_remittance_number, :current_remittance_number,
Expand Down
23 changes: 23 additions & 0 deletions spec/cobrato/entities/company_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true
require "spec_helper"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/FrozenStringLiteralComment: Missing magic comment # frozen_string_literal: true.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/EmptyLineAfterMagicComment: Add an empty line after magic comments.


describe Cobrato::Entities::Company do
let(:attributes) do
{
national_identifier_type: "cpf",
national_identifier: "38031171513",
name: "João Silveira",
zipcode: "99000-750",
city: "Carapebus",
state: "RJ",
neighbourhood: "Centro",
street: "Rua Julio de Castilhos",
number: "100",
complement: "Ao lado da lotérica.",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/TrailingCommaInHashLiteral: Avoid comma after the last item of a hash.

}
end

subject { described_class.new(attributes) }

it_behaves_like "entity_attributes", %i[id national_identifier_type national_identifier name zipcode city state neighbourhood number complement street]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [153/120]

end
48 changes: 42 additions & 6 deletions spec/cobrato/entities/payment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@
note: "Pagamento para Fulano de tal",

bank_code: "341",
payee_document_type: "cpf",
payee_document: "123.456.789-09",
payee_name: "John Doe",
payee_id: 7,
company_document_type: "cpf",
company_document: "123.456.789-09",
company_name: "John Doe",
company_id: 7,
payee_document_type: "cpf", # DEPRECATED
payee_document: "123.456.789-09", # DEPRECATED
payee_name: "John Doe", # DEPRECATED
payee_id: 7, # DEPRECATED

agency: "9358",
account: "21500",
Expand Down Expand Up @@ -61,15 +65,47 @@

subject { described_class.new(attributes) }

describe '#payee_id' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

it 'print a deprecation warning' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

expect {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/BlockDelimiters: Avoid using {...} for multi-line blocks.

subject.payee_id
}.to output("Warning: 'payee_id' is deprecated. Use 'company_id' instead.\n").to_stdout
end
end

describe '#payee_name' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

it 'print a deprecation warning' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

expect {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/BlockDelimiters: Avoid using {...} for multi-line blocks.

subject.payee_name
}.to output("Warning: 'payee_name' is deprecated. Use 'company_name' instead.\n").to_stdout
end
end

describe '#payee_document' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

it 'print a deprecation warning' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

expect {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/BlockDelimiters: Avoid using {...} for multi-line blocks.

subject.payee_document
}.to output("Warning: 'payee_document' is deprecated. Use 'company_document' instead.\n").to_stdout
end
end

describe '#payee_document_type' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

it 'print a deprecation warning' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

expect do
subject.payee_document_type
end.to output("Warning: 'payee_document_type' is deprecated. Use 'company_document_type' instead.\n").to_stdout
end
end

it_behaves_like "entity_attributes",
[
# Shared with all
:id, :payment_config_id, :payment_type, :payment_method, :amount, :date, :registration_status, :our_number,
:bank_code, :payee_document_type, :payee_document, :payee_name, :note,
:bank_code, :payee_document_type, :payee_document, :payee_name, :note, :company_document_type, :company_document, :company_name,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [134/120]


# Shared with some
:due_date, :calculation_period, :receita_federal_code, :mulct_amount, :interest_amount, :competency_year,
:discount_amount, :payee_id,
:discount_amount, :company_id, :payee_id,

# Transfer specific
:agency, :account, :account_digit, :doc_goal, :ted_goal,
Expand Down
Loading