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.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/README.md +25 -1
  4. data/freee.gemspec +2 -0
  5. data/lib/freee/{account.rb → account_item.rb} +3 -3
  6. data/lib/freee/base.rb +13 -2
  7. data/lib/freee/company.rb +4 -0
  8. data/lib/freee/deal.rb +4 -2
  9. data/lib/freee/item.rb +4 -2
  10. data/lib/freee/obj/account_item.rb +5 -0
  11. data/lib/freee/obj/response.rb +1 -1
  12. data/lib/freee/obj/{account.rb → section.rb} +1 -1
  13. data/lib/freee/obj/{wallet.rb → tag.rb} +1 -1
  14. data/lib/freee/obj/{amount.rb → wallet_txn.rb} +1 -1
  15. data/lib/freee/partner.rb +4 -2
  16. data/lib/freee/section.rb +15 -0
  17. data/lib/freee/tag.rb +15 -0
  18. data/lib/freee/tax.rb +2 -2
  19. data/lib/freee/transfer.rb +4 -2
  20. data/lib/freee/version.rb +1 -1
  21. data/lib/freee/{wallet.rb → wallet_txn.rb} +5 -4
  22. data/lib/freee/walletable.rb +6 -0
  23. data/spec/account_item_spec.rb +44 -0
  24. data/spec/base_spec.rb +3 -9
  25. data/spec/company_spec.rb +53 -36
  26. data/spec/deal_spec.rb +150 -93
  27. data/spec/fixtures/account_items.json +20 -0
  28. data/spec/fixtures/companies.json +11 -0
  29. data/spec/fixtures/company.json +13 -0
  30. data/spec/fixtures/create_deal.json +1 -0
  31. data/spec/fixtures/create_item.json +6 -0
  32. data/spec/fixtures/create_partner.json +1 -0
  33. data/spec/fixtures/create_section.json +1 -0
  34. data/spec/fixtures/create_tag.json +1 -0
  35. data/spec/fixtures/create_transfer.json +1 -0
  36. data/spec/fixtures/create_wallet_txn.json +11 -0
  37. data/spec/fixtures/create_walletable.json +1 -0
  38. data/spec/fixtures/deal.json +34 -0
  39. data/spec/fixtures/deals.json +36 -0
  40. data/spec/fixtures/item.json +9 -0
  41. data/spec/fixtures/items.json +11 -0
  42. data/spec/fixtures/partner.json +9 -0
  43. data/spec/fixtures/partners.json +11 -0
  44. data/spec/fixtures/section.json +9 -0
  45. data/spec/fixtures/sections.json +11 -0
  46. data/spec/fixtures/tag.json +9 -0
  47. data/spec/fixtures/tags.json +11 -0
  48. data/spec/fixtures/taxes.json +8 -0
  49. data/spec/fixtures/taxes_with_code.json +9 -0
  50. data/spec/fixtures/transfer.json +13 -0
  51. data/spec/fixtures/transfers.json +37 -0
  52. data/spec/fixtures/user.json +10 -0
  53. data/spec/fixtures/user_with_companies.json +19 -0
  54. data/spec/fixtures/wallet_txn.json +14 -0
  55. data/spec/fixtures/wallet_txns.json +16 -0
  56. data/spec/fixtures/walletable.json +1 -0
  57. data/spec/fixtures/walletables.json +9 -0
  58. data/spec/item_spec.rb +74 -21
  59. data/spec/partner_spec.rb +59 -21
  60. data/spec/section_spec.rb +68 -0
  61. data/spec/setenv_spec.rb +0 -4
  62. data/spec/spec_helper.rb +41 -3
  63. data/spec/tag_spec.rb +68 -0
  64. data/spec/tax_spec.rb +63 -22
  65. data/spec/transfer_spec.rb +89 -34
  66. data/spec/user_spec.rb +47 -20
  67. data/spec/util_spec.rb +19 -10
  68. data/spec/wallet_txn_spec.rb +88 -0
  69. data/spec/walletable_spec.rb +74 -24
  70. metadata +109 -15
  71. data/lib/freee/amount.rb +0 -7
  72. data/spec/account_spec.rb +0 -34
  73. data/spec/amount_spec.rb +0 -26
  74. data/spec/wallet_spec.rb +0 -89
@@ -10,8 +10,4 @@ describe Freee::Base do
10
10
  it 'should be able to get client' do
11
11
  expect(freee.client).not_to be_nil
12
12
  end
13
-
14
- it 'should be call of get by Freee' do
15
- expect(freee.client.get('/api/1/users/me?companies=true')).to include("user")
16
- end
17
13
  end
@@ -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
- $:.unshift(File.realpath(File.dirname(__FILE__) + '/../lib'))
7
+ include WebMock::API
8
+ WebMock.disable_net_connect!(allow_localhost: true)
4
9
 
5
- require 'freee'
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'
@@ -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
@@ -1,33 +1,74 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Freee::Tax 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(: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
- describe 'should can be able to create instance' do
15
- subject { tax.list(company_id) }
16
- it { is_expected.not_to be_nil }
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 'should get item of tax for the company' do
21
- subject { tax.list(company_id) }
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
- it { is_expected.to include('taxes') }
24
- end
18
+ it 'requests the correct resource' do
19
+ assert_request_requested a_get('/api/1/taxes?company_id=-1')
20
+ end
25
21
 
26
- describe 'should get item of first tax for the company' do
27
- subject { tax.list(company_id)['taxes'].first }
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
- it { is_expected.to include('id') }
30
- it { is_expected.to include('name') }
31
- end
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
@@ -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
- describe 'should be able to get client' do
15
- subject { transfer.list(company_id) }
16
- it { is_expected.not_to be_nil }
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
- it 'should be get information of transfers for the company' do
21
- expect(transfer.list(company_id)).to include('transfers')
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 'should be get information of first transfers for the company' do
25
- subject { transfer.list(company_id)['transfers'].first }
26
-
27
- it { is_expected.not_to be_nil }
28
- it { is_expected.to include('id') }
29
- it { is_expected.to include('company_id') }
30
- it { is_expected.to include('date') }
31
- it { is_expected.to include('amount') }
32
- it { is_expected.to include('from_walletable_id') }
33
- it { is_expected.to include('from_walletable_type') }
34
- it { is_expected.to include('to_walletable_type') }
35
- it { is_expected.to include('to_walletable_id') }
36
- it { is_expected.to include('description') }
37
- end
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
- describe "should be get one's information of first transfers for the company" do
40
- subject { transfer.list(company_id, limit: 3)['transfers'].length }
84
+ describe 'should be get information of first transfers for the company' do
85
+ subject { @responses['transfer'] }
41
86
 
42
- it { is_expected.not_to be_nil }
43
- it { is_expected.to eq 3 }
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
@@ -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(:each) do
10
- Freee::Base.config(client_id, secret_key, token)
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 'should be get information of user' do
14
- subject { user.me }
15
- it { is_expected.not_to be_nil }
16
- it { is_expected.to be_instance_of(Freee::Response::User) }
17
- it { is_expected.to include('user') }
18
- end
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
- it 'should be get information of user at all' do
21
- result = user.me_all
22
- expect(result).to include('user')
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
- expect(user_company_info_of_first).to include('id')
27
- expect(user_company_info_of_first).to include('display_name')
28
- expect(user_company_info_of_first).to include('role')
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
@@ -1,20 +1,29 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Freee::Util do
4
- let(:client_id) { get_client_id }
5
- let(:secret_key) { get_secret_key }
6
- let(:redirect_url) { get_redirect_url }
7
- let(:authorization_code) { get_authorization_code }
8
- let(:token) { get_token }
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: client_id,
13
- secret_key: secret_key,
14
- redirect_url: 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
- expect(result).to be_kind_of(String)
18
- expect(result).to match(/[a-z0-9]{64}/)
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