fs_api 1.0.0 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -3
- data/fs_api.gemspec +3 -4
- data/lib/fs_api/client.rb +71 -69
- data/lib/fs_api/service/base_service.rb +4 -2
- data/lib/fs_api/version.rb +1 -1
- data/spec/lib/fs_api/service/invoice_spec.rb +9 -0
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a52ab0e49975acfd0375aceb668af719979dc70
|
4
|
+
data.tar.gz: e91f6223ec78f1a2c042693135d70101feb54d96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f3a459ffa206839f3fc45ee9b9f43fd29c9c397b44a3f9cdb44c0cc9936847edad964c154f2a09a8fa5e7d5bab30bbb7a977cec7e51ce9bf88680ee7c5dec32
|
7
|
+
data.tar.gz: d788390a2bc06be9b0404e3b0cf94799080e2aa93d63b04b5049a0be5682c3cc03ef43dd461692eae12992c55e902813fbecea2272dc0c27d656121855de4019
|
data/README.md
CHANGED
@@ -61,13 +61,19 @@ invoice.errors
|
|
61
61
|
# Delete an invoice
|
62
62
|
api_client.invoices.delete(invoice)
|
63
63
|
|
64
|
+
# Search in all fields of invoices
|
65
|
+
api_client.invoices.search('john')
|
66
|
+
|
67
|
+
# Search in city field of invoices
|
68
|
+
api_client.invoices.search(city: 'john')
|
64
69
|
```
|
65
70
|
|
66
71
|
## Todo
|
67
72
|
* Handle rate limiting
|
68
|
-
*
|
69
|
-
* Implement
|
70
|
-
* Implement
|
73
|
+
* Refactor base service so services can choose to implement parts
|
74
|
+
* ~~Implement saved invoices resource~~
|
75
|
+
* ~~Implement search~~
|
76
|
+
* ~~Implement invoice payment registration~~
|
71
77
|
|
72
78
|
## Contributing
|
73
79
|
|
data/fs_api.gemspec
CHANGED
@@ -9,13 +9,12 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Maarten van Vliet"]
|
10
10
|
spec.email = ["maartenvanvliet@gmail.com"]
|
11
11
|
spec.summary = %q{Ruby-Api library for factuursturen.nl }
|
12
|
-
spec.description = %q{Ruby-Api library for factuursturen.nl
|
13
|
-
spec.homepage = ""
|
12
|
+
spec.description = %q{Ruby-Api library for factuursturen.nl }
|
13
|
+
spec.homepage = "https://github.com/maartenvanvliet/fs_api"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
17
|
-
spec.
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.test_files = spec.files.grep(%r{^(spec)/})
|
19
18
|
spec.require_paths = ["lib"]
|
20
19
|
|
21
20
|
spec.add_development_dependency "rspec", "~> 3.2"
|
data/lib/fs_api/client.rb
CHANGED
@@ -1,86 +1,88 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
module FsApi
|
2
|
+
class Client
|
3
|
+
attr_reader :username, :password, :_last_response
|
4
|
+
attr_accessor :errors
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
def base_url
|
11
|
-
"https://www.factuursturen.nl:443/api/v1"
|
12
|
-
end
|
6
|
+
def initialize(username, password)
|
7
|
+
@username = username
|
8
|
+
@password = password
|
9
|
+
end
|
13
10
|
|
14
|
-
|
15
|
-
|
16
|
-
uri = uri_for_path(base_url)
|
17
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
18
|
-
http.use_ssl = uri.scheme == 'https'
|
19
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
20
|
-
http
|
11
|
+
def base_url
|
12
|
+
"https://www.factuursturen.nl:443/api/v1"
|
21
13
|
end
|
22
|
-
end
|
23
14
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
15
|
+
def http
|
16
|
+
@http ||= begin
|
17
|
+
uri = uri_for_path(base_url)
|
18
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
19
|
+
http.use_ssl = uri.scheme == 'https'
|
20
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
21
|
+
http
|
22
|
+
end
|
23
|
+
end
|
30
24
|
|
31
|
-
|
32
|
-
|
33
|
-
|
25
|
+
def headers
|
26
|
+
{
|
27
|
+
'Accept' => 'application/json',
|
28
|
+
'Content-Type' => 'application/json'
|
29
|
+
}
|
30
|
+
end
|
34
31
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
perform(http)
|
39
|
-
end
|
32
|
+
def uri_for_path(path)
|
33
|
+
URI.parse(File.join(base_url, path))
|
34
|
+
end
|
40
35
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
36
|
+
def get(path, headers={})
|
37
|
+
uri = uri_for_path(path)
|
38
|
+
http = Net::HTTP::Get.new(uri.request_uri, self.headers.merge(headers))
|
39
|
+
perform(http)
|
40
|
+
end
|
47
41
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
42
|
+
def put(path, body=nil, headers={})
|
43
|
+
uri = uri_for_path(path)
|
44
|
+
http = Net::HTTP::Put.new(uri.request_uri, self.headers.merge(headers))
|
45
|
+
http.body = body
|
46
|
+
perform(http)
|
47
|
+
end
|
54
48
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
49
|
+
def post(path, body=nil, headers={})
|
50
|
+
uri = uri_for_path(path)
|
51
|
+
http = Net::HTTP::Post.new(uri.request_uri, self.headers.merge(headers))
|
52
|
+
http.body = body
|
53
|
+
perform(http)
|
54
|
+
end
|
60
55
|
|
61
|
-
|
62
|
-
|
63
|
-
|
56
|
+
def delete(path, headers={})
|
57
|
+
uri = uri_for_path(path)
|
58
|
+
http = Net::HTTP::Delete.new(uri.request_uri, self.headers.merge(headers))
|
59
|
+
perform(http)
|
60
|
+
end
|
64
61
|
|
65
|
-
|
66
|
-
|
67
|
-
|
62
|
+
def invoices
|
63
|
+
FsApi::Service::Invoice.new(self)
|
64
|
+
end
|
68
65
|
|
69
|
-
|
70
|
-
|
71
|
-
|
66
|
+
def clients
|
67
|
+
FsApi::Service::Client.new(self)
|
68
|
+
end
|
72
69
|
|
73
|
-
|
74
|
-
|
75
|
-
|
70
|
+
def products
|
71
|
+
FsApi::Service::Product.new(self)
|
72
|
+
end
|
76
73
|
|
77
|
-
|
78
|
-
|
79
|
-
|
74
|
+
def invoices_payments
|
75
|
+
FsApi::Service::InvoicesPayment.new(self)
|
76
|
+
end
|
80
77
|
|
81
|
-
|
82
|
-
|
83
|
-
request.basic_auth username, password
|
84
|
-
@_last_response = http.request(request)
|
78
|
+
def saved_invoices
|
79
|
+
FsApi::Service::InvoicesSaved.new(self)
|
85
80
|
end
|
81
|
+
|
82
|
+
private
|
83
|
+
def perform(request)
|
84
|
+
request.basic_auth username, password
|
85
|
+
@_last_response = http.request(request)
|
86
|
+
end
|
87
|
+
end
|
86
88
|
end
|
@@ -70,8 +70,10 @@ module FsApi
|
|
70
70
|
true
|
71
71
|
end
|
72
72
|
|
73
|
-
def all
|
74
|
-
|
73
|
+
def all(params = {})
|
74
|
+
query_path = params.empty? ? path : "#{path}?#{URI.encode_www_form(params)}"
|
75
|
+
|
76
|
+
if response = api_client.get(query_path)
|
75
77
|
if response.code.to_i == success_status_code
|
76
78
|
JSON.parse(response.body).map do |attributes|
|
77
79
|
collection_class.new(attributes.merge(from_api: true))
|
data/lib/fs_api/version.rb
CHANGED
@@ -16,6 +16,15 @@ describe FsApi::Service::Invoice do
|
|
16
16
|
expect(invoices.first.invoicenr).to eq 'F20150001'
|
17
17
|
end
|
18
18
|
|
19
|
+
it "retrieves all invoices with filter" do
|
20
|
+
stub_request(:get, "https://username:api_key@www.factuursturen.nl/api/v1/invoices?filter=overdue").to_return(body: [json_response(:invoice)].to_json )
|
21
|
+
|
22
|
+
invoices = service.all(filter: :overdue)
|
23
|
+
|
24
|
+
expect(invoices.size).to eq 1
|
25
|
+
expect(invoices.first.invoicenr).to eq 'F20150001'
|
26
|
+
end
|
27
|
+
|
19
28
|
it "retrieves a invoice" do
|
20
29
|
stub_request(:get, "https://username:api_key@www.factuursturen.nl/api/v1/invoices/20150001").to_return(body: { 'invoice' => json_response(:invoice)}.to_json )
|
21
30
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fs_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maarten van Vliet
|
@@ -38,8 +38,7 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.21'
|
41
|
-
description: 'Ruby-Api library for factuursturen.nl
|
42
|
-
for the api, but functional '
|
41
|
+
description: 'Ruby-Api library for factuursturen.nl '
|
43
42
|
email:
|
44
43
|
- maartenvanvliet@gmail.com
|
45
44
|
executables: []
|
@@ -80,7 +79,7 @@ files:
|
|
80
79
|
- spec/support/responses/client.json
|
81
80
|
- spec/support/responses/invoice.json
|
82
81
|
- spec/support/responses/product.json
|
83
|
-
homepage:
|
82
|
+
homepage: https://github.com/maartenvanvliet/fs_api
|
84
83
|
licenses:
|
85
84
|
- MIT
|
86
85
|
metadata: {}
|