fakturan_nu 1.2.0 → 1.2.1

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: 64fc9b74cfb95861e8b574f428566b6bfbd595c7
4
- data.tar.gz: 06bf8ba9173850d5ea72d6b83480a547a978c5b6
3
+ metadata.gz: 02e35fa5a923f61075b3e317194962264c8ee81f
4
+ data.tar.gz: ae4c21387becc98cce2317202131450e7aa9feb4
5
5
  SHA512:
6
- metadata.gz: f39f502582ebd9e7dd6afc6c1a860224fe7b0654bdf141bc9eb6efd6c09f859eb476e20420c53b9f27e026e3fa4104b553b958c29c239e0520e888fda35ab936
7
- data.tar.gz: d15e1c04982734057338d0060de635f4281769d6ab160814678d85ddb36978389066af543b7d9f977a1cb6c4504ccd6c97625475e15f923ab36d2d7687a26f24
6
+ metadata.gz: b8f81b2e68400977172e5dfd33d32e81d55c41a7211985836c26a8a8937603a0a229d03de9f96df4c10520254c85a27fe839a86b394dfd1dbb18224d431a9617
7
+ data.tar.gz: b56c5ae954df126117441917ad54303e3dde7cac5457556c4b395e07f82f31dedfc4f62ada4f02a979384d76932bd91ce62405355d71818e56a65db156b8e52a
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Ruby client for the fakturan.nu API
2
2
  ==============================
3
3
 
4
- API client in ruby for the Swedish web based invoicing software [fakturan.nu](https://www.fakturan.nu). The API is currently in Beta and may be subject to change without notice until final release.
4
+ API client in ruby for the Swedish web based invoicing software [fakturan.nu](https://www.fakturan.nu).
5
5
 
6
6
  ---
7
7
 
@@ -30,7 +30,7 @@ If you're not using Rails, just ``` require 'fakturan_nu'``` and run setup where
30
30
 
31
31
  ### General
32
32
 
33
- The client attempts to provide an interface similar to ActiveRecord.
33
+ The api client attempts to provide an interface similar to ActiveRecord.
34
34
 
35
35
  ```ruby
36
36
  Fakturan::Product.all
@@ -56,7 +56,7 @@ product.save
56
56
 
57
57
  ### Invoices
58
58
 
59
- For creating invoices, a client is required. It can be an existing client (by using ```client_id```), or a new one (by using ```client```):
59
+ For creating invoices, a client/customer is required. It can be an existing client (by using ```client_id```), or a new one (by using ```client```):
60
60
 
61
61
  ```ruby
62
62
  invoice = Fakturan::Invoice.create(client: { company: "Acme Inc" })
@@ -72,6 +72,15 @@ invoice = Fakturan::Invoice.create(client_id: 1, rows: [{ product_name: "Shoes",
72
72
  # POST "https://fakturan.nu/api/v2/invoices" # Will create a new invoice for client with id: 1
73
73
  ```
74
74
 
75
+ ### Finding specific resources
76
+
77
+ Some resources can be found by other attributes than their id. Any attribute that can be used for *filtering* on the list action, (see [client/list](https://sandbox.fakturan.nu/apidocs/2/clients/index.en.html) for example) can be used to find a single resource as well. This is done through the same find_by-interface that ActiveRecord uses:
78
+
79
+ ```ruby
80
+ Client.find_by(number: 123)
81
+ # GET "https://fakturan.nu/api/v2/clients?number=123" # Find a client by number or return nil if not found
82
+ ```
83
+
75
84
  ### Available resources and properties
76
85
 
77
86
  For a full list of resources and the properties of each type of resource, see the [api reference](https://sandbox.fakturan.nu/apidocs).
data/fakturan_nu.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |s|
3
3
  s.name = 'fakturan_nu'
4
- s.version = '1.2.0'
4
+ s.version = '1.2.1'
5
5
  s.date = '2015-05-11'
6
6
  s.summary = 'A ruby client for the Fakturan.nu - API'
7
7
  s.description = 'A ruby client for the Fakturan.nu - API. Fakturan.nu is a webbapp for billing.'
data/lib/fakturan_nu.rb CHANGED
@@ -14,6 +14,9 @@ require 'fakturan_nu/product'
14
14
  require 'fakturan_nu/client'
15
15
  require 'fakturan_nu/row'
16
16
  require 'fakturan_nu/invoice'
17
+ require 'fakturan_nu/account'
18
+ require 'fakturan_nu/setting'
19
+ require 'fakturan_nu/user'
17
20
 
18
21
  I18n.load_path += Dir.glob( File.dirname(__FILE__) + "lib/locales/*.{rb,yml}" )
19
22
 
@@ -0,0 +1,27 @@
1
+ module Fakturan
2
+ class Account < Base
3
+ uri 'accounts/(:id)'
4
+ has_many :users, uri: nil
5
+ belongs_to :setting, uri: nil
6
+
7
+ attributes :api_token
8
+
9
+ accepts_nested_attributes_for :users, :setting
10
+
11
+ def users=(attrs_or_obj_array)
12
+ if attrs_or_obj_array.first.respond_to?(:each)
13
+ send(:users_attributes=, attrs_or_obj_array)
14
+ else
15
+ super
16
+ end
17
+ end
18
+
19
+ def setting=(attrs_or_obj)
20
+ if attrs_or_obj.respond_to?(:each)
21
+ send(:setting_attributes=, attrs_or_obj)
22
+ else
23
+ super
24
+ end
25
+ end
26
+ end
27
+ end
@@ -41,7 +41,7 @@ module Fakturan
41
41
 
42
42
  # The errors are for an associated object, and there is an associated object to put them on
43
43
  if (association = self.class.reflect_on_association(ass_name)) && !self.send(ass_name).blank?
44
- if association.type == Spyke::Associations::HasMany
44
+ if association.type == Spyke::Associations::HasMany && self.respond_to?(field_name.to_sym)
45
45
  # We need to add one error to our "base" object so that it's not valid
46
46
  self.add_to_errors(field_name.to_sym, [{error: :invalid}])
47
47
  field_errors.each do |new_error_hash_with_index| # new_error_hash_OR_error_type ("blank") on presence of has_many
@@ -63,14 +63,16 @@ module Fakturan
63
63
  association_target_parent = path_sub_parts[0..-2].inject(self, :send)
64
64
 
65
65
  # We add the error to the associated object
66
- association_target.add_to_errors(field_name, field_errors)
67
- # and then we get the errors (with generated messages) and add them to
68
- # the parent (but without details, like nested_attributes works)
69
- # This only makes sense on belongs_to and has_one, since it's impossible
70
- # to know which object is refered to on has_many
71
- association_target.errors.each do |attribute, message|
72
- association_target_parent.errors[full_field_path] << message
73
- association_target_parent.errors[full_field_path].uniq!
66
+ if association_target.respond_to?(field_name)
67
+ association_target.add_to_errors(field_name, field_errors)
68
+ # and then we get the errors (with generated messages) and add them to
69
+ # the parent (but without details, like nested_attributes works)
70
+ # This only makes sense on belongs_to and has_one, since it's impossible
71
+ # to know which object is refered to on has_many
72
+ association_target.errors.each do |attribute, message|
73
+ association_target_parent.errors[full_field_path] << message
74
+ association_target_parent.errors[full_field_path].uniq!
75
+ end
74
76
  end
75
77
  end
76
78
  end
@@ -19,7 +19,7 @@ module Fakturan
19
19
  else # If we get 204 = request fine, but no content returned
20
20
  env.body = { data: {}, metadata: {}, errors: {} }
21
21
  end
22
- rescue MultiJson::ParseError => exception
22
+ rescue MultiJson::ParseError
23
23
  raise Fakturan::Error::ParseError, {:status => env.status, :headers => env.response_headers, :body => env.body}
24
24
  end
25
25
  end
@@ -0,0 +1,5 @@
1
+ module Fakturan
2
+ class Setting < Base
3
+ attributes :company_email
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ module Fakturan
2
+ class User < Base
3
+ attributes :login, :name
4
+
5
+ validates :login, presence: true
6
+ validates :name, presence: true
7
+ end
8
+ end
@@ -114,6 +114,13 @@ module Fakturan
114
114
  assert_equal ({:company=>[{:error=>:blank}]}), invoice.client.errors.details
115
115
  end
116
116
 
117
+ def test_ignores_errors_for_nonexistant_attributes
118
+ stub_api_request(:post, '/accounts').to_return(body: {errors: { "users.email" => [{ error: "taken", value: "palle@kuling.net"}], "users.login" => [{error:"taken",value:"palle@kuling.net"}], users: [{"0" => { "users.email" => [{error: "taken", value: "palle@kuling.net"}], "users.login" => [{ error: "taken", value: "palle@kuling.net"}]}}]}}.to_json, status: 422)
119
+
120
+ account = Fakturan::Account.new( setting: { company_email: "palle@kuling.net" }, users: [{ email: "palle@kuling.net", password: "asdfasdf", firstname: "asdfasdf", lastname: "asdfasdf"}])
121
+ assert !account.save # Should just return false without raising errors
122
+ end
123
+
117
124
  def test_validation_errors_on_nested_associated_objects
118
125
  stub_api_request(:post, '/invoices').to_return(body: {errors: {date: [{error: :blank},{error: :invalid}], :"client.address.country" => [{ error: :blank}]}}.to_json, status: 422)
119
126
  invoice = Fakturan::Invoice.new(client: { address: { street_address: 'Some street' } })
data/test/models_test.rb CHANGED
@@ -28,19 +28,12 @@ module Fakturan
28
28
  assert_equal nil, client
29
29
  end
30
30
 
31
- def get_good_invoice
32
- return if @invoice # We won't change this instance so we really only need to do this once.
33
- @invoice = Fakturan::Invoice.find(5)
34
- end
35
-
36
- def test_find_one_and_access_attribute
37
- client = Fakturan::Client.find(1)
38
- assert client.name.is_a? String
31
+ def good_invoice
32
+ @invoice ||= Fakturan::Invoice.find(5)
39
33
  end
40
34
 
41
35
  def test_should_create_associated_objects
42
- get_good_invoice
43
- assert_equal @invoice.address.name, 'A simple client'
36
+ assert_equal good_invoice.address.name, 'A simple client'
44
37
  end
45
38
 
46
39
  def test_should_be_able_to_fetch_and_update_invoice
@@ -51,11 +44,10 @@ module Fakturan
51
44
  end
52
45
 
53
46
  def test_should_fetch_associated_record
54
- get_good_invoice
55
47
  client = Fakturan::Client.find(11)
56
48
  assert_equal Fakturan::Client, client.class
57
49
  assert_equal 'A simple client', client.name
58
- assert_equal client.name, @invoice.client.name
50
+ assert_equal client.name, good_invoice.client.name
59
51
  end
60
52
 
61
53
  def test_find_one_and_access_attribute
@@ -116,8 +108,7 @@ module Fakturan
116
108
  end
117
109
 
118
110
  def test_date_fields_should_not_be_typecast
119
- get_good_invoice
120
- assert_equal String, @invoice.date.class
111
+ assert_equal String, good_invoice.date.class
121
112
  end
122
113
 
123
114
  def test_getting_attribute_on_new_instance
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fakturan_nu
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Bourque Olivegren
@@ -203,6 +203,7 @@ files:
203
203
  - config/locales/en.yml
204
204
  - fakturan_nu.gemspec
205
205
  - lib/fakturan_nu.rb
206
+ - lib/fakturan_nu/account.rb
206
207
  - lib/fakturan_nu/address.rb
207
208
  - lib/fakturan_nu/base.rb
208
209
  - lib/fakturan_nu/client.rb
@@ -213,7 +214,9 @@ files:
213
214
  - lib/fakturan_nu/middleware/raise_error.rb
214
215
  - lib/fakturan_nu/product.rb
215
216
  - lib/fakturan_nu/row.rb
217
+ - lib/fakturan_nu/setting.rb
216
218
  - lib/fakturan_nu/spyke_extensions.rb
219
+ - lib/fakturan_nu/user.rb
217
220
  - test/basics_test.rb
218
221
  - test/exceptions_test.rb
219
222
  - test/fixtures.rb
@@ -240,7 +243,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
240
243
  version: '0'
241
244
  requirements: []
242
245
  rubyforge_project:
243
- rubygems_version: 2.2.2
246
+ rubygems_version: 2.4.5.1
244
247
  signing_key:
245
248
  specification_version: 4
246
249
  summary: A ruby client for the Fakturan.nu - API