freee 0.3.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7775dac3cdd570593801f5cb42c8feb777309c8d
|
4
|
+
data.tar.gz: acbcaf03d3bab36d0a9cbdf23c2be8f84977737a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 600303de998cee8f7ece820c5c8b51c685a7d15ccdd21a22d83183dec6cbca0ba7eca590eff98f6ef45f6b6aaf0ea26e5a68954c3744c2b7a1aaba32c0a30877
|
7
|
+
data.tar.gz: 58d9b02faf0d017bf12d21335d7be0612407888d65727b1dd4b6648bb7c2867d009e1c2ff8219359ce806ef389d58397226a2c348130ed502f3b70b7d7ff3dc4
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
Ruby implementation of the freee API.
|
4
4
|
|
5
|
+
# Document
|
6
|
+
|
7
|
+
- [freee API v1.0](https://gist.github.com/yokoji/822edacff497b21fa7bf)(Japanese)
|
8
|
+
|
5
9
|
## Installation
|
6
10
|
|
7
11
|
Add this line to your application's Gemfile:
|
@@ -31,8 +35,28 @@ Or install it yourself as:
|
|
31
35
|
|
32
36
|
### Generate token
|
33
37
|
|
38
|
+
- Generate application token
|
39
|
+
|
40
|
+
```
|
41
|
+
> freee token \
|
42
|
+
--client-id=$FREEE_CLIENT_ID \
|
43
|
+
--secret-key=$FREEE_SECRET_KEY \
|
44
|
+
--redirect-uri=$FREEE_REDIRECT_URI \
|
45
|
+
--authorization-code=$FREEE_AUTHORIZATION_CODE
|
46
|
+
Token: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
47
|
+
RefreshToken: YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
|
48
|
+
```
|
49
|
+
|
50
|
+
- Refresh application token
|
51
|
+
|
34
52
|
```
|
35
|
-
> freee token
|
53
|
+
> freee token \
|
54
|
+
--client-id=$FREEE_CLIENT_ID \
|
55
|
+
--secret-key=$FREEE_SECRET_KEY \
|
56
|
+
--redirect-uri=$FREEE_REDIRECT_URI \
|
57
|
+
--refresh-token=$FREEE_REFRESH_TOKEN
|
58
|
+
Token: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
59
|
+
RefreshToken: YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
|
36
60
|
```
|
37
61
|
|
38
62
|
## Contributing
|
data/freee.gemspec
CHANGED
@@ -27,5 +27,7 @@ Gem::Specification.new do |spec|
|
|
27
27
|
|
28
28
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
29
29
|
spec.add_development_dependency 'rake'
|
30
|
+
spec.add_development_dependency 'pry'
|
30
31
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
32
|
+
spec.add_development_dependency 'webmock'
|
31
33
|
end
|
data/lib/freee/base.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'uri'
|
2
|
+
require 'json'
|
2
3
|
|
3
4
|
module Freee
|
4
5
|
def client
|
@@ -15,6 +16,13 @@ module Freee
|
|
15
16
|
end
|
16
17
|
module_function :encode_params
|
17
18
|
|
19
|
+
def encode_json(params)
|
20
|
+
JSON.parse(params).to_json
|
21
|
+
rescue
|
22
|
+
'?' + URI.encode_www_form(JSON.parse(params, quirks_mode: true))
|
23
|
+
end
|
24
|
+
module_function :encode_json
|
25
|
+
|
18
26
|
def includes(file_path, search_path)
|
19
27
|
Dir.glob(File.realpath(File.dirname(file_path)) + '/' + search_path).map do |f|
|
20
28
|
require f if FileTest.file?(f)
|
@@ -62,8 +70,11 @@ module Freee
|
|
62
70
|
return Freee::Response::Type.convert(response, type)
|
63
71
|
end
|
64
72
|
|
65
|
-
def post(path, type=nil,
|
66
|
-
response = @client.post(path, { params:
|
73
|
+
def post(path, type=nil, params)
|
74
|
+
response = @client.post(path, { body: {params: params} }).response.env[:body]
|
75
|
+
rescue
|
76
|
+
response = @client.post(path + params).response.env[:body]
|
77
|
+
ensure
|
67
78
|
return Freee::Response::Type.convert(response, type)
|
68
79
|
end
|
69
80
|
|
data/lib/freee/company.rb
CHANGED
data/lib/freee/deal.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
module Freee
|
2
2
|
class Deal < Freee::Base
|
3
|
-
|
4
|
-
|
3
|
+
|
4
|
+
def self.create(json)
|
5
|
+
params = Freee.encode_json(json)
|
6
|
+
Freee.client.post('/api//1/deals', :deal, params)
|
5
7
|
end
|
6
8
|
|
7
9
|
def self.list(company_id, **kwargs)
|
data/lib/freee/item.rb
CHANGED
data/lib/freee/obj/response.rb
CHANGED
data/lib/freee/partner.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
module Freee
|
2
2
|
class Partner < Freee::Base
|
3
|
-
|
4
|
-
|
3
|
+
|
4
|
+
def self.create(json)
|
5
|
+
params = Freee.encode_json(json)
|
6
|
+
Freee.client.post('/api/1/partners', :partner, params)
|
5
7
|
end
|
6
8
|
|
7
9
|
def self.list(company_id)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Freee
|
2
|
+
class Section < Freee::Base
|
3
|
+
def self.create(json)
|
4
|
+
params = Freee.encode_json(json)
|
5
|
+
Freee.client.post('/api/1/sections', :section, params)
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.list(company_id)
|
9
|
+
Freee.client.get(
|
10
|
+
"/api/1/sections?company_id=#{company_id.to_i}",
|
11
|
+
:section
|
12
|
+
)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/freee/tag.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module Freee
|
2
|
+
class Tag < Freee::Base
|
3
|
+
def self.create(json)
|
4
|
+
params = Freee.encode_json(json)
|
5
|
+
Freee.client.post('/api/1/tags', :tag, params)
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.list(company_id)
|
9
|
+
Freee.client.get(
|
10
|
+
"/api/1/tags?company_id=#{company_id.to_i}",
|
11
|
+
:tag
|
12
|
+
)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/freee/tax.rb
CHANGED
@@ -3,12 +3,12 @@ module Freee
|
|
3
3
|
def self.list(company_id)
|
4
4
|
Freee.client.get(
|
5
5
|
"/api/1/taxes?company_id=#{company_id.to_i}",
|
6
|
-
:
|
6
|
+
:taxes
|
7
7
|
)
|
8
8
|
end
|
9
9
|
|
10
10
|
def self.list_of_code
|
11
|
-
Freee.client.get('/api/1/taxes/codes', :
|
11
|
+
Freee.client.get('/api/1/taxes/codes', :taxes)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
data/lib/freee/transfer.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
module Freee
|
2
2
|
class Transfer < Freee::Base
|
3
|
-
|
4
|
-
|
3
|
+
|
4
|
+
def self.create(json)
|
5
|
+
params = Freee.encode_json(json)
|
6
|
+
Freee.client.post('/api//1/transfers', :transfer, params)
|
5
7
|
end
|
6
8
|
|
7
9
|
def self.list(company_id, **kwargs)
|
data/lib/freee/version.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
module Freee
|
2
|
-
class
|
3
|
-
def self.create(
|
4
|
-
Freee.
|
2
|
+
class WalletTxn < Freee::Base
|
3
|
+
def self.create(json)
|
4
|
+
params = Freee.encode_json(json)
|
5
|
+
Freee.client.post('/api/1/wallet_txns', :wallet_txn, json)
|
5
6
|
end
|
6
7
|
|
7
8
|
def self.list(company_id, **kwargs)
|
8
9
|
params = Freee.encode_params(kwargs)
|
9
10
|
Freee.client.get(
|
10
11
|
"/api/1/wallet_txns?company_id=#{company_id.to_i}#{params}",
|
11
|
-
:
|
12
|
+
:wallet_txn
|
12
13
|
)
|
13
14
|
end
|
14
15
|
end
|
data/lib/freee/walletable.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
module Freee
|
2
2
|
class Walletable < Freee::Base
|
3
|
+
def self.create(json)
|
4
|
+
params = Freee.encode_json(json)
|
5
|
+
Freee.client.post('/api/1/walletables', :walletable, params)
|
6
|
+
end
|
7
|
+
|
8
|
+
|
3
9
|
def self.list(company_id)
|
4
10
|
Freee.client.get(
|
5
11
|
"/api/1/walletables?company_id=#{company_id.to_i}",
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
describe Freee::AccountItem do
|
4
|
+
|
5
|
+
let(:company_id) { -1 }
|
6
|
+
|
7
|
+
before do
|
8
|
+
Freee::Base.config(get_client_id, get_secret_key, get_token)
|
9
|
+
@client = Freee::AccountItem
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#list' do
|
13
|
+
before do
|
14
|
+
stub_get('/api/1/account_items?company_id=-1').to_return(body: fixture('account_items.json'), headers: {content_type: 'application/json; charset=utf-8'} )
|
15
|
+
@responses = @client.list(company_id)
|
16
|
+
end
|
17
|
+
after { WebMock.reset! }
|
18
|
+
|
19
|
+
it 'requests the correct resource' do
|
20
|
+
assert_request_requested a_get('/api/1/account_items?company_id=-1')
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should can be able to create instance' do
|
24
|
+
expect(@responses).to include('account_items')
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'should be get information of account' do
|
28
|
+
subject { @responses }
|
29
|
+
it { is_expected.to include('account_items') }
|
30
|
+
it { is_expected.to be_instance_of(Freee::Response::AccountItem) }
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'should be get information of account_items' do
|
34
|
+
subject { @responses['account_items'].first }
|
35
|
+
|
36
|
+
it { is_expected.not_to be_nil }
|
37
|
+
it { is_expected.to include('id') }
|
38
|
+
it { is_expected.to include('name') }
|
39
|
+
it { is_expected.to include('shortcut') }
|
40
|
+
it { is_expected.to include('default_tax_id') }
|
41
|
+
it { is_expected.to include('categories') }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/spec/base_spec.rb
CHANGED
@@ -1,20 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Freee::Base do
|
4
|
-
|
5
|
-
let(:secret_key) { get_secret_key }
|
6
|
-
let(:token) { get_token }
|
4
|
+
|
7
5
|
let(:freee) { Freee::Base.new }
|
8
6
|
|
9
|
-
before
|
10
|
-
Freee::Base.config(
|
7
|
+
before :each do
|
8
|
+
Freee::Base.config(get_client_id, get_secret_key, get_token)
|
11
9
|
end
|
12
10
|
|
13
11
|
it 'should be able to get client' do
|
14
12
|
expect(freee.client).not_to be_nil
|
15
13
|
end
|
16
|
-
|
17
|
-
it 'should be call of get by Freee' do
|
18
|
-
expect(freee.client.get('/api/1/users/me?companies=true')).to include("user")
|
19
|
-
end
|
20
14
|
end
|
data/spec/company_spec.rb
CHANGED
@@ -1,45 +1,62 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Freee::Company 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(:company) { Freee::Company }
|
9
|
-
|
10
|
-
before(:each) do
|
11
|
-
Freee::Base.config(client_id, secret_key, token)
|
12
|
-
end
|
13
|
-
|
14
|
-
describe 'should can be able to create instance' do
|
15
|
-
subject { company.list }
|
16
|
-
it { is_expected.not_to be_nil }
|
17
|
-
it { is_expected.to be_instance_of(Freee::Response::Company) }
|
18
|
-
end
|
19
4
|
|
20
|
-
|
21
|
-
subject { company.list["companies"].first }
|
5
|
+
let(:company_id) { -1 }
|
22
6
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
it { is_expected.to include('display_name') }
|
7
|
+
before do
|
8
|
+
Freee::Base.config(get_client_id, get_secret_key, get_token)
|
9
|
+
@client = Freee::Company
|
27
10
|
end
|
28
|
-
|
29
|
-
describe 'should be get item of the company' do
|
30
|
-
subject { company.list_of_details(company_id) }
|
31
|
-
|
32
|
-
it { is_expected.to include('company') }
|
33
|
-
end
|
34
|
-
|
35
|
-
describe 'should be get information of item for the company' do
|
36
|
-
subject { company.list_of_details(company_id)['company'] }
|
37
11
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
12
|
+
describe 'company' do
|
13
|
+
context '#list' do
|
14
|
+
before do
|
15
|
+
stub_get('/api/1/companies').to_return(body: fixture('companies.json'), headers: {content_type: 'application/json; charset=utf-8'} )
|
16
|
+
@responses = @client.list
|
17
|
+
end
|
18
|
+
after { WebMock.reset! }
|
19
|
+
|
20
|
+
it 'requests the correct resource' do
|
21
|
+
assert_request_requested a_get('/api/1/companies')
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should can be able to create instance' do
|
25
|
+
expect(@responses).to include('companies')
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'should can be able to create instance' do
|
29
|
+
subject { @responses }
|
30
|
+
it { is_expected.not_to be_nil }
|
31
|
+
it { is_expected.to be_instance_of(Freee::Response::Company) }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context '#show' do
|
36
|
+
before do
|
37
|
+
stub_get('/api/1/companies/-1').to_return(body: fixture('company.json'), headers: {content_type: 'application/json; charset=utf-8'} )
|
38
|
+
@responses = @client.show(company_id)
|
39
|
+
end
|
40
|
+
after { WebMock.reset! }
|
41
|
+
|
42
|
+
it 'requests the correct resource' do
|
43
|
+
assert_request_requested a_get('/api/1/companies/-1')
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should can be able to create instance' do
|
47
|
+
expect(@responses).to include('company')
|
48
|
+
end
|
49
|
+
|
50
|
+
describe 'should be get information of item for the company' do
|
51
|
+
subject { @responses['company'] }
|
52
|
+
|
53
|
+
it { is_expected.not_to be_nil }
|
54
|
+
it { is_expected.to include('id') }
|
55
|
+
it { is_expected.to include('name') }
|
56
|
+
it { is_expected.to include('name_kana') }
|
57
|
+
it { is_expected.to include('display_name') }
|
58
|
+
it { is_expected.to include('role') }
|
59
|
+
end
|
60
|
+
end
|
44
61
|
end
|
45
62
|
end
|