fs_api 0.7.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ca3bb7dc2c987a120ce68ac01b80eab0b7b3019a
4
- data.tar.gz: 970a45f66ea754a021d2849d57dfd34ee423a40a
3
+ metadata.gz: 8378c1eb029c90743d0468a0d328bd30af5fd4ad
4
+ data.tar.gz: b2273c9e8c5a425cb111cc6097eb0e5f00eb6042
5
5
  SHA512:
6
- metadata.gz: c639cc53020597dfc81fcbc366aacd5d73dd1ae213ef715c7a73355f15004f41e3ef0080a191f43dc6836f91cb8d630bb888d8df806f28f22a0e4b70237e0379
7
- data.tar.gz: 89b839e992d6671db8359e023750600202456a1dfd24e44792f1f490913778ce77a3cd18c49a55ecd7f60ea72c27a699972c47d45a0277f3fbab31a082e53099
6
+ metadata.gz: b9ceb21d331970ae0b1f9c03ab3d0715b6919dd987cf57e66a6adcc5e2a03efb7876e3f5263ffe85c752e60595b93a0d196e648a2ea346e0cb6c146ff4491200
7
+ data.tar.gz: ec0eb197c15885f757c41f79bcfd0f295b7ec0b77f1d129123980afae67c10d35107eea35dd8873c6d93a6fce1ebc5f705e699ada9c25921a027655bddcd6727
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ sudo: false
3
+ rvm:
4
+ - 2.1.0
5
+ - 2.2.0
6
+ script: bundle exec rspec
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # FsApi
2
-
2
+ [![Build Status](https://travis-ci.org/maartenvanvliet/fs_api.svg)](https://travis-ci.org/maartenvanvliet/fs_api)
3
3
  Gem to interface with the [factuursturen.nl](https://www.factuursturen.nl/?a=1552)
4
4
  invoicing API
5
5
 
@@ -42,6 +42,9 @@ api_client.clients.all
42
42
  # Retrieve all invoices
43
43
  api_client.invoices.all
44
44
 
45
+ # Find an invoice
46
+ api_client.invoices.find(invoice_number)
47
+
45
48
  # Create an invoice
46
49
  invoice = api_client.invoices.build({clientnr: '1'})
47
50
  api_client.invoices.save(invoice)
@@ -55,8 +58,8 @@ api_client.invoices.save(invoice)
55
58
  # Has the errors of the last api operation
56
59
  invoice.errors
57
60
 
58
- # Find an invoice
59
- api_client.invoices.find(invoice_number)
61
+ # Delete an invoice
62
+ api_client.invoices.delete(invoice)
60
63
 
61
64
  ```
62
65
 
data/lib/fs_api/client.rb CHANGED
@@ -70,6 +70,14 @@ class FsApi::Client
70
70
  FsApi::Service::Product.new(self)
71
71
  end
72
72
 
73
+ def invoices_payments
74
+ FsApi::Service::InvoicesPayment.new(self)
75
+ end
76
+
77
+ def saved_invoices
78
+ FsApi::Service::InvoicesSaved.new(self)
79
+ end
80
+
73
81
  private
74
82
  def perform(request)
75
83
  request.basic_auth username, password
@@ -53,6 +53,6 @@ class FsApi::Resource::Client
53
53
  timestamp
54
54
  )
55
55
  def path
56
- "/clients/#{clientnr}"
56
+ persisted? ? "/#{clientnr}" : ""
57
57
  end
58
58
  end
@@ -40,15 +40,28 @@ class FsApi::Resource::Invoice
40
40
  action
41
41
  savename
42
42
  sendmethod
43
+ name
44
+ profile_name
45
+ datesaved
46
+ tax_type
47
+ tax_shifted
43
48
  )
44
49
 
45
50
  has_datetime_attributes %w(
46
51
  duedate
52
+ datesaved
53
+ )
54
+
55
+ has_boolean_attributes %w(
56
+ tax_shifted
47
57
  )
48
58
  def path
49
- "/invoices/#{id}"
59
+ persisted? ? "/#{id}" : ""
50
60
  end
51
61
 
62
+ def saved?
63
+ !datesaved.nil? && datesaved != ''
64
+ end
52
65
 
53
66
  # invoices cannot be updated
54
67
  def updateable?
@@ -0,0 +1,20 @@
1
+ class FsApi::Resource::InvoicesPayment
2
+ include FsApi::Resource
3
+ extend FsApi::Resource::ClassMethods
4
+
5
+ has_attributes %i(
6
+ id
7
+ invoicenr
8
+ date
9
+ amount
10
+ )
11
+
12
+ def remote_id
13
+ id || invoicenr
14
+ end
15
+
16
+ def path
17
+ "/#{remote_id}"
18
+ end
19
+
20
+ end
@@ -12,7 +12,7 @@ class FsApi::Resource::Product
12
12
  )
13
13
 
14
14
  def path
15
- "/products/#{id}"
15
+ persisted? ? "/#{id}" : ""
16
16
  end
17
17
 
18
18
  end
@@ -20,6 +20,10 @@ module FsApi
20
20
  "/#{resource_type_plural}"
21
21
  end
22
22
 
23
+ def instance_path(instance)
24
+ [path, instance.path].join
25
+ end
26
+
23
27
  def find(id)
24
28
  if response = @api_client.get([path,id].join('/'))
25
29
  if response.code.to_i == success_status_code
@@ -41,7 +45,7 @@ module FsApi
41
45
  end
42
46
 
43
47
  def delete(instance)
44
- @api_client.delete(instance.path)
48
+ @api_client.delete(instance_path(instance))
45
49
  if api_client._last_response.code.to_i != success_status_code
46
50
  instance.errors = api_client._last_response.body
47
51
  return false
@@ -51,13 +55,13 @@ module FsApi
51
55
  def save(instance)
52
56
  return false if instance.persisted? && !instance.updateable?
53
57
  if instance.persisted?
54
- @api_client.put(instance.path, instance.to_json)
58
+ @api_client.put(instance_path(instance), instance.to_json)
55
59
  if api_client._last_response.code.to_i != success_status_code
56
60
  instance.errors = api_client._last_response
57
61
  return false
58
62
  end
59
63
  else
60
- @api_client.post(path, instance.to_json)
64
+ @api_client.post(instance_path(instance), instance.to_json)
61
65
  if api_client._last_response.code.to_i != create_success_status_code
62
66
  instance.errors = api_client._last_response.body
63
67
  return false
@@ -1,6 +1,8 @@
1
1
  module FsApi
2
2
  module Service
3
3
  class Client < BaseService
4
+ include FsApi::Service::Searchable
5
+
4
6
  def collection_class
5
7
  FsApi::Resource::Client
6
8
  end
@@ -1,6 +1,8 @@
1
1
  module FsApi
2
2
  module Service
3
3
  class Invoice < BaseService
4
+ include FsApi::Service::Searchable
5
+
4
6
  def collection_class
5
7
  FsApi::Resource::Invoice
6
8
  end
@@ -0,0 +1,13 @@
1
+ module FsApi
2
+ module Service
3
+ class InvoicesPayment < BaseService
4
+ def collection_class
5
+ FsApi::Resource::InvoicesPayment
6
+ end
7
+
8
+ def resource_type_plural
9
+ "invoices_payment"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ module FsApi
2
+ module Service
3
+ class InvoicesSaved < BaseService
4
+ def collection_class
5
+ FsApi::Resource::Invoice
6
+ end
7
+
8
+ def resource_type_plural
9
+ "invoices_saved"
10
+ end
11
+
12
+ def resource_type
13
+ 'invoice'
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,6 +1,8 @@
1
1
  module FsApi
2
2
  module Service
3
3
  class Product < BaseService
4
+ include FsApi::Service::Searchable
5
+
4
6
  def collection_class
5
7
  FsApi::Resource::Product
6
8
  end
@@ -0,0 +1,24 @@
1
+ module FsApi
2
+ module Service
3
+ module Searchable
4
+ def search(options)
5
+ if options.is_a? String
6
+ field = 'all'
7
+ value = options
8
+ elsif options.is_a? Hash
9
+ field, value = options.first
10
+ end
11
+
12
+ search_path = ["search#{path}", field, value].join('/')
13
+
14
+ if response = api_client.get(search_path)
15
+ if response.code.to_i == success_status_code
16
+ JSON.parse(response.body).map do |attributes|
17
+ collection_class.new(attributes.merge(from_api: true))
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,3 +1,3 @@
1
1
  module FsApi
2
- VERSION = "0.7.0"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/fs_api.rb CHANGED
@@ -1,13 +1,17 @@
1
1
  require 'json'
2
2
 
3
3
  require "fs_api/client"
4
+ require "fs_api/service/searchable"
4
5
  require "fs_api/service/base_service"
5
6
  require "fs_api/service/client"
6
7
  require "fs_api/service/invoice"
8
+ require "fs_api/service/invoices_payment"
9
+ require "fs_api/service/invoices_saved"
7
10
  require "fs_api/service/product"
8
11
  require "fs_api/resource/resource"
9
12
  require "fs_api/resource/client"
10
13
  require "fs_api/resource/invoice"
14
+ require "fs_api/resource/invoices_payment"
11
15
  require "fs_api/resource/product"
12
16
 
13
17
  module FsApi
@@ -53,4 +53,26 @@ describe FsApi::Service::Client do
53
53
  service.save(client)
54
54
  end
55
55
  end
56
+
57
+ describe "search" do
58
+ it "searches in all fields" do
59
+ stub_request(:get, "https://username:api_key@www.factuursturen.nl/api/v1/search/clients/all/john").
60
+ to_return(body: [json_response(:client)].to_json )
61
+
62
+ clients = service.search('john')
63
+
64
+ expect(clients.size).to eq 1
65
+ expect(clients.first.clientnr).to eq '1'
66
+ end
67
+
68
+ it "searches in a fields" do
69
+ stub_request(:get, "https://username:api_key@www.factuursturen.nl/api/v1/search/clients/city/john").
70
+ to_return(body: [json_response(:client)].to_json )
71
+
72
+ clients = service.search(city: 'john')
73
+
74
+ expect(clients.size).to eq 1
75
+ expect(clients.first.clientnr).to eq '1'
76
+ end
77
+ end
56
78
  end
@@ -1,6 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
- describe FsApi::Service::Client do
3
+ describe FsApi::Service::Invoice do
4
4
 
5
5
  let(:api_client) { FsApi::Client.new('username', 'api_key') }
6
6
  let(:service) { FsApi::Service::Invoice.new(api_client) }
@@ -43,4 +43,26 @@ describe FsApi::Service::Client do
43
43
  expect(invoice.invoicenr).to eq 2
44
44
  end
45
45
  end
46
+
47
+ describe "search" do
48
+ it "searches in all fields" do
49
+ stub_request(:get, "https://username:api_key@www.factuursturen.nl/api/v1/search/invoices/all/john").
50
+ to_return(body: [json_response(:invoice)].to_json )
51
+
52
+ invoices = service.search('john')
53
+
54
+ expect(invoices.size).to eq 1
55
+ expect(invoices.first.invoicenr).to eq 'F20150001'
56
+ end
57
+
58
+ it "searches in a fields" do
59
+ stub_request(:get, "https://username:api_key@www.factuursturen.nl/api/v1/search/invoices/city/john").
60
+ to_return(body: [json_response(:invoice)].to_json )
61
+
62
+ invoices = service.search(city: 'john')
63
+
64
+ expect(invoices.size).to eq 1
65
+ expect(invoices.first.invoicenr).to eq 'F20150001'
66
+ end
67
+ end
46
68
  end
@@ -0,0 +1,20 @@
1
+ require "spec_helper"
2
+
3
+ describe FsApi::Service::InvoicesPayment do
4
+
5
+ let(:api_client) { FsApi::Client.new('username', 'api_key') }
6
+ let(:service) { FsApi::Service::InvoicesPayment.new(api_client) }
7
+ let(:invoice) { FsApi::Resource::Invoice.new(json_response(:invoice).merge('from_api' => true)) }
8
+
9
+ describe "creation" do
10
+ it "creates a invoice" do
11
+ stub_request(:post, "https://username:api_key@www.factuursturen.nl/api/v1/invoices_payment/2").
12
+ to_return(status: 201)
13
+
14
+
15
+ response = service.create({'id' => 2, date: Time.now, amount: 'full'})
16
+ expect(response.amount).to eq 'full'
17
+ expect(response.errors).to be_nil
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,35 @@
1
+ require "spec_helper"
2
+
3
+ describe FsApi::Service::InvoicesSaved do
4
+
5
+ let(:api_client) { FsApi::Client.new('username', 'api_key') }
6
+ let(:service) { FsApi::Service::InvoicesSaved.new(api_client) }
7
+ let(:invoice) { FsApi::Resource::Invoice.new(json_response(:invoice).merge('from_api' => true)) }
8
+
9
+ describe "retrieval" do
10
+ it "retrieves all invoices" do
11
+ stub_request(:get, "https://username:api_key@www.factuursturen.nl/api/v1/invoices_saved").to_return(body: [json_response(:invoice)].to_json )
12
+
13
+ invoices = service.all
14
+
15
+ expect(invoices.size).to eq 1
16
+ expect(invoices.first.invoicenr).to eq 'F20150001'
17
+ end
18
+
19
+ it "retrieves a invoice" do
20
+ stub_request(:get, "https://username:api_key@www.factuursturen.nl/api/v1/invoices_saved/20150001").to_return(body: { 'invoice' => json_response(:invoice)}.to_json )
21
+
22
+ invoice = service.find('20150001')
23
+
24
+ expect(invoice.invoicenr).to eq 'F20150001'
25
+ end
26
+ end
27
+
28
+ describe "deletion" do
29
+ it "deletes a invoice" do
30
+ stub_request(:delete, "https://username:api_key@www.factuursturen.nl/api/v1/invoices_saved/20150001")
31
+
32
+ service.delete(invoice)
33
+ end
34
+ end
35
+ end
@@ -1,6 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
- describe FsApi::Service::Client do
3
+ describe FsApi::Service::Product do
4
4
  let(:api_client) { FsApi::Client.new('username', 'api_key') }
5
5
 
6
6
  let(:service) { FsApi::Service::Product.new(api_client) }
@@ -52,4 +52,26 @@ describe FsApi::Service::Client do
52
52
  service.save(product)
53
53
  end
54
54
  end
55
+
56
+ describe "search" do
57
+ it "searches in all fields" do
58
+ stub_request(:get, "https://username:api_key@www.factuursturen.nl/api/v1/search/products/all/john").
59
+ to_return(body: [json_response(:product)].to_json )
60
+
61
+ products = service.search('john')
62
+
63
+ expect(products.size).to eq 1
64
+ expect(products.first.code).to eq "product code"
65
+ end
66
+
67
+ it "searches in a fields" do
68
+ stub_request(:get, "https://username:api_key@www.factuursturen.nl/api/v1/search/products/city/john").
69
+ to_return(body: [json_response(:product)].to_json )
70
+
71
+ products = service.search(city: 'john')
72
+
73
+ expect(products.size).to eq 1
74
+ expect(products.first.code).to eq "product code"
75
+ end
76
+ end
55
77
  end
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: 0.7.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maarten van Vliet
@@ -49,6 +49,7 @@ files:
49
49
  - ".gitignore"
50
50
  - ".kick"
51
51
  - ".rspec"
52
+ - ".travis.yml"
52
53
  - Gemfile
53
54
  - LICENSE.txt
54
55
  - README.md
@@ -57,16 +58,22 @@ files:
57
58
  - lib/fs_api/client.rb
58
59
  - lib/fs_api/resource/client.rb
59
60
  - lib/fs_api/resource/invoice.rb
61
+ - lib/fs_api/resource/invoices_payment.rb
60
62
  - lib/fs_api/resource/product.rb
61
63
  - lib/fs_api/resource/resource.rb
62
64
  - lib/fs_api/service/base_service.rb
63
65
  - lib/fs_api/service/client.rb
64
66
  - lib/fs_api/service/invoice.rb
67
+ - lib/fs_api/service/invoices_payment.rb
68
+ - lib/fs_api/service/invoices_saved.rb
65
69
  - lib/fs_api/service/product.rb
70
+ - lib/fs_api/service/searchable.rb
66
71
  - lib/fs_api/version.rb
67
72
  - spec/lib/fs_api/client_spec.rb
68
73
  - spec/lib/fs_api/service/client_spec.rb
69
74
  - spec/lib/fs_api/service/invoice_spec.rb
75
+ - spec/lib/fs_api/service/invoices_payment_spec.rb
76
+ - spec/lib/fs_api/service/invoices_saved_spec.rb
70
77
  - spec/lib/fs_api/service/product_spec.rb
71
78
  - spec/spec_helper.rb
72
79
  - spec/support/json_response_helper.rb
@@ -101,6 +108,8 @@ test_files:
101
108
  - spec/lib/fs_api/client_spec.rb
102
109
  - spec/lib/fs_api/service/client_spec.rb
103
110
  - spec/lib/fs_api/service/invoice_spec.rb
111
+ - spec/lib/fs_api/service/invoices_payment_spec.rb
112
+ - spec/lib/fs_api/service/invoices_saved_spec.rb
104
113
  - spec/lib/fs_api/service/product_spec.rb
105
114
  - spec/spec_helper.rb
106
115
  - spec/support/json_response_helper.rb