quaderno 1.8.0 → 1.9.0

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: 423898afe9290b9d5a056ed17c7e0ec2cb50e777
4
- data.tar.gz: 7617314a3d1c18d9db47729030b8232f4de2011b
3
+ metadata.gz: c8752ad69dde9702c70fe935dc295170dbbbedb5
4
+ data.tar.gz: 44ab70967522966a4deb25b632d3e2e78b256029
5
5
  SHA512:
6
- metadata.gz: ed38c65f4f96f9999c85b0b19f9fa9c31ae59db0c3ea2420600acab0f48e4f4a20434fa5a7ac86384ffb612dc4d3f774bbf8d034beb6fad96a82dc561fa25136
7
- data.tar.gz: 1a9c6a1d1b737c3304bc7a5dbffab9d51c0ff74f8ddc7df571e8ae405566be39c40effdf9798a34279dd6b841c68a0a58926f4855ada5dec8dc2099ce89ea7ab
6
+ metadata.gz: 99ffeb8d24d6cd028cbe6eae2aa535ee9f0fcf6222ba726faecc61bc3fe9d45ea07752f6c128d6f55523a0aeae9cdce701aeed5d3c892e8983e62b6f526027b5
7
+ data.tar.gz: d7bbdea3bf038efd83f31b1f38d844c00104f5d83c40a22fb7f7a4f138fe68a724ee4ffe09df2b6a981c6967572adad063fe84d2e0f934b67154cc534bcb249b
data/README.md CHANGED
@@ -18,7 +18,8 @@ To configure just add this to your initializers
18
18
  ```ruby
19
19
  Quaderno::Base.configure do |config|
20
20
  config.auth_token = 'my_authenticate_token'
21
- config.url = 'https://my_subdomain.quadernoapp.com/api/v1/'
21
+ config.url = 'https://my_subdomain.quadernoapp.com/api/'
22
+ config.api_version = API_VERSION # Optional, defaults to the API version set in your account
22
23
  end
23
24
  ```
24
25
 
@@ -30,7 +31,7 @@ You can get your account subdomain by grabbing it from your account url or by ca
30
31
 
31
32
  ```ruby
32
33
  Quaderno::Base.authorization 'my_authenticate_token', environment
33
- # => {"identity"=>{"id"=>737000, "name"=>"Walter White", "email"=>"cooking@br.bd", "href"=>"https://my_subdomain.quadernoapp.com/api/v1/"}}
34
+ # => {"identity"=>{"id"=>737000, "name"=>"Walter White", "email"=>"cooking@br.bd", "href"=>"https://my_subdomain.quadernoapp.com/api/"}}
34
35
  ```
35
36
 
36
37
  `environment` is an optional argument. By passing `:sandbox`, you will retrieve your credentials for the sandbox environment and not for production.
@@ -530,10 +531,18 @@ will calculate the taxes applied for a customer based on the data pased as param
530
531
  Quaderno-ruby exceptions raise depending on the type of error:
531
532
 
532
533
  ```ruby
534
+ Quaderno::Exceptions::UnsupportedApiVersion # Raised when the API version set is not supported.
535
+
533
536
  Quaderno::Exceptions::InvalidSubdomainOrToken # Raised when the credentials are wrong, missing or do not match the permission for some object.
534
537
 
538
+ Quaderno::Exceptions::InvalidID # Raised when the requested resource by ID does not exist in the account context.
539
+
540
+ Quaderno::Exceptions::ThrottleLimitExceeded # Raised when the throttle limit is exceeded.
541
+
535
542
  Quaderno::Exceptions::RateLimitExceeded # Raised when the rate limit is exceeded.
536
543
 
544
+ Quaderno::Exceptions::HasAssociatedDocuments # Raised when trying to delete a contact with associated documents.
545
+
537
546
  Quaderno::Exceptions::RequiredFieldsEmptyOrInvalid # Raised if the format of the request is right but some validations failed. You can JSON parse the exception message to get which field triggered the exception. For example: '{"errors":{"vat_number":["is not a valid German vat number"]}}'
538
547
 
539
548
  ```
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.8.0
1
+ 1.9.0
data/changelog.md CHANGED
@@ -1,5 +1,8 @@
1
1
  #Changelog
2
2
 
3
+ ##1.9.0
4
+ * Add support for new versioning system
5
+
3
6
  ##1.8.0
4
7
  * Add Quaderno::Receipt support
5
8
  * Fix errors in README
@@ -7,11 +7,12 @@ module Quaderno
7
7
  include Quaderno::Exceptions
8
8
  include Quaderno::Behavior::Crud
9
9
 
10
- PRODUCTION_URL = 'https://quadernoapp.com/api/v1/'
11
- SANDBOX_URL = 'http://sandbox-quadernoapp.com/api/v1/'
10
+ PRODUCTION_URL = 'https://quadernoapp.com/api/'
11
+ SANDBOX_URL = 'http://sandbox-quadernoapp.com/api/'
12
12
 
13
13
  @@auth_token = nil
14
14
  @@rate_limit_info = nil
15
+ @@api_version = nil
15
16
  @@url = PRODUCTION_URL
16
17
 
17
18
  # Class methods
@@ -32,6 +33,10 @@ module Quaderno
32
33
  yield self
33
34
  end
34
35
 
36
+ def self.api_version=(api_version)
37
+ @@api_version = api_version
38
+ end
39
+
35
40
  def self.auth_token=(auth_token)
36
41
  @@auth_token = auth_token
37
42
  end
@@ -44,7 +49,7 @@ module Quaderno
44
49
  begin
45
50
  mode ||= :production
46
51
  url = mode == :sandbox ? SANDBOX_URL : PRODUCTION_URL
47
- party_response = get("#{url}authorization.json", basic_auth: { username: auth_token })
52
+ party_response = get("#{url}authorization.json", basic_auth: { username: auth_token }, headers: version_header)
48
53
  return JSON::parse party_response.body
49
54
  rescue Exception
50
55
  return false
@@ -54,7 +59,7 @@ module Quaderno
54
59
  #Check the connection
55
60
  def self.ping
56
61
  begin
57
- party_response = get("#{@@url}ping.json", basic_auth: { username: auth_token })
62
+ party_response = get("#{@@url}ping.json", basic_auth: { username: auth_token }, headers: version_header)
58
63
  check_exception_for(party_response, { subdomain_or_token: true })
59
64
  rescue Errno::ECONNREFUSED
60
65
  return false
@@ -64,7 +69,7 @@ module Quaderno
64
69
 
65
70
  #Returns the rate limit information: limit and remaining requests
66
71
  def self.rate_limit_info
67
- party_response = get("#{@@url}ping.json", basic_auth: { username: auth_token })
72
+ party_response = get("#{@@url}ping.json", basic_auth: { username: auth_token }, headers: version_header)
68
73
  check_exception_for(party_response, { subdomain_or_token: true })
69
74
  @@rate_limit_info = { reset: party_response.headers['x-ratelimit-reset'].to_i, remaining: party_response.headers["x-ratelimit-remaining"].to_i }
70
75
  end
@@ -75,6 +80,7 @@ module Quaderno
75
80
  end
76
81
 
77
82
  private
83
+ # Class methods
78
84
  def self.auth_token
79
85
  @@auth_token
80
86
  end
@@ -95,5 +101,9 @@ module Quaderno
95
101
  def self.is_a_document?(document = nil)
96
102
  @_document ||= document
97
103
  end
104
+
105
+ def self.version_header
106
+ { 'Accept' => @@api_version.to_i.zero? ? "application/json" : "application/json; api_version=#{@@api_version.to_i}"}
107
+ end
98
108
  end
99
109
  end
@@ -29,7 +29,7 @@ module Quaderno
29
29
  end
30
30
 
31
31
  def all(filter = nil)
32
- party_response = get("#{api_model.url}#{ api_model.api_path }.json", body: filter, basic_auth: { username: api_model.auth_token })
32
+ party_response = get("#{api_model.url}#{ api_model.api_path }.json", body: filter, basic_auth: { username: api_model.auth_token }, headers: version_header)
33
33
  check_exception_for(party_response, { rate_limit: true, subdomain_or_token: true })
34
34
  array = party_response.parsed_response
35
35
  collection = []
@@ -47,7 +47,7 @@ module Quaderno
47
47
  end
48
48
 
49
49
  def find(id)
50
- party_response = get "#{api_model.url}#{ api_model.api_path }/#{ id }.json", basic_auth: { username: api_model.auth_token }
50
+ party_response = get "#{api_model.url}#{ api_model.api_path }/#{ id }.json", basic_auth: { username: api_model.auth_token }, headers: version_header
51
51
  check_exception_for(party_response, { rate_limit: true, subdomain_or_token: true, id: true })
52
52
  hash = party_response.parsed_response
53
53
 
@@ -57,7 +57,7 @@ module Quaderno
57
57
  end
58
58
 
59
59
  def create(params)
60
- party_response = post "#{api_model.url}#{ api_model.api_path }.json", body: params, basic_auth: { username: api_model.auth_token }
60
+ party_response = post "#{api_model.url}#{ api_model.api_path }.json", body: params, basic_auth: { username: api_model.auth_token }, headers: version_header
61
61
  check_exception_for(party_response, { rate_limit: true, subdomain_or_token: true, required_fields: true })
62
62
  hash = party_response.parsed_response
63
63
 
@@ -67,7 +67,7 @@ module Quaderno
67
67
  end
68
68
 
69
69
  def update(id, params)
70
- party_response = put "#{api_model.url}#{ api_model.api_path }/#{ id }.json", body: params, basic_auth: { username: api_model.auth_token }
70
+ party_response = put "#{api_model.url}#{ api_model.api_path }/#{ id }.json", body: params, basic_auth: { username: api_model.auth_token }, headers: version_header
71
71
  check_exception_for(party_response, { rate_limit: true, required_fields: true, subdomain_or_token: true, id: true })
72
72
  hash = party_response.parsed_response
73
73
 
@@ -77,7 +77,7 @@ module Quaderno
77
77
  end
78
78
 
79
79
  def delete(id)
80
- party_response = HTTParty.delete "#{api_model.url}#{ api_model.api_path }/#{ id }.json", basic_auth: { username: api_model.auth_token }
80
+ party_response = HTTParty.delete "#{api_model.url}#{ api_model.api_path }/#{ id }.json", basic_auth: { username: api_model.auth_token }, headers: version_header
81
81
  check_exception_for(party_response, { rate_limit: true, subdomain_or_token: true, id: true, has_documents: true })
82
82
  true
83
83
  end
@@ -8,7 +8,7 @@ module Quaderno
8
8
 
9
9
  module InstanceMethods
10
10
  def deliver
11
- party_response = api_model.get("#{api_model.url}#{ api_model.api_path }/#{ id }/deliver.json", basic_auth: { username: api_model.auth_token })
11
+ party_response = api_model.get("#{api_model.url}#{ api_model.api_path }/#{ id }/deliver.json", basic_auth: { username: api_model.auth_token }, headers: self.class.version_header)
12
12
  api_model.check_exception_for(party_response, { rate_limit: true, subdomain_or_token: true, id: true, required_fields: true })
13
13
  { limit: party_response.headers["x-ratelimit-limit"].to_i, remaining: party_response.headers["x-ratelimit-remaining"].to_i }
14
14
  end
@@ -11,7 +11,7 @@ module Quaderno
11
11
  end
12
12
 
13
13
  def add_payment(params)
14
- party_response = api_model.post "#{api_model.url}#{ api_model.api_path }/#{ id }/payments.json", body: params, basic_auth: { username: api_model.auth_token }
14
+ party_response = api_model.post "#{api_model.url}#{ api_model.api_path }/#{ id }/payments.json", body: params, basic_auth: { username: api_model.auth_token }, headers: self.class.version_header
15
15
  api_model.check_exception_for(party_response, { rate_limit: true, subdomain_or_token: true, required_fields: true })
16
16
  parsed = JSON::parse party_response.body
17
17
  instance = to_instance(Quaderno::Payment, parsed)
@@ -20,7 +20,7 @@ module Quaderno
20
20
  end
21
21
 
22
22
  def remove_payment(payment_id)
23
- party_response = HTTParty.delete "#{api_model.url}#{ api_model.api_path }/#{ id }/payments/#{ payment_id }.json", basic_auth: { username: api_model.auth_token }
23
+ party_response = HTTParty.delete "#{api_model.url}#{ api_model.api_path }/#{ id }/payments/#{ payment_id }.json", basic_auth: { username: api_model.auth_token }, headers: self.class.version_header
24
24
  to_delete = nil
25
25
  payments.each do |payment|
26
26
  if payment.id == payment_id
@@ -18,12 +18,17 @@ module Quaderno
18
18
  class ThrottleLimitExceeded < Exception
19
19
  end
20
20
 
21
+ class UnsupportedApiVersion < Exception
22
+ end
23
+
21
24
  def self.included(receiver)
22
25
  receiver.send :extend, ClassMethods
23
- end
26
+ end
24
27
 
25
28
  module ClassMethods
26
29
  def check_exception_for(party_response, params = {})
30
+ raise(Quaderno::Exceptions::UnsupportedApiVersion, 'Unsupported API version') if !!(party_response.body =~ /Unsupported API version/)
31
+
27
32
  if params[:throttle_limit].nil? == false
28
33
  raise(Quaderno::Exceptions::ThrottleLimitExceeded, 'Throttle limit exceeded, please try again later') if party_response.response.class == Net::HTTPServiceUnavailable
29
34
  end
data/quaderno.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: quaderno 1.8.0 ruby lib
5
+ # stub: quaderno 1.9.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "quaderno"
9
- s.version = "1.8.0"
9
+ s.version = "1.9.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Recrea"]
14
- s.date = "2016-05-09"
14
+ s.date = "2016-06-17"
15
15
  s.description = " A ruby wrapper for Quaderno API "
16
16
  s.email = "carlos@recrea.es"
17
17
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quaderno
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Recrea
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-09 00:00:00.000000000 Z
11
+ date: 2016-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty