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
@@ -0,0 +1,11 @@
1
+ {
2
+ "partners" : [
3
+ {
4
+ "id" : 101,
5
+ "company_id" : 1,
6
+ "name" : "ABC商店",
7
+ "shortcut1" : "ABC",
8
+ "shortcut2" : "501"
9
+ }
10
+ ]
11
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "section" : {
3
+ "id" : 102,
4
+ "company_id" : 1,
5
+ "name" : "開発部門",
6
+ "shortcut1" : "DEVELOPER",
7
+ "shortcut2" : "123"
8
+ }
9
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "sections" : [
3
+ {
4
+ "id" : 101,
5
+ "company_id" : 1,
6
+ "name" : "開発部門",
7
+ "shortcut1" : "DEVELOPER",
8
+ "shortcut2" : "123"
9
+ }
10
+ ]
11
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "tag" : {
3
+ "id" : 102,
4
+ "company_id" : 1,
5
+ "name" : "メモタグ",
6
+ "shortcut1" : "MEMOTAG",
7
+ "shortcut2" : "123"
8
+ }
9
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "tags" : [
3
+ {
4
+ "id" : 101,
5
+ "company_id" : 1,
6
+ "name" : "メモタグ",
7
+ "shortcut1" : "MEMOTAG",
8
+ "shortcut2" : "123"
9
+ }
10
+ ]
11
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "taxes" : [
3
+ {
4
+ "id" : 101,
5
+ "name" : "課税売上"
6
+ }
7
+ ]
8
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "taxes" : [
3
+ {
4
+ "code" : 21,
5
+ "name" : "sales_with_tax",
6
+ "name_ja" : "課税売上"
7
+ }
8
+ ]
9
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "transfer" : {
3
+ "id" : 101,
4
+ "company_id" : -1,
5
+ "date" : "2013-01-01",
6
+ "amount" : 5000,
7
+ "from_walletable_type" : "bank_account",
8
+ "from_walletable_id" : 101,
9
+ "to_walletable_type" : "credit_card",
10
+ "to_walletable_id" : 201,
11
+ "description" : "備考"
12
+ }
13
+ }
@@ -0,0 +1,37 @@
1
+ {
2
+ "transfers" : [
3
+ {
4
+ "id" : 101,
5
+ "company_id" : 1,
6
+ "date" : "2013-01-01",
7
+ "amount" : 5000,
8
+ "from_walletable_type" : "bank_account",
9
+ "from_walletable_id" : 101,
10
+ "to_walletable_type" : "credit_card",
11
+ "to_walletable_id" : 201,
12
+ "description" : "備考"
13
+ },
14
+ {
15
+ "id" : 102,
16
+ "company_id" : 1,
17
+ "date" : "2013-02-01",
18
+ "amount" : 5000,
19
+ "from_walletable_type" : "bank_account",
20
+ "from_walletable_id" : 101,
21
+ "to_walletable_type" : "credit_card",
22
+ "to_walletable_id" : 201,
23
+ "description" : "備考"
24
+ },
25
+ {
26
+ "id" : 103,
27
+ "company_id" : 1,
28
+ "date" : "2013-03-01",
29
+ "amount" : 5000,
30
+ "from_walletable_type" : "bank_account",
31
+ "from_walletable_id" : 101,
32
+ "to_walletable_type" : "credit_card",
33
+ "to_walletable_id" : 201,
34
+ "description" : "備考"
35
+ }
36
+ ]
37
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "user" : {
3
+ "email" : "example@freee.co.jp",
4
+ "display_name" : "フリー太郎",
5
+ "first_name" : "太郎",
6
+ "last_name" : "フリー",
7
+ "first_name_kana" : "たろう",
8
+ "last_name_kana" : "ふりー"
9
+ }
10
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "user" : {
3
+ "email" : "example@freee.co.jp",
4
+ "display_name" : "フリー太郎",
5
+ "first_name" : "太郎",
6
+ "last_name" : "フリー",
7
+ "first_name_kana" : "たろう",
8
+ "last_name_kana" : "ふりー",
9
+ "companies" : [
10
+ {
11
+ "id" : 101,
12
+ "name" : "freee事務所",
13
+ "name_kana" : "フリージムショ",
14
+ "display_name" : "freee事務所",
15
+ "role" : "admin"
16
+ }
17
+ ]
18
+ }
19
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "wallet_txn" : {
3
+ "id" : 101,
4
+ "company_id" : 1,
5
+ "date" : "2013-01-01",
6
+ "amount" : 5000,
7
+ "due_amount" : 0,
8
+ "balance" : 10000,
9
+ "entry_side" : "income",
10
+ "walletable_type" : "bank_account",
11
+ "walletable_id" : 101,
12
+ "description" : "振込 カ)ABC"
13
+ }
14
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "wallet_txns" : [
3
+ {
4
+ "id" : 101,
5
+ "company_id" : 1,
6
+ "date" : "2013-01-01",
7
+ "amount" : 5000,
8
+ "due_amount" : 0,
9
+ "balance" : 10000,
10
+ "entry_side" : "income",
11
+ "walletable_type" : "bank_account",
12
+ "walletable_id" : 101,
13
+ "description" : "振込 カ)ABC"
14
+ }
15
+ ]
16
+ }
@@ -0,0 +1 @@
1
+ {"id":10,"name":"〇〇銀行","type":"bank_account"}
@@ -0,0 +1,9 @@
1
+ {
2
+ "walletables" : [
3
+ {
4
+ "id" : 101,
5
+ "name" : "〇〇銀行",
6
+ "type" : "bank_account"
7
+ }
8
+ ]
9
+ }
@@ -1,30 +1,83 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Freee::Item 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(:item) { Freee::Item }
9
-
10
- before(:each) do
11
- Freee::Base.config(client_id, secret_key, token)
12
- end
13
4
 
14
- describe 'should can be able to create instance' do
15
- subject { item.list(company_id) }
16
- it { is_expected.not_to be_nil }
17
- it { is_expected.to be_instance_of(Freee::Response::Item) }
5
+ let(:company_id) { -1 }
6
+ let(:params) { fixture('create_deal.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::Item
18
12
  end
19
13
 
20
- describe 'should get information of first item for the company' do
21
- subject { item.list(company_id)['items'].first }
14
+ describe 'item' do
15
+ context '#list' do
16
+ before do
17
+ stub_get('/api/1/items?company_id=-1').to_return(body: fixture('items.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/items?company_id=-1')
24
+ end
25
+
26
+ it 'should can be able to create instance' do
27
+ expect(@responses).to include('items')
28
+ end
29
+
30
+ describe 'should can be able to create instance' do
31
+ subject { @responses }
32
+
33
+ it { is_expected.not_to be_nil }
34
+ it { is_expected.to be_instance_of(Freee::Response::Item) }
35
+ end
36
+
37
+ describe 'should get information of first item for the company' do
38
+ subject { @responses['items'].first }
39
+
40
+ it { is_expected.not_to be_nil }
41
+ it { is_expected.to include('id') }
42
+ it { is_expected.to include('company_id') }
43
+ it { is_expected.to include('name') }
44
+ it { is_expected.to include('shortcut1') }
45
+ it { is_expected.to include('shortcut2') }
46
+ end
47
+ end
48
+
49
+ context '#create' do
50
+ before do
51
+ stub_post('/api/1/items').
52
+ with(body: json).
53
+ to_return(body: fixture('item.json'), headers: {content_type: 'application/json; charset=utf-8'} )
54
+ @responses = @client.create(params)
55
+ end
56
+ after { WebMock.reset! }
57
+
58
+ it 'requests the correct resource' do
59
+ assert_request_requested a_post('/api/1/items').with(body: json)
60
+ end
61
+
62
+ it 'should can be able to create instance' do
63
+ expect(@responses).to include('item')
64
+ end
65
+
66
+ describe 'should can be able to create instance' do
67
+ subject { @responses }
68
+ it { is_expected.to be_instance_of(Freee::Response::Item) }
69
+ end
70
+
71
+ describe 'should get information of first item for the company' do
72
+ subject { @responses['item'] }
22
73
 
23
- it { is_expected.not_to be_nil }
24
- it { is_expected.to include('id') }
25
- it { is_expected.to include('company_id') }
26
- it { is_expected.to include('name') }
27
- it { is_expected.to include('shortcut1') }
28
- it { is_expected.to include('shortcut2') }
74
+ it { is_expected.not_to be_nil }
75
+ it { is_expected.to include('id') }
76
+ it { is_expected.to include('company_id') }
77
+ it { is_expected.to include('name') }
78
+ it { is_expected.to include('shortcut1') }
79
+ it { is_expected.to include('shortcut2') }
80
+ end
81
+ end
29
82
  end
30
83
  end
@@ -1,30 +1,68 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Freee::Partner 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(:partner) { Freee::Partner }
9
-
10
- before(:each) do
11
- Freee::Base.config(client_id, secret_key, token)
12
- end
13
4
 
14
- it 'should can be able to create instance' do
15
- subject { partner.list(company_id) }
16
- it { is_expected.not_to be_nil }
17
- it { is_expected.to be_instance_of(Freee::Response::Partner) }
5
+ let(:company_id) { -1 }
6
+ let(:params) { fixture('create_partner.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::Partner
18
12
  end
13
+ describe 'partner' do
14
+ context '#list' do
15
+ before do
16
+ stub_get('/api/1/partners?company_id=-1').to_return(body: fixture('partners.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::Partner) }
26
+ end
27
+
28
+ describe 'should get partners of first item for the company' do
29
+ subject { @responses['partners'].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/partners').
43
+ with(body: json).
44
+ to_return(body: fixture('partner.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::Partner) }
54
+ end
19
55
 
20
- describe 'should get partners of first item for the company' do
21
- subject { partner.list(company_id)['partners'].first }
56
+ describe 'should get partners of first item for the company' do
57
+ subject { @responses['partner'] }
22
58
 
23
- it { is_expected.not_to be_nil }
24
- it { is_expected.to include('id') }
25
- it { is_expected.to include('company_id') }
26
- it { is_expected.to include('name') }
27
- it { is_expected.to include('shortcut1') }
28
- it { is_expected.to include('shortcut2') }
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
29
67
  end
30
68
  end
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ describe Freee::Section do
4
+
5
+ let(:company_id) { -1 }
6
+ let(:params) { fixture('create_section.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::Section
12
+ end
13
+ describe 'section' do
14
+ context '#list' do
15
+ before do
16
+ stub_get('/api/1/sections?company_id=-1').to_return(body: fixture('sections.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::Section) }
26
+ end
27
+
28
+ describe 'should get sections of first item for the company' do
29
+ subject { @responses['sections'].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/sections').
43
+ with(body: json).
44
+ to_return(body: fixture('section.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::Section) }
54
+ end
55
+
56
+ describe 'should get sections of first item for the company' do
57
+ subject { @responses['section'] }
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