freee 0.3.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +25 -1
- data/freee.gemspec +2 -0
- data/lib/freee/{account.rb → account_item.rb} +3 -3
- data/lib/freee/base.rb +13 -2
- data/lib/freee/company.rb +4 -0
- data/lib/freee/deal.rb +4 -2
- data/lib/freee/item.rb +4 -2
- data/lib/freee/obj/account_item.rb +5 -0
- data/lib/freee/obj/response.rb +1 -1
- data/lib/freee/obj/{account.rb → section.rb} +1 -1
- data/lib/freee/obj/{wallet.rb → tag.rb} +1 -1
- data/lib/freee/obj/{amount.rb → wallet_txn.rb} +1 -1
- data/lib/freee/partner.rb +4 -2
- data/lib/freee/section.rb +15 -0
- data/lib/freee/tag.rb +15 -0
- data/lib/freee/tax.rb +2 -2
- data/lib/freee/transfer.rb +4 -2
- data/lib/freee/version.rb +1 -1
- data/lib/freee/{wallet.rb → wallet_txn.rb} +5 -4
- data/lib/freee/walletable.rb +6 -0
- data/spec/account_item_spec.rb +44 -0
- data/spec/base_spec.rb +3 -9
- data/spec/company_spec.rb +53 -36
- data/spec/deal_spec.rb +150 -93
- data/spec/fixtures/account_items.json +20 -0
- data/spec/fixtures/companies.json +11 -0
- data/spec/fixtures/company.json +13 -0
- data/spec/fixtures/create_deal.json +1 -0
- data/spec/fixtures/create_item.json +6 -0
- data/spec/fixtures/create_partner.json +1 -0
- data/spec/fixtures/create_section.json +1 -0
- data/spec/fixtures/create_tag.json +1 -0
- data/spec/fixtures/create_transfer.json +1 -0
- data/spec/fixtures/create_wallet_txn.json +11 -0
- data/spec/fixtures/create_walletable.json +1 -0
- data/spec/fixtures/deal.json +34 -0
- data/spec/fixtures/deals.json +36 -0
- data/spec/fixtures/item.json +9 -0
- data/spec/fixtures/items.json +11 -0
- data/spec/fixtures/partner.json +9 -0
- data/spec/fixtures/partners.json +11 -0
- data/spec/fixtures/section.json +9 -0
- data/spec/fixtures/sections.json +11 -0
- data/spec/fixtures/tag.json +9 -0
- data/spec/fixtures/tags.json +11 -0
- data/spec/fixtures/taxes.json +8 -0
- data/spec/fixtures/taxes_with_code.json +9 -0
- data/spec/fixtures/transfer.json +13 -0
- data/spec/fixtures/transfers.json +37 -0
- data/spec/fixtures/user.json +10 -0
- data/spec/fixtures/user_with_companies.json +19 -0
- data/spec/fixtures/wallet_txn.json +14 -0
- data/spec/fixtures/wallet_txns.json +16 -0
- data/spec/fixtures/walletable.json +1 -0
- data/spec/fixtures/walletables.json +9 -0
- data/spec/item_spec.rb +74 -21
- data/spec/partner_spec.rb +59 -21
- data/spec/section_spec.rb +68 -0
- data/spec/setenv_spec.rb +0 -4
- data/spec/spec_helper.rb +41 -3
- data/spec/tag_spec.rb +68 -0
- data/spec/tax_spec.rb +63 -22
- data/spec/transfer_spec.rb +89 -34
- data/spec/user_spec.rb +47 -20
- data/spec/util_spec.rb +19 -10
- data/spec/wallet_txn_spec.rb +88 -0
- data/spec/walletable_spec.rb +74 -24
- metadata +109 -15
- data/lib/freee/amount.rb +0 -7
- data/spec/account_spec.rb +0 -34
- data/spec/amount_spec.rb +0 -26
- data/spec/wallet_spec.rb +0 -89
data/spec/setenv_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,8 +1,47 @@
|
|
1
|
+
$:.unshift(File.realpath(File.dirname(__FILE__) + '/../lib'))
|
1
2
|
require 'set'
|
3
|
+
require 'webmock/rspec'
|
4
|
+
require 'freee'
|
5
|
+
require 'pry'
|
2
6
|
|
3
|
-
|
7
|
+
include WebMock::API
|
8
|
+
WebMock.disable_net_connect!(allow_localhost: true)
|
4
9
|
|
5
|
-
|
10
|
+
def fixture_path
|
11
|
+
File.expand_path("../fixtures", __FILE__)
|
12
|
+
end
|
13
|
+
|
14
|
+
def fixture(file)
|
15
|
+
File.new(fixture_path + '/' + file).read
|
16
|
+
end
|
17
|
+
|
18
|
+
def a_get(path)
|
19
|
+
a_request(:get, Freee::OPTIONS[:site] + path)
|
20
|
+
end
|
21
|
+
|
22
|
+
def a_post(path)
|
23
|
+
a_request(:post, Freee::OPTIONS[:site] + path)
|
24
|
+
end
|
25
|
+
|
26
|
+
def a_put(path)
|
27
|
+
a_request(:put, Freee::OPTIONS[:site] + path)
|
28
|
+
end
|
29
|
+
|
30
|
+
def a_delete(path)
|
31
|
+
a_request(:delete, Freee::OPTIONS[:site] + path)
|
32
|
+
end
|
33
|
+
|
34
|
+
def stub_get(path)
|
35
|
+
stub_request(:get, Freee::OPTIONS[:site] + path)
|
36
|
+
end
|
37
|
+
|
38
|
+
def stub_post(path)
|
39
|
+
stub_request(:post, Freee::OPTIONS[:site] + path)
|
40
|
+
end
|
41
|
+
|
42
|
+
def stub_put(path)
|
43
|
+
stub_request(:put, Freee::OPTIONS[:site] + path)
|
44
|
+
end
|
6
45
|
|
7
46
|
def get_client_id
|
8
47
|
ENV["FREEE_CLIENT_ID"]
|
@@ -33,7 +72,6 @@ def get_walletable_id
|
|
33
72
|
end
|
34
73
|
|
35
74
|
RSpec.configure do |config|
|
36
|
-
config.treat_symbols_as_metadata_keys_with_true_values = true
|
37
75
|
config.run_all_when_everything_filtered = true
|
38
76
|
config.filter_run :focus
|
39
77
|
config.order = 'random'
|
data/spec/tag_spec.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Freee::Tag do
|
4
|
+
|
5
|
+
let(:company_id) { -1 }
|
6
|
+
let(:params) { fixture('create_tag.json') }
|
7
|
+
let(:json) { { params: params } }
|
8
|
+
|
9
|
+
before do
|
10
|
+
Freee::Base.config(get_client_id, get_secret_key, get_token)
|
11
|
+
@client = Freee::Tag
|
12
|
+
end
|
13
|
+
describe 'tag' do
|
14
|
+
context '#list' do
|
15
|
+
before do
|
16
|
+
stub_get('/api/1/tags?company_id=-1').to_return(body: fixture('tags.json'), headers: {content_type: 'application/json; charset=utf-8'} )
|
17
|
+
@responses = @client.list(company_id)
|
18
|
+
end
|
19
|
+
after { WebMock.reset! }
|
20
|
+
|
21
|
+
describe 'should can be able to create instance' do
|
22
|
+
subject { @responses }
|
23
|
+
|
24
|
+
it { is_expected.not_to be_nil }
|
25
|
+
it { is_expected.to be_instance_of(Freee::Response::Tag) }
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'should get tags of first item for the company' do
|
29
|
+
subject { @responses['tags'].first }
|
30
|
+
|
31
|
+
it { is_expected.not_to be_nil }
|
32
|
+
it { is_expected.to include('id') }
|
33
|
+
it { is_expected.to include('company_id') }
|
34
|
+
it { is_expected.to include('name') }
|
35
|
+
it { is_expected.to include('shortcut1') }
|
36
|
+
it { is_expected.to include('shortcut2') }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context '#create' do
|
41
|
+
before do
|
42
|
+
stub_post('/api/1/tags').
|
43
|
+
with(body: json).
|
44
|
+
to_return(body: fixture('tag.json'), headers: {content_type: 'application/json; charset=utf-8'} )
|
45
|
+
@responses = @client.create(params)
|
46
|
+
end
|
47
|
+
after { WebMock.reset! }
|
48
|
+
|
49
|
+
describe 'should can be able to create instance' do
|
50
|
+
subject { @responses }
|
51
|
+
|
52
|
+
it { is_expected.not_to be_nil }
|
53
|
+
it { is_expected.to be_instance_of(Freee::Response::Tag) }
|
54
|
+
end
|
55
|
+
|
56
|
+
describe 'should get tags of first item for the company' do
|
57
|
+
subject { @responses['tag'] }
|
58
|
+
|
59
|
+
it { is_expected.not_to be_nil }
|
60
|
+
it { is_expected.to include('id') }
|
61
|
+
it { is_expected.to include('company_id') }
|
62
|
+
it { is_expected.to include('name') }
|
63
|
+
it { is_expected.to include('shortcut1') }
|
64
|
+
it { is_expected.to include('shortcut2') }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/spec/tax_spec.rb
CHANGED
@@ -1,33 +1,74 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Freee::Tax do
|
4
|
-
let(:
|
5
|
-
let(:secret_key) { get_secret_key }
|
6
|
-
let(:token) { get_token }
|
7
|
-
let(:company_id) { get_company_id }
|
8
|
-
let(:tax) { Freee::Tax }
|
9
|
-
|
10
|
-
before(:each) do
|
11
|
-
Freee::Base.config(client_id, secret_key, token)
|
12
|
-
end
|
4
|
+
let(:company_id) { -1 }
|
13
5
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
it { is_expected.to be_instance_of(Freee::Response::Tax) }
|
6
|
+
before do
|
7
|
+
Freee::Base.config(get_client_id, get_secret_key, get_token)
|
8
|
+
@client = Freee::Tax
|
18
9
|
end
|
19
10
|
|
20
|
-
describe '
|
21
|
-
|
11
|
+
describe 'tax' do
|
12
|
+
context '#list' do
|
13
|
+
before do
|
14
|
+
stub_get('/api/1/taxes?company_id=-1').to_return(body: fixture('taxes.json'), headers: {content_type: 'application/json; charset=utf-8'} )
|
15
|
+
@responses = @client.list(company_id)
|
16
|
+
end
|
22
17
|
|
23
|
-
|
24
|
-
|
18
|
+
it 'requests the correct resource' do
|
19
|
+
assert_request_requested a_get('/api/1/taxes?company_id=-1')
|
20
|
+
end
|
25
21
|
|
26
|
-
|
27
|
-
|
22
|
+
describe 'should can be able to create instance' do
|
23
|
+
subject { @responses }
|
24
|
+
it { is_expected.not_to be_nil }
|
25
|
+
it { is_expected.to be_instance_of(Freee::Response::Tax) }
|
26
|
+
end
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
describe 'should get item of tax for the company' do
|
29
|
+
subject { @responses }
|
30
|
+
|
31
|
+
it { is_expected.to include('taxes') }
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'should get item of first tax for the company' do
|
35
|
+
subject { @responses['taxes'].first }
|
36
|
+
|
37
|
+
it { is_expected.to include('id') }
|
38
|
+
it { is_expected.to include('name') }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context '#list_of_code' do
|
43
|
+
before do
|
44
|
+
stub_get('/api/1/taxes/codes').to_return(body: fixture('taxes_with_code.json'), headers: {content_type: 'application/json; charset=utf-8'} )
|
45
|
+
@responses = @client.list_of_code
|
46
|
+
end
|
32
47
|
|
48
|
+
it 'requests the correct resource' do
|
49
|
+
assert_request_requested a_get('/api/1/taxes/codes')
|
50
|
+
end
|
51
|
+
|
52
|
+
describe 'should can be able to create instance' do
|
53
|
+
subject { @responses }
|
54
|
+
it { is_expected.not_to be_nil }
|
55
|
+
it { is_expected.to be_instance_of(Freee::Response::Tax) }
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'should get item of tax for the company' do
|
59
|
+
subject { @responses }
|
60
|
+
|
61
|
+
it { is_expected.to include('taxes') }
|
62
|
+
end
|
63
|
+
|
64
|
+
describe 'should get item of first tax for the company' do
|
65
|
+
subject { @responses['taxes'].first }
|
66
|
+
|
67
|
+
it { is_expected.to include('code') }
|
68
|
+
it { is_expected.to include('name') }
|
69
|
+
it { is_expected.to include('name_ja') }
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
33
74
|
end
|
data/spec/transfer_spec.rb
CHANGED
@@ -1,45 +1,100 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Freee::Transfer do
|
4
|
-
let(:client_id) { get_client_id }
|
5
|
-
let(:secret_key) { get_secret_key }
|
6
|
-
let(:token) { get_token }
|
7
|
-
let(:company_id) { get_company_id }
|
8
|
-
let(:transfer) { Freee::Transfer }
|
9
|
-
|
10
|
-
before(:each) do
|
11
|
-
Freee::Base.config(client_id, secret_key, token)
|
12
|
-
end
|
13
4
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
it { is_expected.to be_instance_of(Freee::Response::Transfer) }
|
18
|
-
end
|
5
|
+
let(:company_id) { -1 }
|
6
|
+
let(:params) { fixture('create_transfer.json') }
|
7
|
+
let(:json) { { params: params } }
|
19
8
|
|
20
|
-
|
21
|
-
|
9
|
+
before do
|
10
|
+
Freee::Base.config(get_client_id, get_secret_key, get_token)
|
11
|
+
@client = Freee::Transfer
|
22
12
|
end
|
23
13
|
|
24
|
-
describe '
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
14
|
+
describe 'transfers' do
|
15
|
+
context '#list' do
|
16
|
+
before do
|
17
|
+
stub_get('/api/1/transfers?company_id=-1').to_return(body: fixture('transfers.json'), headers: {content_type: 'application/json; charset=utf-8'} )
|
18
|
+
@responses = @client.list(company_id)
|
19
|
+
end
|
20
|
+
after { WebMock.reset! }
|
21
|
+
|
22
|
+
it 'requests the correct resource' do
|
23
|
+
assert_request_requested a_get('/api/1/transfers?company_id=-1')
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should can be able to create instance' do
|
27
|
+
expect(@responses).to include('transfers')
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'should be get information of account' do
|
31
|
+
subject { @responses }
|
32
|
+
it { is_expected.to be_instance_of(Freee::Response::Transfer) }
|
33
|
+
end
|
34
|
+
|
35
|
+
describe 'should be get information of first transfers for the company' do
|
36
|
+
subject { @responses['transfers'].first }
|
37
|
+
|
38
|
+
it { is_expected.not_to be_nil }
|
39
|
+
it { is_expected.to include('id') }
|
40
|
+
it { is_expected.to include('company_id') }
|
41
|
+
it { is_expected.to include('date') }
|
42
|
+
it { is_expected.to include('amount') }
|
43
|
+
it { is_expected.to include('from_walletable_id') }
|
44
|
+
it { is_expected.to include('from_walletable_type') }
|
45
|
+
it { is_expected.to include('to_walletable_type') }
|
46
|
+
it { is_expected.to include('to_walletable_id') }
|
47
|
+
it { is_expected.to include('description') }
|
48
|
+
|
49
|
+
context "with options" do
|
50
|
+
before do
|
51
|
+
stub_get('/api/1/transfers?company_id=-1&limit=3').to_return(body: fixture('transfers.json'), headers: {content_type: 'application/json; charset=utf-8'} )
|
52
|
+
@responses = @client.list(company_id, limit: 3)['transfers'].length
|
53
|
+
end
|
54
|
+
|
55
|
+
it { assert_request_requested a_get('/api/1/transfers?company_id=-1&limit=3') }
|
56
|
+
it { expect(@responses).not_to be_nil }
|
57
|
+
it { expect(@responses).to eq 3 }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context '#create' do
|
63
|
+
before do
|
64
|
+
stub_post('/api/1/transfers').
|
65
|
+
with(body: json).
|
66
|
+
to_return(body: fixture('transfer.json'), headers: {content_type: 'application/json; charset=utf-8'} )
|
67
|
+
@responses = @client.create(params)
|
68
|
+
end
|
69
|
+
after { WebMock.reset! }
|
70
|
+
|
71
|
+
it 'requests the correct resource' do
|
72
|
+
assert_request_requested a_post('/api/1/transfers').with(body: json)
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should can be able to create instance' do
|
76
|
+
expect(@responses).to include('transfer')
|
77
|
+
end
|
78
|
+
|
79
|
+
describe 'should be get information of account' do
|
80
|
+
subject { @responses }
|
81
|
+
it { is_expected.to be_instance_of(Freee::Response::Transfer) }
|
82
|
+
end
|
38
83
|
|
39
|
-
|
40
|
-
|
84
|
+
describe 'should be get information of first transfers for the company' do
|
85
|
+
subject { @responses['transfer'] }
|
41
86
|
|
42
|
-
|
43
|
-
|
87
|
+
it { is_expected.not_to be_nil }
|
88
|
+
it { is_expected.to include('id') }
|
89
|
+
it { is_expected.to include('company_id') }
|
90
|
+
it { is_expected.to include('date') }
|
91
|
+
it { is_expected.to include('amount') }
|
92
|
+
it { is_expected.to include('from_walletable_id') }
|
93
|
+
it { is_expected.to include('from_walletable_type') }
|
94
|
+
it { is_expected.to include('to_walletable_type') }
|
95
|
+
it { is_expected.to include('to_walletable_id') }
|
96
|
+
it { is_expected.to include('description') }
|
97
|
+
end
|
98
|
+
end
|
44
99
|
end
|
45
100
|
end
|
data/spec/user_spec.rb
CHANGED
@@ -1,30 +1,57 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Freee::User do
|
4
|
-
let(:client_id) { get_client_id }
|
5
|
-
let(:secret_key) { get_secret_key }
|
6
|
-
let(:token) { get_token }
|
7
|
-
let(:user) { Freee::User }
|
8
4
|
|
9
|
-
before
|
10
|
-
Freee::Base.config(
|
5
|
+
before do
|
6
|
+
Freee::Base.config(get_client_id, get_secret_key, get_token)
|
7
|
+
@client = Freee::User
|
11
8
|
end
|
12
9
|
|
13
|
-
describe '
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
10
|
+
describe 'user' do
|
11
|
+
context '#me' do
|
12
|
+
before do
|
13
|
+
stub_get('/api/1/users/me').to_return(body: fixture('user.json'), headers: {content_type: 'application/json; charset=utf-8'} )
|
14
|
+
@responses = @client.me
|
15
|
+
end
|
16
|
+
after { WebMock.reset! }
|
17
|
+
|
18
|
+
it 'requests the correct resource' do
|
19
|
+
assert_request_requested a_get('/api/1/users/me')
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should can be able to create instance' do
|
23
|
+
expect(@responses).to include('user')
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'should be get information of user' do
|
27
|
+
subject { @responses}
|
28
|
+
it { is_expected.to be_instance_of(Freee::Response::User) }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context '#me_all' do
|
33
|
+
before do
|
34
|
+
stub_get('/api/1/users/me?companies=true').to_return(body: fixture('user_with_companies.json'), headers: {content_type: 'application/json; charset=utf-8'} )
|
35
|
+
@responses = @client.me_all
|
36
|
+
end
|
37
|
+
after { WebMock.reset! }
|
38
|
+
|
39
|
+
it 'requests the correct resource' do
|
40
|
+
assert_request_requested a_get('/api/1/users/me?companies=true')
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should can be able to create instance' do
|
44
|
+
expect(@responses).to include('user')
|
45
|
+
end
|
19
46
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
expect(result['user']).to include('companies')
|
24
|
-
user_company_info_of_first = result['user']['companies'].first
|
47
|
+
it 'should be get information of user at all' do
|
48
|
+
expect(@responses['user']).to include('companies')
|
49
|
+
user_company_info_of_first = @responses['user']['companies'].first
|
25
50
|
|
26
|
-
|
27
|
-
|
28
|
-
|
51
|
+
expect(user_company_info_of_first).to include('id')
|
52
|
+
expect(user_company_info_of_first).to include('display_name')
|
53
|
+
expect(user_company_info_of_first).to include('role')
|
54
|
+
end
|
55
|
+
end
|
29
56
|
end
|
30
57
|
end
|
data/spec/util_spec.rb
CHANGED
@@ -1,20 +1,29 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Freee::Util do
|
4
|
-
|
5
|
-
let(:
|
6
|
-
let(:
|
7
|
-
let(:
|
8
|
-
|
4
|
+
|
5
|
+
let(:authorization_code) { 'authorization_code' }
|
6
|
+
let(:redirect_uri) { get_redirect_url }
|
7
|
+
let(:access_token) { OpenStruct.new({token: 'a'*64 }) }
|
8
|
+
|
9
|
+
before do
|
10
|
+
stub_post("/oauth/token").
|
11
|
+
with(:body => "{\"grant_type\":\"authorization_code\",\"code\":\"#{authorization_code}\",\"redirect_uri\":#{redirect_uri}}").
|
12
|
+
to_return(:status => 200, :body => "", :headers => {})
|
13
|
+
allow_any_instance_of(OAuth2::Client).to receive(:get_token).
|
14
|
+
and_return(access_token)
|
15
|
+
end
|
9
16
|
|
10
17
|
it 'should be get access token' do
|
11
18
|
result = Freee::Util.create_token(
|
12
|
-
client_id:
|
13
|
-
secret_key:
|
14
|
-
redirect_url:
|
19
|
+
client_id: get_client_id,
|
20
|
+
secret_key: get_secret_key,
|
21
|
+
redirect_url: redirect_uri,
|
15
22
|
authorization_code: authorization_code
|
16
23
|
)
|
17
|
-
|
18
|
-
|
24
|
+
|
25
|
+
token = result[:token]
|
26
|
+
expect(token).to be_kind_of(String)
|
27
|
+
expect(token).to match(/[a-z0-9]{64}/)
|
19
28
|
end
|
20
29
|
end
|