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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d1c589c590102035d3d89a4a526279973333251c
4
- data.tar.gz: d47aa633efefa7fd6432efdcde48c6d6f11b4a8f
3
+ metadata.gz: 7775dac3cdd570593801f5cb42c8feb777309c8d
4
+ data.tar.gz: acbcaf03d3bab36d0a9cbdf23c2be8f84977737a
5
5
  SHA512:
6
- metadata.gz: 3f43e6a967186c45ad4bcd7015a430628551e211c44d67600a6c597ab81be8695fa5e1a03d1a554dffb109003f8cd5d9c76bbb6ccebe39f9e2740de29544bb6e
7
- data.tar.gz: 0ae697091e7b4ce21c0198285a1da78665f70ad5e3596809bc1e9d12fdd6fd3dbaa5ebcf78bc50daa2a84f337db788c8740c16800a0f9564b4e68c08ab430f80
6
+ metadata.gz: 600303de998cee8f7ece820c5c8b51c685a7d15ccdd21a22d83183dec6cbca0ba7eca590eff98f6ef45f6b6aaf0ea26e5a68954c3744c2b7a1aaba32c0a30877
7
+ data.tar.gz: 58d9b02faf0d017bf12d21335d7be0612407888d65727b1dd4b6648bb7c2867d009e1c2ff8219359ce806ef389d58397226a2c348130ed502f3b70b7d7ff3dc4
data/.gitignore CHANGED
@@ -21,3 +21,4 @@ tmp
21
21
  *.a
22
22
  mkmf.log
23
23
  vendor/*
24
+ .DS_Store
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
@@ -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
@@ -1,9 +1,9 @@
1
1
  module Freee
2
- class Account < Freee::Base
3
- def self.items(company_id)
2
+ class AccountItem < Freee::Base
3
+ def self.list(company_id)
4
4
  Freee.client.get(
5
5
  "/api/1/account_items?company_id=#{company_id.to_i}",
6
- :account
6
+ :account_item
7
7
  )
8
8
  end
9
9
  end
@@ -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, **kwargs)
66
- response = @client.post(path, { params: kwargs }).response.env[:body]
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
 
@@ -7,5 +7,9 @@ module Freee
7
7
  def self.list_of_details(company_id)
8
8
  Freee.client.get("/api/1/companies/#{company_id.to_i}", :company)
9
9
  end
10
+
11
+ class << self
12
+ alias :show :list_of_details
13
+ end
10
14
  end
11
15
  end
@@ -1,7 +1,9 @@
1
1
  module Freee
2
2
  class Deal < Freee::Base
3
- def create
4
- Freeee.client.post('/api/1/deals', :deals, **kwargs)
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)
@@ -1,7 +1,9 @@
1
1
  module Freee
2
2
  class Item < Freee::Base
3
- def create
4
- Freee.client.post('/api/1/items', :item, **kwargs)
3
+
4
+ def self.create(json)
5
+ params = Freee.encode_json(json)
6
+ Freee.client.post('/api/1/items', :item, params)
5
7
  end
6
8
 
7
9
  def self.list(company_id)
@@ -0,0 +1,5 @@
1
+ module Freee::Response
2
+ class AccountItem < Base
3
+ end
4
+ end
5
+
@@ -30,7 +30,7 @@ module Freee::Response
30
30
 
31
31
  class Type
32
32
  def self.convert(response, type=nil)
33
- klass = "Freee::Response::#{type.to_s.capitalize}".constantize
33
+ klass = "Freee::Response::#{type.to_s.classify}".constantize
34
34
  klass.new(response)
35
35
  end
36
36
  end
@@ -1,5 +1,5 @@
1
1
  module Freee::Response
2
- class Account < Base
2
+ class Section < Base
3
3
  end
4
4
  end
5
5
 
@@ -1,5 +1,5 @@
1
1
  module Freee::Response
2
- class Wallet < Base
2
+ class Tag < Base
3
3
  end
4
4
  end
5
5
 
@@ -1,5 +1,5 @@
1
1
  module Freee::Response
2
- class Amount < Base
2
+ class WalletTxn < Base
3
3
  end
4
4
  end
5
5
 
@@ -1,7 +1,9 @@
1
1
  module Freee
2
2
  class Partner < Freee::Base
3
- def self.create
4
- Freee.client.post('/api/1/partners', :partner, **kwargs)
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
@@ -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
@@ -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
- :tax
6
+ :taxes
7
7
  )
8
8
  end
9
9
 
10
10
  def self.list_of_code
11
- Freee.client.get('/api/1/taxes/codes', :tax)
11
+ Freee.client.get('/api/1/taxes/codes', :taxes)
12
12
  end
13
13
  end
14
14
  end
@@ -1,7 +1,9 @@
1
1
  module Freee
2
2
  class Transfer < Freee::Base
3
- def self.create
4
- Freee.client.post('/api/1/transfers', :transfer, **kwargs)
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)
@@ -1,3 +1,3 @@
1
1
  module Freee
2
- VERSION = "0.3.1"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -1,14 +1,15 @@
1
1
  module Freee
2
- class Wallet < Freee::Base
3
- def self.create(**kwargs)
4
- Freee.client.post('/api/1/wallet_txns', :wallet, **kwargs)
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
- :wallet
12
+ :wallet_txn
12
13
  )
13
14
  end
14
15
  end
@@ -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
@@ -1,20 +1,14 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Freee::Base do
4
- let(:client_id) { get_client_id }
5
- let(:secret_key) { get_secret_key }
6
- let(:token) { get_token }
4
+
7
5
  let(:freee) { Freee::Base.new }
8
6
 
9
- before(:each) do
10
- Freee::Base.config(client_id, secret_key, token)
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
@@ -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
- describe 'should be get first list of company' do
21
- subject { company.list["companies"].first }
5
+ let(:company_id) { -1 }
22
6
 
23
- it { is_expected.to include('id') }
24
- it { is_expected.to include('name') }
25
- it { is_expected.to include('name_kana') }
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
- it { is_expected.not_to be_nil }
39
- it { is_expected.to include('id') }
40
- it { is_expected.to include('name') }
41
- it { is_expected.to include('name_kana') }
42
- it { is_expected.to include('display_name') }
43
- it { is_expected.to include('role') }
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