fakturoid 0.1.0 → 0.1.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: 076c161dacf951eb18acf2852ef982e0105ca544
4
- data.tar.gz: dadf19899fa9ee0eda8bb8e96ca8e225ac166194
3
+ metadata.gz: 6e7ed6762d5dc5f9d0e070d17634ef90c6998ed3
4
+ data.tar.gz: a7014987ec7c1a578836ce9aa8bf3fe12c22ea45
5
5
  SHA512:
6
- metadata.gz: 8b46b7684942b394c3bd00dcd256e5a66ff388737371be5f61441b73b10920fe1cb0197892de2ee79d2433a47a1e33c5974bdc4fbc70383209d003ff98aa5359
7
- data.tar.gz: 68ebfce58da609f156a85657f8d05057ca7888f0ae703e654f2514e4fb4698dd7b454256faa80fa38bf534a1e1566a8f75daf2b585a2f20c3e20117b4ad47942
6
+ metadata.gz: 061964316f09a034a40be9f9d08f03e55f8f57d199b0af9295fbd3dee8ec1679b96753b3ec0a98e8facc55a5a6a74b5a258e2e5463763d98aac3b4d8c30a0112
7
+ data.tar.gz: cea2e8ec2f2bf02a903d0f9b2cbe3c8b15ee4a8bf8bd88b40507f0d9f6931da25027ddd2c08831827fcf2f54103c7033b46a566641ce41491a288b38d54508eb
data/.gitignore CHANGED
@@ -4,3 +4,4 @@ coverage/
4
4
  doc/
5
5
  pkg/
6
6
  .DS_Store
7
+ rubocop.html
data/.rubocop.yml ADDED
@@ -0,0 +1,35 @@
1
+ Metrics/LineLength:
2
+ Enabled: false
3
+
4
+ Metrics/ClassLength:
5
+ Exclude:
6
+ - 'test/**/*'
7
+
8
+ Style/AccessModifierIndentation:
9
+ EnforcedStyle: outdent
10
+
11
+ Style/CaseIndentation:
12
+ IndentOneStep: true
13
+
14
+ Style/SignalException:
15
+ EnforcedStyle: only_raise
16
+
17
+ Style/TrailingWhitespace:
18
+ Enabled: false
19
+
20
+ Style/ClassAndModuleChildren:
21
+ Exclude:
22
+ - 'test/**/*'
23
+
24
+ Style/SpaceAroundOperators:
25
+ MultiSpaceAllowedForOperators:
26
+ - '<'
27
+ - '='
28
+
29
+ Documentation:
30
+ Enabled: false
31
+
32
+ AllCops:
33
+ Exclude:
34
+ - 'Rakefile'
35
+ - 'fakturoid.gemspec'
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.2.0
1
+ 2.2.2
data/CHANGELOG.md CHANGED
@@ -1 +1,18 @@
1
- ## 0.1.0 (Initial version)
1
+ ## 0.1.1
2
+
3
+ - Added support for `updated_since` param.
4
+ - Defined `respond_to_missing?` method for `Response` class. Example:
5
+
6
+ ```ruby
7
+ ### Before
8
+ invoice = Fakturoid::Client::Invoice.find(1234)
9
+ invoice.respond_to?(:number)
10
+ # => false
11
+
12
+ ### After
13
+ invoice = Fakturoid::Client::Invoice.find(1234)
14
+ invoice.respond_to?(:number)
15
+ # => true
16
+ ```
17
+
18
+ ## 0.1.0 (Initial version)
data/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  The Fakturoid gem is ruby library for API communication with web based invoicing service [www.fakturoid.cz](https://fakturoid.cz).
4
4
  Fakturoid [API documentation](http://docs.fakturoid.apiary.io).
5
5
 
6
+ [![Gem Version](https://badge.fury.io/rb/fakturoid.svg)](http://badge.fury.io/rb/fakturoid)
6
7
  [![Circle CI](https://circleci.com/gh/fakturoid/fakturoid-ruby.svg?style=svg)](https://circleci.com/gh/fakturoid/fakturoid-ruby)
7
8
 
8
9
  ## Installation
@@ -10,16 +11,13 @@ Fakturoid [API documentation](http://docs.fakturoid.apiary.io).
10
11
  Add this line to your application's Gemfile:
11
12
 
12
13
  ```ruby
13
- gem 'fakturoid', git: 'https://github.com/fakturoid/fakturoid-ruby.git'
14
+ gem 'fakturoid'
14
15
  ```
15
16
 
16
17
  And then run:
17
18
 
18
19
  $ bundle
19
20
 
20
- Gem is not officially released and is under construction. So if you want to use it please install it from this repository
21
- and specify `:ref` option. API of the Fakturoid gem can be still changed.
22
-
23
21
  ## Configuration
24
22
 
25
23
  Fakturoid gem is configured within config block placed in `config/initializers/fakturoid.rb`:
@@ -260,3 +258,6 @@ The Fakturoid gem raises exceptions if error response is returned from the serve
260
258
  </tr>
261
259
  </tbody>
262
260
  </table>
261
+
262
+ ## Thanks
263
+ Development was supported by [eBallance Creative s.r.o.](http://www.eballance.cz)
data/fakturoid.gemspec CHANGED
@@ -26,4 +26,5 @@ Gem::Specification.new do |s|
26
26
  s.add_development_dependency "minitest"
27
27
  s.add_development_dependency "shoulda-context"
28
28
  s.add_development_dependency "mocha"
29
+ s.add_development_dependency "rubocop"
29
30
  end
data/lib/fakturoid.rb CHANGED
@@ -12,7 +12,6 @@ require 'fakturoid/version'
12
12
  require 'fakturoid/railtie' if defined?(::Rails)
13
13
 
14
14
  module Fakturoid
15
-
16
15
  class ApiError < StandardError
17
16
  attr_accessor :response_code, :response_body
18
17
 
data/lib/fakturoid/api.rb CHANGED
@@ -14,4 +14,4 @@ module Fakturoid
14
14
  @config
15
15
  end
16
16
  end
17
- end
17
+ end
@@ -2,7 +2,7 @@ module Fakturoid
2
2
  class Api
3
3
  module Arguments
4
4
  def permit_params(params_hash, *permitted_params)
5
- params_hash.select { |param, value| permitted_params.include?(param.to_sym) }
5
+ params_hash.select { |param, _value| permitted_params.include?(param.to_sym) }
6
6
  end
7
7
 
8
8
  def validate_numerical_id(id)
@@ -16,4 +16,4 @@ module Fakturoid
16
16
  end
17
17
  end
18
18
  end
19
- end
19
+ end
@@ -18,4 +18,4 @@ module Fakturoid
18
18
  end
19
19
  end
20
20
  end
21
- end
21
+ end
@@ -6,4 +6,4 @@ require 'fakturoid/client/invoice'
6
6
  require 'fakturoid/client/expense'
7
7
  require 'fakturoid/client/generator'
8
8
  require 'fakturoid/client/event'
9
- require 'fakturoid/client/todo'
9
+ require 'fakturoid/client/todo'
@@ -6,4 +6,4 @@ module Fakturoid
6
6
  end
7
7
  end
8
8
  end
9
- end
9
+ end
@@ -1,9 +1,9 @@
1
1
  module Fakturoid
2
2
  module Client
3
3
  class BankAccount < Fakturoid::Api
4
- def self.all
4
+ def self.all
5
5
  get_request('bank_accounts.json')
6
6
  end
7
7
  end
8
8
  end
9
- end
9
+ end
@@ -14,4 +14,4 @@ module Fakturoid
14
14
  end
15
15
  end
16
16
  end
17
- end
17
+ end
@@ -2,7 +2,7 @@ module Fakturoid
2
2
  module Client
3
3
  class Expense < Fakturoid::Api
4
4
  def self.all(params = {})
5
- request_params = permit_params(params, :page, :since, :number, :variable_symbol, :status, :subject_id) || {}
5
+ request_params = permit_params(params, :page, :since, :updated_since, :number, :variable_symbol, :status, :subject_id) || {}
6
6
 
7
7
  get_request('expenses.json', request_params: request_params)
8
8
  end
@@ -37,4 +37,4 @@ module Fakturoid
37
37
  end
38
38
  end
39
39
  end
40
- end
40
+ end
@@ -2,19 +2,19 @@ module Fakturoid
2
2
  module Client
3
3
  class Generator < Fakturoid::Api
4
4
  def self.all(params = {})
5
- request_params = permit_params(params, :page, :since, :subject_id) || {}
5
+ request_params = permit_params(params, :page, :since, :updated_since, :subject_id) || {}
6
6
 
7
7
  get_request('generators.json', request_params: request_params)
8
8
  end
9
9
 
10
10
  def self.recurring(params = {})
11
- request_params = permit_params(params, :page, :since, :subject_id) || {}
11
+ request_params = permit_params(params, :page, :since, :updated_since, :subject_id) || {}
12
12
 
13
13
  get_request('generators/recurring.json', request_params: request_params)
14
14
  end
15
15
 
16
16
  def self.template(params = {})
17
- request_params = permit_params(params, :page, :since, :subject_id) || {}
17
+ request_params = permit_params(params, :page, :since, :updated_since, :subject_id) || {}
18
18
 
19
19
  get_request('generators/template.json', request_params: request_params)
20
20
  end
@@ -39,4 +39,4 @@ module Fakturoid
39
39
  end
40
40
  end
41
41
  end
42
- end
42
+ end
@@ -2,19 +2,19 @@ module Fakturoid
2
2
  module Client
3
3
  class Invoice < Fakturoid::Api
4
4
  def self.all(params = {})
5
- request_params = permit_params(params, :page, :since, :number, :status, :subject_id) || {}
5
+ request_params = permit_params(params, :page, :since, :updated_since, :number, :status, :subject_id) || {}
6
6
 
7
7
  get_request('invoices.json', request_params: request_params)
8
8
  end
9
9
 
10
10
  def self.regular(params = {})
11
- request_params = permit_params(params, :page, :since, :number, :status, :subject_id) || {}
11
+ request_params = permit_params(params, :page, :since, :updated_since, :number, :status, :subject_id) || {}
12
12
 
13
13
  get_request('invoices/regular.json', request_params: request_params)
14
14
  end
15
15
 
16
16
  def self.proforma(params = {})
17
- request_params = permit_params(params, :page, :since, :number, :status, :subject_id) || {}
17
+ request_params = permit_params(params, :page, :since, :updated_since, :number, :status, :subject_id) || {}
18
18
 
19
19
  get_request('invoices/proforma.json', request_params: request_params)
20
20
  end
@@ -59,4 +59,4 @@ module Fakturoid
59
59
  end
60
60
  end
61
61
  end
62
- end
62
+ end
@@ -2,7 +2,7 @@ module Fakturoid
2
2
  module Client
3
3
  class Subject < Fakturoid::Api
4
4
  def self.all(params = {})
5
- request_params = permit_params(params, :page, :since, :custom_id) || {}
5
+ request_params = permit_params(params, :page, :since, :updated_since, :custom_id) || {}
6
6
 
7
7
  get_request('subjects.json', request_params: request_params)
8
8
  end
@@ -32,4 +32,4 @@ module Fakturoid
32
32
  end
33
33
  end
34
34
  end
35
- end
35
+ end
@@ -13,4 +13,4 @@ module Fakturoid
13
13
  end
14
14
  end
15
15
  end
16
- end
16
+ end
@@ -15,4 +15,4 @@ module Fakturoid
15
15
  end
16
16
  end
17
17
  end
18
- end
18
+ end
@@ -5,7 +5,7 @@ module Fakturoid
5
5
 
6
6
  ENDPOINT = 'https://app.fakturoid.cz/api/v2'
7
7
 
8
- def initialize(&block)
8
+ def initialize(&_block)
9
9
  yield self
10
10
  end
11
11
 
@@ -25,4 +25,4 @@ module Fakturoid
25
25
  ENDPOINT
26
26
  end
27
27
  end
28
- end
28
+ end
@@ -19,4 +19,4 @@ module Fakturoid
19
19
  @connection
20
20
  end
21
21
  end
22
- end
22
+ end
@@ -1,4 +1,4 @@
1
1
  module Fakturoid
2
2
  class Railtie < Rails::Railtie
3
3
  end
4
- end
4
+ end
@@ -12,9 +12,8 @@ module Fakturoid
12
12
  end
13
13
 
14
14
  def call(params = {})
15
- unless HTTP_METHODS.include?(method.to_sym)
16
- raise ArgumentError, "Unknown http method: #{method}"
17
- end
15
+ raise ArgumentError, "Unknown http method: #{method}" unless HTTP_METHODS.include?(method.to_sym)
16
+
18
17
  request_params = params[:request_params] || {}
19
18
 
20
19
  http_connection = connection(params)
@@ -25,4 +24,4 @@ module Fakturoid
25
24
  Response.new(response, caller, method)
26
25
  end
27
26
  end
28
- end
27
+ end
@@ -14,14 +14,6 @@ module Fakturoid
14
14
  handle_response
15
15
  end
16
16
 
17
- def method_missing(method, *args, &block)
18
- if body && body.is_a?(Hash) && body.key?(method.to_s)
19
- body[method.to_s]
20
- else
21
- super
22
- end
23
- end
24
-
25
17
  def status_code
26
18
  env['status']
27
19
  end
@@ -35,7 +27,7 @@ module Fakturoid
35
27
  end
36
28
 
37
29
  def inspect
38
- "#<#{self.class.name}:#{object_id} @body=\"#{self.body}\" @status_code=\"#{status_code}\">"
30
+ "#<#{self.class.name}:#{object_id} @body=\"#{body}\" @status_code=\"#{status_code}\">"
39
31
  end
40
32
 
41
33
  private
@@ -66,5 +58,21 @@ module Fakturoid
66
58
  def error(klass, message = nil)
67
59
  klass.new message, status_code, body
68
60
  end
61
+
62
+ def method_missing(method, *args, &block)
63
+ if body_has_key?(method)
64
+ body[method.to_s]
65
+ else
66
+ super
67
+ end
68
+ end
69
+
70
+ def respond_to_missing?(method, _include_all)
71
+ body_has_key?(method) || super
72
+ end
73
+
74
+ def body_has_key?(key)
75
+ body && body.is_a?(Hash) && body.key?(key.to_s)
76
+ end
69
77
  end
70
- end
78
+ end
@@ -1,3 +1,3 @@
1
1
  module Fakturoid
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
data/test/api_test.rb CHANGED
@@ -1,22 +1,22 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class Fakturoid::ApiTest < Fakturoid::TestCase
4
- should "permit only required arguments" do
4
+ should 'permit only required arguments' do
5
5
  hash = { page: 4, number: '2015-0015', account: 15 }
6
6
  permitted_params = Fakturoid::Api.permit_params(hash, :page, :number, :status)
7
7
  assert_equal({ page: 4, number: '2015-0015' }, permitted_params)
8
8
  end
9
9
 
10
- should "raise argument error if id is in wrong format" do
10
+ should 'raise argument error if id is in wrong format' do
11
11
  assert_raises(ArgumentError) { Fakturoid::Api.validate_numerical_id(nil) }
12
- assert_raises(ArgumentError) { Fakturoid::Api.validate_numerical_id("nil") }
12
+ assert_raises(ArgumentError) { Fakturoid::Api.validate_numerical_id('nil') }
13
13
  assert Fakturoid::Api.validate_numerical_id(15)
14
- assert Fakturoid::Api.validate_numerical_id("15")
14
+ assert Fakturoid::Api.validate_numerical_id('15')
15
15
  end
16
16
 
17
- should "raise argument error if search query is not given" do
17
+ should 'raise argument error if search query is not given' do
18
18
  assert_raises(ArgumentError) { Fakturoid::Api.validate_search_query(nil) }
19
- assert_raises(ArgumentError) { Fakturoid::Api.validate_search_query("") }
20
- assert Fakturoid::Api.validate_search_query("Company name")
19
+ assert_raises(ArgumentError) { Fakturoid::Api.validate_search_query('') }
20
+ assert Fakturoid::Api.validate_search_query('Company name')
21
21
  end
22
- end
22
+ end
data/test/config_test.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class Fakturoid::ConfigTest < Fakturoid::TestCase
4
- should "configure with block param" do
5
- config = Fakturoid::Config.new do |config|
6
- config.email = 'test@email.cz'
7
- config.api_key = 'XXXXXXXXXXX'
8
- config.account = 'testaccount'
9
- config.user_agent = 'My test app (test@email.cz)'
4
+ should 'configure with block param' do
5
+ config = Fakturoid::Config.new do |c|
6
+ c.email = 'test@email.cz'
7
+ c.api_key = 'XXXXXXXXXXX'
8
+ c.account = 'testaccount'
9
+ c.user_agent = 'My test app (test@email.cz)'
10
10
  end
11
11
 
12
12
  assert_equal 'test@email.cz', config.email
@@ -15,24 +15,24 @@ class Fakturoid::ConfigTest < Fakturoid::TestCase
15
15
  assert_equal 'My test app (test@email.cz)', config.user_agent
16
16
  end
17
17
 
18
- should "use default user agent" do
19
- config = Fakturoid::Config.new do |config|
20
- config.email = 'test@email.cz'
21
- config.api_key = 'XXXXXXXXXXX'
22
- config.account = 'testaccount'
18
+ should 'use default user agent' do
19
+ config = Fakturoid::Config.new do |c|
20
+ c.email = 'test@email.cz'
21
+ c.api_key = 'XXXXXXXXXXX'
22
+ c.account = 'testaccount'
23
23
  end
24
24
 
25
25
  assert_equal 'Fakturoid ruby gem (test@email.cz)', config.user_agent
26
26
  end
27
27
 
28
- should "return correct endpoints" do
29
- config = Fakturoid::Config.new do |config|
30
- config.email = 'test@email.cz'
31
- config.api_key = 'XXXXXXXXXXX'
32
- config.account = 'testaccount'
28
+ should 'return correct endpoints' do
29
+ config = Fakturoid::Config.new do |c|
30
+ c.email = 'test@email.cz'
31
+ c.api_key = 'XXXXXXXXXXX'
32
+ c.account = 'testaccount'
33
33
  end
34
34
 
35
35
  assert_equal 'https://app.fakturoid.cz/api/v2/accounts/testaccount', config.endpoint
36
36
  assert_equal 'https://app.fakturoid.cz/api/v2', config.endpoint_without_account
37
37
  end
38
- end
38
+ end
@@ -0,0 +1,8 @@
1
+ {
2
+ "status": "Account blocked",
3
+ "overdue_invoices": [
4
+ {
5
+ "invoice_url": "http://app.fakturoid.dev/robot/p/3WfeLRO5HZ/2015-0002"
6
+ }
7
+ ]
8
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "errors": {
3
+ "number": [
4
+ "je povinná položka"
5
+ ]
6
+ }
7
+ }
@@ -0,0 +1,52 @@
1
+ [
2
+ {
3
+ "id": 6,
4
+ "custom_id": null,
5
+ "type": "customer",
6
+ "name": "Apple Czech s.r.o.",
7
+ "street": "Klimentská 1216/46",
8
+ "street2": null,
9
+ "city": "Praha",
10
+ "zip": "11000",
11
+ "country": "CZ",
12
+ "registration_no": "28897501",
13
+ "vat_no": "CZ28897501",
14
+ "bank_account": null,
15
+ "iban": null,
16
+ "variable_symbol": "",
17
+ "full_name": null,
18
+ "email": "",
19
+ "email_copy": null,
20
+ "phone": null,
21
+ "web": "https://www.apple.cz",
22
+ "avatar_url": "https://ssl.fakturoid.cz/images/company-contact.png",
23
+ "html_url": "https://app.fakturoid.cz/applecorp/subjects/6",
24
+ "url": "https://app.fakturoid.cz/api/v2/accounts/applecorp/subjects/6.json",
25
+ "updated_at": "2012-05-13T12:11:38+02:00"
26
+ },
27
+ {
28
+ "id": 28,
29
+ "custom_id": null,
30
+ "type": "supplier",
31
+ "name": "MICROSOFT s.r.o.",
32
+ "street": "Vyskočilova 1461/2a",
33
+ "street2": null,
34
+ "city": "Praha",
35
+ "zip": "14000",
36
+ "country": "Česká republika",
37
+ "registration_no": "47123737",
38
+ "vat_no": "CZ47123737",
39
+ "bank_account": "",
40
+ "iban": "",
41
+ "variable_symbol": "1234567890"
42
+ "full_name": "",
43
+ "email": "",
44
+ "email_copy": "",
45
+ "phone": "",
46
+ "web": "",
47
+ "avatar_url": "https://ssl.fakturoid.cz/images/company-contact.png",
48
+ "html_url": "https://app.fakturoid.cz/applecorp/subjects/28",
49
+ "url": "https://app.fakturoid.cz/api/v2/accounts/applecorp/subjects/28.json",
50
+ "updated_at": "2012-06-02T09:34:47+02:00"
51
+ }
52
+ ]
data/test/request_test.rb CHANGED
@@ -1,13 +1,13 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class Fakturoid::RequestTest < Fakturoid::TestCase
4
- should "should return pdf" do
4
+ should 'should return pdf' do
5
5
  pdf = load_fixture('invoice.pdf')
6
6
  test_connection = Faraday.new do |builder|
7
7
  builder.adapter :test do |stub|
8
- stub.get('invoices/5/download.pdf') { |env| [ 200, {content_type: 'application/pdf'}, pdf ]}
8
+ stub.get('invoices/5/download.pdf') { |_env| [200, { content_type: 'application/pdf' }, pdf] }
9
9
  end
10
- builder.headers = { content_type: 'applicatoin/pdf' }
10
+ builder.headers = { content_type: 'application/pdf' }
11
11
  end
12
12
  Fakturoid::Request.any_instance.stubs(:connection).returns(test_connection)
13
13
 
@@ -15,4 +15,4 @@ class Fakturoid::RequestTest < Fakturoid::TestCase
15
15
  assert !response.json?
16
16
  assert_raises(NoMethodError) { response.name }
17
17
  end
18
- end
18
+ end
@@ -0,0 +1,187 @@
1
+ require 'test_helper'
2
+
3
+ class Fakturoid::ResponseTest < Fakturoid::TestCase
4
+ should 'should return json invoice' do
5
+ json = load_fixture('invoice.json')
6
+ test_connection = Faraday.new do |builder|
7
+ builder.adapter :test do |stub|
8
+ stub.get('invoices/5.json') { |_env| [200, { content_type: 'application/json' }, json] }
9
+ end
10
+ builder.headers = { content_type: 'application/json', user_agent: 'Fakturoid gem (email@testmail.cz)' }
11
+ end
12
+
13
+ response = Fakturoid::Response.new(test_connection.get('invoices/5.json'), Fakturoid::Client::Invoice, :get)
14
+ assert response.json?
15
+ assert_equal 200, response.status_code
16
+ assert_equal 5, response.id
17
+ assert_equal 5, response.body['id']
18
+ assert response.respond_to?(:body)
19
+ assert response.respond_to?(:id)
20
+ assert_raises(NoMethodError) { response.name }
21
+ end
22
+
23
+ context 'Exceptions' do
24
+ should 'raise user agent error' do
25
+ test_connection = Faraday.new do |builder|
26
+ builder.adapter :test do |stub|
27
+ stub.get('invoices/5.json') { |_env| [400, { content_type: 'application/json' }, ' '] }
28
+ end
29
+ builder.headers = { content_type: 'application/json', user_agent: '' }
30
+ end
31
+
32
+ assert_raises(Fakturoid::UserAgentError) { Fakturoid::Response.new(test_connection.get('invoices/5.json'), Fakturoid::Client::Invoice, :get) }
33
+ end
34
+
35
+ should 'raise pagination error' do
36
+ test_connection = Faraday.new do |builder|
37
+ builder.adapter :test do |stub|
38
+ stub.get('invoices.json?page=4') { |_env| [400, { content_type: 'application/json' }, ' '] }
39
+ end
40
+ builder.headers = { content_type: 'application/json', user_agent: 'Fakturoid gem (email@testmail.cz)' }
41
+ end
42
+
43
+ assert_raises(Fakturoid::PaginationError) { Fakturoid::Response.new(test_connection.get('invoices.json?page=4'), Fakturoid::Client::Invoice, :get) }
44
+ end
45
+
46
+ should 'raise authentication error' do
47
+ test_connection = Faraday.new do |builder|
48
+ builder.adapter :test do |stub|
49
+ stub.get('invoices.json?page=4') { |_env| [401, { content_type: 'application/json' }, ' '] }
50
+ end
51
+ builder.headers = { content_type: 'application/json', user_agent: 'Fakturoid gem (email@testmail.cz)' }
52
+ end
53
+
54
+ assert_raises(Fakturoid::AuthenticationError) { Fakturoid::Response.new(test_connection.get('invoices.json?page=4'), Fakturoid::Client::Invoice, :get) }
55
+ end
56
+
57
+ should 'raise blocked account error' do
58
+ json = load_fixture('blocked_account.json')
59
+ test_connection = Faraday.new do |builder|
60
+ builder.adapter :test do |stub|
61
+ stub.get('account.json') { |_env| [402, { content_type: 'application/json' }, json] }
62
+ end
63
+ builder.headers = { content_type: 'application/json', user_agent: 'Fakturoid gem (email@testmail.cz)' }
64
+ end
65
+
66
+ begin
67
+ Fakturoid::Response.new(test_connection.get('account.json'), Fakturoid::Client::Account, :get)
68
+ rescue Fakturoid::BlockedAccountError => e
69
+ assert_equal 402, e.response_code
70
+ assert e.response_body.key?('status')
71
+ rescue => e
72
+ assert false, "Raised exception was not expected: #{e.class}"
73
+ else
74
+ assert false, 'Exception was expected'
75
+ end
76
+ end
77
+
78
+ should 'raise destroy subject error' do
79
+ test_connection = Faraday.new do |builder|
80
+ builder.adapter :test do |stub|
81
+ stub.delete('subjects/5.json') { |_env| [403, { content_type: 'application/json' }, ' '] }
82
+ end
83
+ builder.headers = { content_type: 'application/json', user_agent: 'Fakturoid gem (email@testmail.cz)' }
84
+ end
85
+
86
+ assert_raises(Fakturoid::DestroySubjectError) { Fakturoid::Response.new(test_connection.delete('subjects/5.json'), Fakturoid::Client::Subject, :delete) }
87
+ end
88
+
89
+ should 'raise subject limit error' do
90
+ test_connection = Faraday.new do |builder|
91
+ builder.adapter :test do |stub|
92
+ stub.post('subjects.json') { |_env| [403, { content_type: 'application/json' }, ' '] }
93
+ end
94
+ builder.headers = { content_type: 'application/json', user_agent: 'Fakturoid gem (email@testmail.cz)' }
95
+ end
96
+
97
+ assert_raises(Fakturoid::SubjectLimitError) { Fakturoid::Response.new(test_connection.post('subjects.json', name: 'Customer s.r.o.'), Fakturoid::Client::Subject, :post) }
98
+ end
99
+
100
+ should 'raise generator limit error' do
101
+ test_connection = Faraday.new do |builder|
102
+ builder.adapter :test do |stub|
103
+ stub.post('generators.json') { |_env| [403, { content_type: 'application/json' }, ' '] }
104
+ end
105
+ builder.headers = { content_type: 'application/json', user_agent: 'Fakturoid gem (email@testmail.cz)' }
106
+ end
107
+
108
+ assert_raises(Fakturoid::GeneratorLimitError) { Fakturoid::Response.new(test_connection.post('generators.json', name: 'Customer s.r.o.', recurring: true), Fakturoid::Client::Generator, :post) }
109
+ end
110
+
111
+ should 'raise unsupported feature error' do
112
+ test_connection = Faraday.new do |builder|
113
+ builder.adapter :test do |stub|
114
+ stub.post('invoices/5/message.json') { |_env| [403, { content_type: 'application/json' }, ' '] }
115
+ end
116
+ builder.headers = { content_type: 'application/json', user_agent: 'Fakturoid gem (email@testmail.cz)' }
117
+ end
118
+
119
+ assert_raises(Fakturoid::UnsupportedFeatureError) { Fakturoid::Response.new(test_connection.post('invoices/5/message.json', email: 'customer@email.cz'), Fakturoid::Client::Invoice, :post) }
120
+ end
121
+
122
+ should 'raise record not found error' do
123
+ test_connection = Faraday.new do |builder|
124
+ builder.adapter :test do |stub|
125
+ stub.get('invoices/10.json') { |_env| [404, { content_type: 'application/json' }, ' '] }
126
+ end
127
+ builder.headers = { content_type: 'application/json', user_agent: 'Fakturoid gem (email@testmail.cz)' }
128
+ end
129
+
130
+ assert_raises(Fakturoid::RecordNotFoundError) { Fakturoid::Response.new(test_connection.get('invoices/10.json'), Fakturoid::Client::Invoice, :get) }
131
+ end
132
+
133
+ should 'raise content type error' do
134
+ test_connection = Faraday.new do |builder|
135
+ builder.adapter :test do |stub|
136
+ stub.get('invoices/5.xml') { |_env| [415, { content_type: 'application/xml' }, ' '] }
137
+ end
138
+ builder.headers = { content_type: 'application/xml', user_agent: 'Fakturoid gem (email@testmail.cz)' }
139
+ end
140
+
141
+ assert_raises(Fakturoid::ContentTypeError) { Fakturoid::Response.new(test_connection.get('invoices/5.xml'), Fakturoid::Client::Invoice, :get) }
142
+ end
143
+
144
+ should 'raise invalid record error' do
145
+ json = load_fixture('invoice_error.json')
146
+ test_connection = Faraday.new do |builder|
147
+ builder.adapter :test do |stub|
148
+ stub.patch('invoice/5.json') { |_env| [422, { content_type: 'application/json' }, json] }
149
+ end
150
+ builder.headers = { content_type: 'application/json', user_agent: 'Fakturoid gem (email@testmail.cz)' }
151
+ end
152
+
153
+ begin
154
+ Fakturoid::Response.new(test_connection.patch('invoice/5.json'), Fakturoid::Client::Invoice, :patch)
155
+ rescue Fakturoid::InvalidRecordError => e
156
+ assert_equal 422, e.response_code
157
+ assert e.response_body.key?('errors')
158
+ rescue => e
159
+ assert false, "Raised exception was not expected: #{e.class}"
160
+ else
161
+ assert false, 'Exception was expected'
162
+ end
163
+ end
164
+
165
+ should 'raise rate limit error' do
166
+ test_connection = Faraday.new do |builder|
167
+ builder.adapter :test do |stub|
168
+ stub.get('invoices/5.json') { |_env| [429, { content_type: 'application/json' }, ' '] }
169
+ end
170
+ builder.headers = { content_type: 'application/json', user_agent: 'Fakturoid gem (email@testmail.cz)' }
171
+ end
172
+
173
+ assert_raises(Fakturoid::RateLimitError) { Fakturoid::Response.new(test_connection.get('invoices/5.json'), Fakturoid::Client::Invoice, :get) }
174
+ end
175
+
176
+ should 'raise read only site error' do
177
+ test_connection = Faraday.new do |builder|
178
+ builder.adapter :test do |stub|
179
+ stub.delete('invoices/5.json') { |_env| [503, { content_type: 'application/json' }, ' '] }
180
+ end
181
+ builder.headers = { content_type: 'application/json', user_agent: 'Fakturoid gem (email@testmail.cz)' }
182
+ end
183
+
184
+ assert_raises(Fakturoid::ReadOnlySiteError) { Fakturoid::Response.new(test_connection.delete('invoices/5.json'), Fakturoid::Client::Invoice, :delete) }
185
+ end
186
+ end
187
+ end
data/test/test_helper.rb CHANGED
@@ -14,4 +14,4 @@ module Fakturoid
14
14
  File.read(test_path.join('fixtures', file_name))
15
15
  end
16
16
  end
17
- end
17
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fakturoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eda Riedl
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-02-23 00:00:00.000000000 Z
12
+ date: 2015-09-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json
@@ -109,6 +109,20 @@ dependencies:
109
109
  - - ">="
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: rubocop
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
112
126
  description: Ruby client for web based invoicing service www.fakturoid.cz
113
127
  email:
114
128
  - podpora@fakturoid.cz
@@ -117,6 +131,7 @@ extensions: []
117
131
  extra_rdoc_files: []
118
132
  files:
119
133
  - ".gitignore"
134
+ - ".rubocop.yml"
120
135
  - ".ruby-version"
121
136
  - CHANGELOG.md
122
137
  - Gemfile
@@ -146,9 +161,13 @@ files:
146
161
  - lib/fakturoid/version.rb
147
162
  - test/api_test.rb
148
163
  - test/config_test.rb
164
+ - test/fixtures/blocked_account.json
149
165
  - test/fixtures/invoice.json
150
166
  - test/fixtures/invoice.pdf
167
+ - test/fixtures/invoice_error.json
168
+ - test/fixtures/subjects.json
151
169
  - test/request_test.rb
170
+ - test/response_test.rb
152
171
  - test/test_helper.rb
153
172
  homepage: https://github.com/fakturoid/fakturoid-ruby
154
173
  licenses:
@@ -170,14 +189,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
189
  version: '0'
171
190
  requirements: []
172
191
  rubyforge_project:
173
- rubygems_version: 2.4.5
192
+ rubygems_version: 2.4.8
174
193
  signing_key:
175
194
  specification_version: 4
176
195
  summary: Ruby client for web based invoicing service www.fakturoid.cz
177
196
  test_files:
178
197
  - test/api_test.rb
179
198
  - test/config_test.rb
199
+ - test/fixtures/blocked_account.json
180
200
  - test/fixtures/invoice.json
181
201
  - test/fixtures/invoice.pdf
202
+ - test/fixtures/invoice_error.json
203
+ - test/fixtures/subjects.json
182
204
  - test/request_test.rb
205
+ - test/response_test.rb
183
206
  - test/test_helper.rb