fs_api 1.0.0 → 1.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8378c1eb029c90743d0468a0d328bd30af5fd4ad
4
- data.tar.gz: b2273c9e8c5a425cb111cc6097eb0e5f00eb6042
3
+ metadata.gz: 6a52ab0e49975acfd0375aceb668af719979dc70
4
+ data.tar.gz: e91f6223ec78f1a2c042693135d70101feb54d96
5
5
  SHA512:
6
- metadata.gz: b9ceb21d331970ae0b1f9c03ab3d0715b6919dd987cf57e66a6adcc5e2a03efb7876e3f5263ffe85c752e60595b93a0d196e648a2ea346e0cb6c146ff4491200
7
- data.tar.gz: ec0eb197c15885f757c41f79bcfd0f295b7ec0b77f1d129123980afae67c10d35107eea35dd8873c6d93a6fce1ebc5f705e699ada9c25921a027655bddcd6727
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
- * Implement saved invoices resource
69
- * Implement search
70
- * Implement invoice payment registration
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. As of yet incomplete support for the api, but functional }
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.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
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
- class FsApi::Client
2
- attr_reader :username, :password, :_last_response
3
- attr_accessor :errors
1
+ module FsApi
2
+ class Client
3
+ attr_reader :username, :password, :_last_response
4
+ attr_accessor :errors
4
5
 
5
- def initialize(username, password)
6
- @username = username
7
- @password = password
8
- end
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
- def http
15
- @http ||= begin
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
- def headers
25
- {
26
- 'Accept' => 'application/json',
27
- 'Content-Type' => 'application/json'
28
- }
29
- end
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
- def uri_for_path(path)
32
- URI.parse(File.join(base_url, path))
33
- end
25
+ def headers
26
+ {
27
+ 'Accept' => 'application/json',
28
+ 'Content-Type' => 'application/json'
29
+ }
30
+ end
34
31
 
35
- def get(path, headers={})
36
- uri = uri_for_path(path)
37
- http = Net::HTTP::Get.new(uri.request_uri, self.headers.merge(headers))
38
- perform(http)
39
- end
32
+ def uri_for_path(path)
33
+ URI.parse(File.join(base_url, path))
34
+ end
40
35
 
41
- def put(path, body=nil, headers={})
42
- uri = uri_for_path(path)
43
- http = Net::HTTP::Put.new(uri.request_uri, self.headers.merge(headers))
44
- http.body = body
45
- perform(http)
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
- def post(path, body=nil, headers={})
49
- uri = uri_for_path(path)
50
- http = Net::HTTP::Post.new(uri.request_uri, self.headers.merge(headers))
51
- http.body = body
52
- perform(http)
53
- end
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
- def delete(path, headers={})
56
- uri = uri_for_path(path)
57
- http = Net::HTTP::Delete.new(uri.request_uri, self.headers.merge(headers))
58
- perform(http)
59
- end
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
- def invoices
62
- FsApi::Service::Invoice.new(self)
63
- end
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
- def clients
66
- FsApi::Service::Client.new(self)
67
- end
62
+ def invoices
63
+ FsApi::Service::Invoice.new(self)
64
+ end
68
65
 
69
- def products
70
- FsApi::Service::Product.new(self)
71
- end
66
+ def clients
67
+ FsApi::Service::Client.new(self)
68
+ end
72
69
 
73
- def invoices_payments
74
- FsApi::Service::InvoicesPayment.new(self)
75
- end
70
+ def products
71
+ FsApi::Service::Product.new(self)
72
+ end
76
73
 
77
- def saved_invoices
78
- FsApi::Service::InvoicesSaved.new(self)
79
- end
74
+ def invoices_payments
75
+ FsApi::Service::InvoicesPayment.new(self)
76
+ end
80
77
 
81
- private
82
- def perform(request)
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
- if response = api_client.get(path)
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))
@@ -1,3 +1,3 @@
1
1
  module FsApi
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.5"
3
3
  end
@@ -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.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. As of yet incomplete support
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: {}