mf_cloud-invoice 0.1.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 +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +206 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/mf_cloud/invoice.rb +10 -0
- data/lib/mf_cloud/invoice/api/base.rb +76 -0
- data/lib/mf_cloud/invoice/api/billing.rb +13 -0
- data/lib/mf_cloud/invoice/api/item.rb +13 -0
- data/lib/mf_cloud/invoice/api/office.rb +19 -0
- data/lib/mf_cloud/invoice/api/partner.rb +13 -0
- data/lib/mf_cloud/invoice/client.rb +129 -0
- data/lib/mf_cloud/invoice/collection/base.rb +23 -0
- data/lib/mf_cloud/invoice/collection/billing_collection.rb +14 -0
- data/lib/mf_cloud/invoice/collection/department_collection.rb +13 -0
- data/lib/mf_cloud/invoice/collection/item_collection.rb +14 -0
- data/lib/mf_cloud/invoice/collection/meta_data.rb +9 -0
- data/lib/mf_cloud/invoice/collection/partner_collection.rb +14 -0
- data/lib/mf_cloud/invoice/configure.rb +15 -0
- data/lib/mf_cloud/invoice/errors.rb +15 -0
- data/lib/mf_cloud/invoice/model/base.rb +32 -0
- data/lib/mf_cloud/invoice/model/billing.rb +20 -0
- data/lib/mf_cloud/invoice/model/department.rb +10 -0
- data/lib/mf_cloud/invoice/model/document_status.rb +9 -0
- data/lib/mf_cloud/invoice/model/item.rb +10 -0
- data/lib/mf_cloud/invoice/model/office.rb +9 -0
- data/lib/mf_cloud/invoice/model/partner.rb +15 -0
- data/lib/mf_cloud/invoice/version.rb +5 -0
- data/mf_cloud-invoice.gemspec +30 -0
- metadata +178 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1f19dc65ed2ef9229717177a3194b64391ed52af
|
4
|
+
data.tar.gz: 3be1c63e99fc969d55387dd71a547b90f16921cd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ccd19d0342fadeaa4e447193796d23ecfaab20c7ff7888de007d4659e602d79ba5f9f419a2b561734ab056fe2dc659252e3172a7151f86f7762b0cf4934f37a3
|
7
|
+
data.tar.gz: b1e2eb57186b6ccb3315d852a07fd32dee7e62e7a657277ad862b5870058596b83d5f72d8f41c8efce4183d9c52f4a22e26df7cf848bab5adc950cd0c1753fd9
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Izumiya Keisuke
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,206 @@
|
|
1
|
+
# mf_cloud-invoice-ruby
|
2
|
+
|
3
|
+
[MFクラウド請求書API](https://github.com/moneyforward/invoice-api-doc) client library for Ruby
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'mf_cloud-invoice'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install mf_cloud-invoice
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### Build client
|
24
|
+
```ruby
|
25
|
+
require 'mf_cloud/invoice'
|
26
|
+
|
27
|
+
client = MfCloud::Invoice::Client.new(access_token: 'YOUR_ACCESS_TOKEN')
|
28
|
+
|
29
|
+
# or
|
30
|
+
|
31
|
+
client = MfCloud::Invoice::Client.new do |client|
|
32
|
+
client.access_token = 'YOUR_ACCESS_TOKEN'
|
33
|
+
end
|
34
|
+
|
35
|
+
client.billings.all
|
36
|
+
#=> Your Billings
|
37
|
+
```
|
38
|
+
|
39
|
+
### Basic usage
|
40
|
+
|
41
|
+
#### Office
|
42
|
+
```ruby
|
43
|
+
# get information
|
44
|
+
office = client.office.get #=> returns MfCloud::Invoice::Model::Office instance
|
45
|
+
|
46
|
+
p office.name # you can access parameters using getter method
|
47
|
+
#=> 'Sample office'
|
48
|
+
|
49
|
+
# update information
|
50
|
+
params = {
|
51
|
+
name: 'section9',
|
52
|
+
zip: '101-1111'
|
53
|
+
}
|
54
|
+
|
55
|
+
updated_office = client.office.update(params)
|
56
|
+
p updated_office.name
|
57
|
+
#=> 'section9'
|
58
|
+
|
59
|
+
p updated_office.zip
|
60
|
+
#=> '101-1111'
|
61
|
+
```
|
62
|
+
|
63
|
+
#### Billings
|
64
|
+
```ruby
|
65
|
+
# get all billings(all, but using paging)
|
66
|
+
billings = client.billings.all #=> returns MfCloud::Invoice::Collection::BillingCollection instance
|
67
|
+
|
68
|
+
p billings.count # MfCloud::Invoice::Collection::BillingCollection can receive methods of Array
|
69
|
+
#=> 3
|
70
|
+
|
71
|
+
p billings.meta.current_page # meta has parameters of meta data(ex. paging parameter)
|
72
|
+
#=> 1
|
73
|
+
|
74
|
+
billings = client.billings.all(page: 2) # you can pass paging parameter
|
75
|
+
p billings.meta.current_page # meta has parameters of meta data(ex. paging parameter)
|
76
|
+
#=> 2
|
77
|
+
|
78
|
+
# get billing specified by id
|
79
|
+
billing = client.billings.get(id)
|
80
|
+
#=> returns MfCloud::Invoice::Model::Billing instance
|
81
|
+
|
82
|
+
p billing.total_price # you can access parameters using getter method
|
83
|
+
#=> '10000'
|
84
|
+
|
85
|
+
# create new billing
|
86
|
+
client.billings.create(params_hash)
|
87
|
+
|
88
|
+
# update billing
|
89
|
+
client.billings.update(id, params_hash) # NOTE: params_hash does not need id
|
90
|
+
|
91
|
+
# delete billing
|
92
|
+
client.billings.delete(id)
|
93
|
+
#=> true
|
94
|
+
```
|
95
|
+
|
96
|
+
About available parameters, see [API doc](https://github.com/moneyforward/invoice-api-doc#請求書api)
|
97
|
+
|
98
|
+
#### Partners
|
99
|
+
```ruby
|
100
|
+
# get all partners(all, but using paging)
|
101
|
+
partners = client.partners.all #=> returns MfCloud::Invoice::Collection::PartnerCollection instance
|
102
|
+
|
103
|
+
p partners.count # MfCloud::Invoice::Collection::PartnerCollection can receive methods of Array
|
104
|
+
#=> 3
|
105
|
+
|
106
|
+
p partners.meta.current_page # meta has parameters of meta data(ex. paging parameter)
|
107
|
+
#=> 1
|
108
|
+
|
109
|
+
partners = client.partners.all(page: 2) # you can pass paging parameter
|
110
|
+
p partners.meta.current_page # meta has parameters of meta data(ex. paging parameter)
|
111
|
+
#=> 2
|
112
|
+
|
113
|
+
# get partner specified by id
|
114
|
+
partner = client.partners.get(id)
|
115
|
+
#=> returns MfCloud::Invoice::Model::Partner instance
|
116
|
+
|
117
|
+
p partner.name # you can access parameters using getter method
|
118
|
+
#=> 'sample name'
|
119
|
+
|
120
|
+
# create new partner
|
121
|
+
client.partners.create(params_hash)
|
122
|
+
|
123
|
+
# update partner
|
124
|
+
client.partners.update(id, params_hash) # NOTE: params_hash does not need id
|
125
|
+
|
126
|
+
# delete partner
|
127
|
+
client.partners.delete(id)
|
128
|
+
#=> true
|
129
|
+
```
|
130
|
+
|
131
|
+
About available parameters, see [API doc](https://github.com/moneyforward/invoice-api-doc#取引先api)
|
132
|
+
|
133
|
+
#### Items
|
134
|
+
```ruby
|
135
|
+
# get all items(all, but using paging)
|
136
|
+
items = client.items.all #=> returns MfCloud::Invoice::Collection::ItemCollection instance
|
137
|
+
|
138
|
+
p items.count # MfCloud::Invoice::Collection::ItemCollection can receive methods of Array
|
139
|
+
#=> 3
|
140
|
+
|
141
|
+
p items.meta.current_page # meta has parameters of meta data(ex. paging parameter)
|
142
|
+
#=> 1
|
143
|
+
|
144
|
+
items = client.items.all(page: 2) # you can pass paging parameter
|
145
|
+
p items.meta.current_page # meta has parameters of meta data(ex. paging parameter)
|
146
|
+
#=> 2
|
147
|
+
|
148
|
+
# get item specified by id
|
149
|
+
item = client.items.get(id)
|
150
|
+
#=> returns MfCloud::Invoice::Model::Item instance
|
151
|
+
|
152
|
+
p item.price # you can access parameters using getter method
|
153
|
+
#=> 100
|
154
|
+
|
155
|
+
# create new item
|
156
|
+
client.items.create(params_hash)
|
157
|
+
|
158
|
+
# update item
|
159
|
+
client.items.update(id, params_hash) # NOTE: params_hash does not need id
|
160
|
+
|
161
|
+
# delete item
|
162
|
+
client.items.delete(id)
|
163
|
+
#=> true
|
164
|
+
```
|
165
|
+
|
166
|
+
About available parameters, see [API doc](https://github.com/moneyforward/invoice-api-doc#品目api)
|
167
|
+
|
168
|
+
### Errors
|
169
|
+
* MfCloud::Invoice::InvalidAccessToken
|
170
|
+
Access token is nil or invalid or expired.
|
171
|
+
|
172
|
+
* MfCloud::Invoice::PaymentRequired
|
173
|
+
The number of object is over than payment plan limit.
|
174
|
+
For example, when using Starter plan, number of partner limit is 3.
|
175
|
+
See [plan detail](https://invoice.moneyforward.com/pricing).
|
176
|
+
|
177
|
+
* MfCloud::Invoice::InvalidRequest
|
178
|
+
Parameter is collect but validation is not passed.
|
179
|
+
|
180
|
+
* MfCloud::Invoice::ResourceNotFound
|
181
|
+
Request id is invalid. This raises not only request resouce id, also id in parameters(For example, department_id when updating a billing).
|
182
|
+
|
183
|
+
* MfCloud::Invoice::InvalidParameter
|
184
|
+
Parameter format is invalid or necessaly parameter is missing.
|
185
|
+
|
186
|
+
* MfCloud::Invoice::RateLimitted
|
187
|
+
Up to rate limit.
|
188
|
+
See [here](https://github.com/moneyforward/invoice-api-doc#プランごとの利用制限について)
|
189
|
+
|
190
|
+
* MfCloud::Invoice::InternalServerError
|
191
|
+
Unexpected error has happen. Almost case it's success sometime later. Almost case, it will be success some time later. Please try few minits later.
|
192
|
+
|
193
|
+
## Development
|
194
|
+
|
195
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
196
|
+
|
197
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
198
|
+
|
199
|
+
## Contributing
|
200
|
+
|
201
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/moneyforward/mf_cloud-invoice.
|
202
|
+
|
203
|
+
|
204
|
+
## License
|
205
|
+
|
206
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "mf_cloud/invoice"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
module MfCloud
|
2
|
+
module Invoice
|
3
|
+
module Api
|
4
|
+
class Base
|
5
|
+
class << self
|
6
|
+
def model_name
|
7
|
+
name.sub('Api', 'Model')
|
8
|
+
end
|
9
|
+
|
10
|
+
def model_class
|
11
|
+
Object.const_get(model_name)
|
12
|
+
end
|
13
|
+
|
14
|
+
def collection_name
|
15
|
+
"#{name.sub('Api', 'Collection')}Collection"
|
16
|
+
end
|
17
|
+
|
18
|
+
def collection_class
|
19
|
+
Object.const_get(collection_name)
|
20
|
+
end
|
21
|
+
|
22
|
+
def allowed_methods
|
23
|
+
@allowed_methods ||= []
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def allow_method(*methods)
|
29
|
+
@allowed_methods = methods
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def initialize(client)
|
34
|
+
@client = client
|
35
|
+
end
|
36
|
+
|
37
|
+
def all(params = {})
|
38
|
+
fail MethodNotAllowed, "#{self.class.name} has not allowed :all" unless self.class.allowed_methods.include? :all
|
39
|
+
|
40
|
+
response_body = @client.get(self.class::PATH, params)
|
41
|
+
self.class.collection_class.new(
|
42
|
+
response_body[self.class::COLLECTION_KEY],
|
43
|
+
response_body["meta"]
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
def get(id)
|
48
|
+
fail MethodNotAllowed, "#{self.class.name} has not allowed :get" unless self.class.allowed_methods.include? :get
|
49
|
+
|
50
|
+
response_body = @client.get("#{self.class::PATH}/#{id}")
|
51
|
+
self.class.model_class.new(response_body)
|
52
|
+
end
|
53
|
+
|
54
|
+
def create(params)
|
55
|
+
fail MethodNotAllowed, "#{self.class.name} has not allowed :create" unless self.class.allowed_methods.include? :create
|
56
|
+
|
57
|
+
response_body = @client.post(self.class::PATH, self.class::BASE_NAME => params)
|
58
|
+
self.class.model_class.new(response_body)
|
59
|
+
end
|
60
|
+
|
61
|
+
def update(id, params)
|
62
|
+
fail MethodNotAllowed, "#{self.class.name} has not allowed :update" unless self.class.allowed_methods.include? :update
|
63
|
+
|
64
|
+
response_body = @client.put("#{self.class::PATH}/#{id}", self.class::BASE_NAME => params)
|
65
|
+
self.class.model_class.new(response_body)
|
66
|
+
end
|
67
|
+
|
68
|
+
def delete(id)
|
69
|
+
fail MethodNotAllowed, "#{self.class.name} has not allowed :delete" unless self.class.allowed_methods.include? :delete
|
70
|
+
|
71
|
+
@client.delete("#{self.class::PATH}/#{id}")
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module MfCloud
|
2
|
+
module Invoice
|
3
|
+
module Api
|
4
|
+
class Office < MfCloud::Invoice::Api::Base
|
5
|
+
PATH = 'office'
|
6
|
+
|
7
|
+
def get
|
8
|
+
response_body = @client.get(PATH)
|
9
|
+
MfCloud::Invoice::Model::Office.new(response_body)
|
10
|
+
end
|
11
|
+
|
12
|
+
def update(params)
|
13
|
+
response_body = @client.put(PATH, office: params)
|
14
|
+
MfCloud::Invoice::Model::Office.new(response_body)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
|
4
|
+
require 'mf_cloud/invoice/api/base'
|
5
|
+
require 'mf_cloud/invoice/api/office'
|
6
|
+
require 'mf_cloud/invoice/api/partner'
|
7
|
+
require 'mf_cloud/invoice/api/item'
|
8
|
+
require 'mf_cloud/invoice/api/billing'
|
9
|
+
|
10
|
+
require 'mf_cloud/invoice/model/base'
|
11
|
+
require 'mf_cloud/invoice/model/office'
|
12
|
+
require 'mf_cloud/invoice/model/partner'
|
13
|
+
require 'mf_cloud/invoice/model/department'
|
14
|
+
require 'mf_cloud/invoice/model/item'
|
15
|
+
require 'mf_cloud/invoice/model/billing'
|
16
|
+
require 'mf_cloud/invoice/model/document_status'
|
17
|
+
|
18
|
+
require 'mf_cloud/invoice/collection/base'
|
19
|
+
require 'mf_cloud/invoice/collection/meta_data'
|
20
|
+
require 'mf_cloud/invoice/collection/partner_collection'
|
21
|
+
require 'mf_cloud/invoice/collection/department_collection'
|
22
|
+
require 'mf_cloud/invoice/collection/item_collection'
|
23
|
+
require 'mf_cloud/invoice/collection/billing_collection'
|
24
|
+
|
25
|
+
module MfCloud
|
26
|
+
module Invoice
|
27
|
+
class Client
|
28
|
+
def initialize(options = {}, &block)
|
29
|
+
@config = MfCloud::Invoice::Configure.new(options)
|
30
|
+
|
31
|
+
yield @config if block_given?
|
32
|
+
|
33
|
+
@conn = Faraday.new(url: "#{MfCloud::Invoice::API_URL}#{@config.api_version}") do |faraday|
|
34
|
+
faraday.request :json
|
35
|
+
|
36
|
+
faraday.response :json
|
37
|
+
|
38
|
+
faraday.adapter Faraday.default_adapter
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def office
|
43
|
+
@_office ||= MfCloud::Invoice::Api::Office.new(self)
|
44
|
+
end
|
45
|
+
|
46
|
+
def partners
|
47
|
+
@_partners ||= MfCloud::Invoice::Api::Partner.new(self)
|
48
|
+
end
|
49
|
+
|
50
|
+
def items
|
51
|
+
@_items ||= MfCloud::Invoice::Api::Item.new(self)
|
52
|
+
end
|
53
|
+
|
54
|
+
def billings
|
55
|
+
@_billings ||= MfCloud::Invoice::Api::Billing.new(self)
|
56
|
+
end
|
57
|
+
|
58
|
+
def get(path, params = {})
|
59
|
+
res = @conn.get do |req|
|
60
|
+
req.headers['Authorization'] = "Bearer #{@config.access_token}"
|
61
|
+
req.url path, params
|
62
|
+
end
|
63
|
+
|
64
|
+
check_response!(res)
|
65
|
+
res.body
|
66
|
+
end
|
67
|
+
|
68
|
+
def post(path, params = {})
|
69
|
+
res = @conn.post do |req|
|
70
|
+
req.headers['Authorization'] = "Bearer #{@config.access_token}"
|
71
|
+
req.url path
|
72
|
+
req.body = params
|
73
|
+
end
|
74
|
+
|
75
|
+
check_response!(res)
|
76
|
+
res.body
|
77
|
+
end
|
78
|
+
|
79
|
+
def put(path, params = {})
|
80
|
+
res = @conn.put do |req|
|
81
|
+
req.headers['Authorization'] = "Bearer #{@config.access_token}"
|
82
|
+
req.url path
|
83
|
+
req.body = params
|
84
|
+
end
|
85
|
+
|
86
|
+
check_response!(res)
|
87
|
+
res.body
|
88
|
+
end
|
89
|
+
|
90
|
+
def delete(path, params = {})
|
91
|
+
res = @conn.delete do |req|
|
92
|
+
req.headers['Authorization'] = "Bearer #{@config.access_token}"
|
93
|
+
req.url path, params
|
94
|
+
end
|
95
|
+
|
96
|
+
check_response!(res)
|
97
|
+
end
|
98
|
+
|
99
|
+
private
|
100
|
+
|
101
|
+
def check_response!(res)
|
102
|
+
case res.status
|
103
|
+
when 400
|
104
|
+
fail MfCloud::Invoice::InvalidRequest, res.body["errors"].first["message"]
|
105
|
+
when 401
|
106
|
+
fail MfCloud::Invoice::InvalidAccessToken, 'アクセストークンが不正です'
|
107
|
+
when 402
|
108
|
+
fail MfCloud::Invoice::PaymentRequired, res.body["errors"].first["message"]
|
109
|
+
when 404
|
110
|
+
fail MfCloud::Invoice::ResourceNotFound, res.body["errors"].first["message"]
|
111
|
+
when 422
|
112
|
+
fail MfCloud::Invoice::InvalidParameter, res.body["errors"].first["message"]
|
113
|
+
when 429
|
114
|
+
fail MfCloud::Invoice::RateLimitted, res.body["errors"].first["message"]
|
115
|
+
when 500
|
116
|
+
if res.body["errors"].nil?
|
117
|
+
msg = 'サーバーがメンテナンス中かダウンしている可能性があります。しばらく待って再度お試しください。'
|
118
|
+
else
|
119
|
+
msg = res.body["errors"].first["message"]
|
120
|
+
end
|
121
|
+
|
122
|
+
fail MfCloud::Invoice::InternalServerError, msg
|
123
|
+
else
|
124
|
+
true
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module MfCloud
|
2
|
+
module Invoice
|
3
|
+
module Collection
|
4
|
+
class Base
|
5
|
+
attr_reader :meta
|
6
|
+
|
7
|
+
def collection
|
8
|
+
@collection ||= []
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def method_missing(method_name, *args , &block)
|
14
|
+
if collection.respond_to? method_name
|
15
|
+
collection.__send__(method_name, *args, &block)
|
16
|
+
else
|
17
|
+
super
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module MfCloud
|
2
|
+
module Invoice
|
3
|
+
module Collection
|
4
|
+
class BillingCollection < MfCloud::Invoice::Collection::Base
|
5
|
+
def initialize(collection_params = [], meta_params = {})
|
6
|
+
@meta = MfCloud::Invoice::Collection::MetaData.new(meta_params)
|
7
|
+
@collection = collection_params.map do |billing_params|
|
8
|
+
MfCloud::Invoice::Model::Billing.new(billing_params)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module MfCloud
|
2
|
+
module Invoice
|
3
|
+
module Collection
|
4
|
+
class DepartmentCollection < MfCloud::Invoice::Collection::Base
|
5
|
+
def initialize(collection_params = [])
|
6
|
+
@collection = collection_params.map do |department_params|
|
7
|
+
MfCloud::Invoice::Model::Department.new(department_params)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module MfCloud
|
2
|
+
module Invoice
|
3
|
+
module Collection
|
4
|
+
class ItemCollection < MfCloud::Invoice::Collection::Base
|
5
|
+
def initialize(collection_params = [], meta_params = {})
|
6
|
+
@meta = MfCloud::Invoice::Collection::MetaData.new(meta_params)
|
7
|
+
@collection = collection_params.map do |item_params|
|
8
|
+
MfCloud::Invoice::Model::Item.new(item_params)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module MfCloud
|
2
|
+
module Invoice
|
3
|
+
module Collection
|
4
|
+
class PartnerCollection < MfCloud::Invoice::Collection::Base
|
5
|
+
def initialize(collection_params = [], meta_params = {})
|
6
|
+
@meta = MfCloud::Invoice::Collection::MetaData.new(meta_params)
|
7
|
+
@collection = collection_params.map do |partner_params|
|
8
|
+
MfCloud::Invoice::Model::Partner.new(partner_params)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module MfCloud
|
2
|
+
module Invoice
|
3
|
+
class Configure
|
4
|
+
attr_accessor :client_id, :client_secret, :access_token
|
5
|
+
attr_reader :api_version
|
6
|
+
|
7
|
+
def initialize(options = {})
|
8
|
+
@client_id = options[:client_id]
|
9
|
+
@client_secret = options[:client_secret]
|
10
|
+
@access_token = options[:access_token]
|
11
|
+
@api_version = :v1
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module MfCloud
|
2
|
+
module Invoice
|
3
|
+
# for handling api error
|
4
|
+
class InvalidRequest < StandardError; end
|
5
|
+
class InvalidAccessToken < StandardError; end
|
6
|
+
class PaymentRequired < StandardError; end
|
7
|
+
class ResourceNotFound < StandardError; end
|
8
|
+
class InvalidParameter < StandardError; end
|
9
|
+
class RateLimitted < StandardError; end
|
10
|
+
class InternalServerError < StandardError; end
|
11
|
+
|
12
|
+
# for client error
|
13
|
+
class MethodNotAllowed < StandardError; end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module MfCloud
|
2
|
+
module Invoice
|
3
|
+
module Model
|
4
|
+
class Base
|
5
|
+
class << self
|
6
|
+
def attribute_keys
|
7
|
+
@attribute_keys ||= []
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def resource_attributes(*attributes)
|
13
|
+
attributes.each { |attribute| attr_accessor attribute }
|
14
|
+
attribute_keys.concat(attributes)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(params)
|
19
|
+
set_attributes(params)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def set_attributes(params)
|
25
|
+
self.class.attribute_keys.each do |attr|
|
26
|
+
__send__("#{attr}=", params[attr.to_s]) unless params[attr.to_s].nil?
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module MfCloud
|
2
|
+
module Invoice
|
3
|
+
module Model
|
4
|
+
class Billing < MfCloud::Invoice::Model::Base
|
5
|
+
resource_attributes :id, :pdf_url, :user_id, :partner_id, :department_id, :partner_name, :partner_name_suffix,
|
6
|
+
:partner_detail, :member_id, :member_name, :office_name, :office_detail, :title, :excise_price, :deduct_price,
|
7
|
+
:subtotal, :memo, :payment_condition, :total_price, :billing_date, :due_date, :sales_date, :created_at, :updated_at,
|
8
|
+
:billing_number, :note, :document_name, :tags
|
9
|
+
|
10
|
+
attr_reader :items, :status
|
11
|
+
|
12
|
+
def initialize(params)
|
13
|
+
super
|
14
|
+
@items = MfCloud::Invoice::Collection::ItemCollection.new(params["items"])
|
15
|
+
@status = MfCloud::Invoice::Model::DocumentStatus.new(params["status"])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module MfCloud
|
2
|
+
module Invoice
|
3
|
+
module Model
|
4
|
+
class Department < MfCloud::Invoice::Model::Base
|
5
|
+
resource_attributes :id, :name, :zip, :tel, :prefecture, :address1, :address2,
|
6
|
+
:person_title, :person_name, :email, :cc_emails, :created_at, :updated_at
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module MfCloud
|
2
|
+
module Invoice
|
3
|
+
module Model
|
4
|
+
class Partner < MfCloud::Invoice::Model::Base
|
5
|
+
resource_attributes :id, :code, :name, :name_kana, :name_suffix, :memo, :created_at, :updated_at
|
6
|
+
attr_reader :departments
|
7
|
+
|
8
|
+
def initialize(params)
|
9
|
+
super
|
10
|
+
@departments = MfCloud::Invoice::Collection::DepartmentCollection.new(params["departments"])
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mf_cloud/invoice/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mf_cloud-invoice"
|
8
|
+
spec.version = MfCloud::Invoice::VERSION
|
9
|
+
spec.authors = ["Izumiya Keisuke"]
|
10
|
+
spec.email = ["izumiya.keisuke@moneyforward.co.jp"]
|
11
|
+
|
12
|
+
spec.summary = %q{MFCloud Invoice API wrapper}
|
13
|
+
spec.description = %q{Let's start cloud invoice!}
|
14
|
+
spec.homepage = "https://github.com/moneyforward/mf_cloud-invoice-ruby"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "bin"
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "faraday", ">=0.9"
|
23
|
+
spec.add_dependency "faraday_middleware", ">=0.9"
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "rspec"
|
28
|
+
spec.add_development_dependency "webmock"
|
29
|
+
spec.add_development_dependency "pry"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mf_cloud-invoice
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Izumiya Keisuke
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.9'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday_middleware
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.9'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.9'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.10'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.10'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Let's start cloud invoice!
|
112
|
+
email:
|
113
|
+
- izumiya.keisuke@moneyforward.co.jp
|
114
|
+
executables:
|
115
|
+
- console
|
116
|
+
- setup
|
117
|
+
extensions: []
|
118
|
+
extra_rdoc_files: []
|
119
|
+
files:
|
120
|
+
- ".gitignore"
|
121
|
+
- ".rspec"
|
122
|
+
- ".travis.yml"
|
123
|
+
- Gemfile
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- bin/console
|
128
|
+
- bin/setup
|
129
|
+
- lib/mf_cloud/invoice.rb
|
130
|
+
- lib/mf_cloud/invoice/api/base.rb
|
131
|
+
- lib/mf_cloud/invoice/api/billing.rb
|
132
|
+
- lib/mf_cloud/invoice/api/item.rb
|
133
|
+
- lib/mf_cloud/invoice/api/office.rb
|
134
|
+
- lib/mf_cloud/invoice/api/partner.rb
|
135
|
+
- lib/mf_cloud/invoice/client.rb
|
136
|
+
- lib/mf_cloud/invoice/collection/base.rb
|
137
|
+
- lib/mf_cloud/invoice/collection/billing_collection.rb
|
138
|
+
- lib/mf_cloud/invoice/collection/department_collection.rb
|
139
|
+
- lib/mf_cloud/invoice/collection/item_collection.rb
|
140
|
+
- lib/mf_cloud/invoice/collection/meta_data.rb
|
141
|
+
- lib/mf_cloud/invoice/collection/partner_collection.rb
|
142
|
+
- lib/mf_cloud/invoice/configure.rb
|
143
|
+
- lib/mf_cloud/invoice/errors.rb
|
144
|
+
- lib/mf_cloud/invoice/model/base.rb
|
145
|
+
- lib/mf_cloud/invoice/model/billing.rb
|
146
|
+
- lib/mf_cloud/invoice/model/department.rb
|
147
|
+
- lib/mf_cloud/invoice/model/document_status.rb
|
148
|
+
- lib/mf_cloud/invoice/model/item.rb
|
149
|
+
- lib/mf_cloud/invoice/model/office.rb
|
150
|
+
- lib/mf_cloud/invoice/model/partner.rb
|
151
|
+
- lib/mf_cloud/invoice/version.rb
|
152
|
+
- mf_cloud-invoice.gemspec
|
153
|
+
homepage: https://github.com/moneyforward/mf_cloud-invoice-ruby
|
154
|
+
licenses:
|
155
|
+
- MIT
|
156
|
+
metadata: {}
|
157
|
+
post_install_message:
|
158
|
+
rdoc_options: []
|
159
|
+
require_paths:
|
160
|
+
- lib
|
161
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
|
+
requirements:
|
168
|
+
- - ">="
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
version: '0'
|
171
|
+
requirements: []
|
172
|
+
rubyforge_project:
|
173
|
+
rubygems_version: 2.4.5.1
|
174
|
+
signing_key:
|
175
|
+
specification_version: 4
|
176
|
+
summary: MFCloud Invoice API wrapper
|
177
|
+
test_files: []
|
178
|
+
has_rdoc:
|