quaderno 1.13.2 → 1.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +56 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +4 -0
  5. data/Gemfile +2 -15
  6. data/README.md +120 -42
  7. data/Rakefile +4 -50
  8. data/changelog.md +67 -41
  9. data/lib/quaderno-ruby.rb +5 -5
  10. data/lib/quaderno-ruby/base.rb +112 -107
  11. data/lib/quaderno-ruby/behavior/block.rb +20 -19
  12. data/lib/quaderno-ruby/behavior/crud.rb +108 -95
  13. data/lib/quaderno-ruby/behavior/deliver.rb +20 -18
  14. data/lib/quaderno-ruby/behavior/payment.rb +38 -34
  15. data/lib/quaderno-ruby/behavior/retrieve.rb +26 -25
  16. data/lib/quaderno-ruby/checkout_session.rb +4 -0
  17. data/lib/quaderno-ruby/collection.rb +1 -0
  18. data/lib/quaderno-ruby/contact.rb +6 -8
  19. data/lib/quaderno-ruby/credit.rb +10 -12
  20. data/lib/quaderno-ruby/document_item.rb +1 -3
  21. data/lib/quaderno-ruby/estimate.rb +5 -7
  22. data/lib/quaderno-ruby/evidence.rb +5 -7
  23. data/lib/quaderno-ruby/exceptions/exceptions.rb +50 -44
  24. data/lib/quaderno-ruby/expense.rb +6 -8
  25. data/lib/quaderno-ruby/helpers/authentication.rb +16 -18
  26. data/lib/quaderno-ruby/helpers/rate_limit.rb +12 -0
  27. data/lib/quaderno-ruby/income.rb +8 -10
  28. data/lib/quaderno-ruby/invoice.rb +9 -11
  29. data/lib/quaderno-ruby/item.rb +3 -6
  30. data/lib/quaderno-ruby/payment.rb +2 -3
  31. data/lib/quaderno-ruby/receipt.rb +6 -8
  32. data/lib/quaderno-ruby/recurring.rb +4 -7
  33. data/lib/quaderno-ruby/report.rb +67 -29
  34. data/lib/quaderno-ruby/tax.rb +51 -46
  35. data/lib/quaderno-ruby/version.rb +3 -0
  36. data/lib/quaderno-ruby/webhook.rb +3 -5
  37. data/quaderno.gemspec +28 -148
  38. metadata +92 -92
  39. data/Gemfile.lock +0 -91
  40. data/VERSION +0 -1
  41. data/test/fixtures/quaderno_cassettes/.DS_Store +0 -0
  42. data/test/fixtures/quaderno_cassettes/all_contacts.yml +0 -52
  43. data/test/fixtures/quaderno_cassettes/all_contacts_by_access_token.yml +0 -56
  44. data/test/fixtures/quaderno_cassettes/all_contacts_by_authentication_token.yml +0 -57
  45. data/test/fixtures/quaderno_cassettes/all_estimates.yml +0 -52
  46. data/test/fixtures/quaderno_cassettes/all_expenses.yml +0 -55
  47. data/test/fixtures/quaderno_cassettes/all_invoices.yml +0 -56
  48. data/test/fixtures/quaderno_cassettes/all_items.yml +0 -46
  49. data/test/fixtures/quaderno_cassettes/all_receipts.yml +0 -53
  50. data/test/fixtures/quaderno_cassettes/all_webhooks.yml +0 -214
  51. data/test/fixtures/quaderno_cassettes/create_estimate_on_downgraded_API.yml +0 -156
  52. data/test/fixtures/quaderno_cassettes/create_expense_on_downgraded_API.yml +0 -278
  53. data/test/fixtures/quaderno_cassettes/create_invoice_on_downgraded_API.yml +0 -159
  54. data/test/fixtures/quaderno_cassettes/create_receipt_on_downgraded_API.yml +0 -196
  55. data/test/fixtures/quaderno_cassettes/deleted_contact.yml +0 -187
  56. data/test/fixtures/quaderno_cassettes/deleted_contact_by_access_token.yml +0 -199
  57. data/test/fixtures/quaderno_cassettes/deleted_contact_by_authentication_token.yml +0 -199
  58. data/test/fixtures/quaderno_cassettes/deleted_estimate.yml +0 -187
  59. data/test/fixtures/quaderno_cassettes/deleted_expense.yml +0 -189
  60. data/test/fixtures/quaderno_cassettes/deleted_invoice.yml +0 -190
  61. data/test/fixtures/quaderno_cassettes/deleted_item.yml +0 -128
  62. data/test/fixtures/quaderno_cassettes/deleted_receipt.yml +0 -223
  63. data/test/fixtures/quaderno_cassettes/deleted_webhook.yml +0 -257
  64. data/test/fixtures/quaderno_cassettes/delivered_estimate.yml +0 -136
  65. data/test/fixtures/quaderno_cassettes/delivered_invoice.yml +0 -143
  66. data/test/fixtures/quaderno_cassettes/delivered_receipt.yml +0 -140
  67. data/test/fixtures/quaderno_cassettes/evidence_invoice.yml +0 -98
  68. data/test/fixtures/quaderno_cassettes/found_contact.yml +0 -95
  69. data/test/fixtures/quaderno_cassettes/found_contact_by_access_token.yml +0 -99
  70. data/test/fixtures/quaderno_cassettes/found_contact_by_authentication_token.yml +0 -100
  71. data/test/fixtures/quaderno_cassettes/found_estimate.yml +0 -97
  72. data/test/fixtures/quaderno_cassettes/found_expense.yml +0 -99
  73. data/test/fixtures/quaderno_cassettes/found_invoice.yml +0 -100
  74. data/test/fixtures/quaderno_cassettes/found_item.yml +0 -91
  75. data/test/fixtures/quaderno_cassettes/found_receipt.yml +0 -98
  76. data/test/fixtures/quaderno_cassettes/found_webhook.yml +0 -130
  77. data/test/fixtures/quaderno_cassettes/new_contact.yml +0 -48
  78. data/test/fixtures/quaderno_cassettes/new_contact_by_access_token.yml +0 -48
  79. data/test/fixtures/quaderno_cassettes/new_contact_by_authentication_token.yml +0 -48
  80. data/test/fixtures/quaderno_cassettes/new_estimate.yml +0 -137
  81. data/test/fixtures/quaderno_cassettes/new_evidence.yml +0 -48
  82. data/test/fixtures/quaderno_cassettes/new_expense.yml +0 -189
  83. data/test/fixtures/quaderno_cassettes/new_invoice.yml +0 -137
  84. data/test/fixtures/quaderno_cassettes/new_item.yml +0 -48
  85. data/test/fixtures/quaderno_cassettes/new_receipt.yml +0 -173
  86. data/test/fixtures/quaderno_cassettes/new_webhook.yml +0 -87
  87. data/test/fixtures/quaderno_cassettes/paid_expense.yml +0 -98
  88. data/test/fixtures/quaderno_cassettes/paid_invoice.yml +0 -99
  89. data/test/fixtures/quaderno_cassettes/rate_limit.yml +0 -46
  90. data/test/fixtures/quaderno_cassettes/unpay_an_expense.yml +0 -138
  91. data/test/fixtures/quaderno_cassettes/unpay_an_invoice.yml +0 -138
  92. data/test/fixtures/quaderno_cassettes/updated_contact.yml +0 -97
  93. data/test/fixtures/quaderno_cassettes/updated_contact_by_access_token.yml +0 -101
  94. data/test/fixtures/quaderno_cassettes/updated_contact_by_authentication_token.yml +0 -102
  95. data/test/fixtures/quaderno_cassettes/updated_estimate.yml +0 -185
  96. data/test/fixtures/quaderno_cassettes/updated_expense.yml +0 -184
  97. data/test/fixtures/quaderno_cassettes/updated_invoice.yml +0 -184
  98. data/test/fixtures/quaderno_cassettes/updated_item.yml +0 -93
  99. data/test/fixtures/quaderno_cassettes/updated_receipt.yml +0 -220
  100. data/test/fixtures/quaderno_cassettes/updated_webhook.yml +0 -175
  101. data/test/fixtures/quaderno_cassettes/validate_invalid_VAT_number.yml +0 -44
  102. data/test/fixtures/quaderno_cassettes/validate_valid_VAT_number.yml +0 -44
  103. data/test/helper.rb +0 -32
  104. data/test/unit/test_quaderno_contacts.rb +0 -83
  105. data/test/unit/test_quaderno_contacts_thread_safe.rb +0 -104
  106. data/test/unit/test_quaderno_estimates.rb +0 -155
  107. data/test/unit/test_quaderno_evidences.rb +0 -41
  108. data/test/unit/test_quaderno_expenses.rb +0 -162
  109. data/test/unit/test_quaderno_invoices.rb +0 -177
  110. data/test/unit/test_quaderno_items.rb +0 -84
  111. data/test/unit/test_quaderno_receipts.rb +0 -156
  112. data/test/unit/test_quaderno_tax.rb +0 -46
  113. data/test/unit/test_quaderno_webhooks.rb +0 -93
data/Rakefile CHANGED
@@ -1,52 +1,6 @@
1
- # encoding: utf-8
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
2
3
 
3
- require 'rubygems'
4
- require 'bundler'
5
- begin
6
- Bundler.setup(:default, :development)
7
- rescue Bundler::BundlerError => e
8
- $stderr.puts e.message
9
- $stderr.puts "Run `bundle install` to install missing gems"
10
- exit e.status_code
11
- end
12
- require 'rake'
4
+ RSpec::Core::RakeTask.new(:spec)
13
5
 
14
- require 'jeweler'
15
- Jeweler::Tasks.new do |gem|
16
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
- gem.name = "quaderno"
18
- gem.homepage = "http://github.com/quaderno/quaderno-ruby"
19
- gem.license = "MIT"
20
- gem.summary = %Q{one-line summary of your gem}
21
- gem.description = %Q{ A ruby wrapper for Quaderno API }
22
- gem.email = "carlos@recrea.es"
23
- gem.authors = ["Recrea"]
24
- # dependencies defined in Gemfile
25
- end
26
- Jeweler::RubygemsDotOrgTasks.new
27
-
28
- require 'rake/testtask'
29
- Rake::TestTask.new(:test) do |test|
30
- test.libs << 'lib' << 'test'
31
- test.pattern = 'test/**/test_*.rb'
32
- test.verbose = true
33
- end
34
-
35
- desc "Code coverage detail"
36
- task :simplecov do
37
- ENV['COVERAGE'] = "true"
38
- Rake::Task['test'].execute
39
- end
40
-
41
-
42
- task :default => :test
43
-
44
- require 'rdoc/task'
45
- Rake::RDocTask.new do |rdoc|
46
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
-
48
- rdoc.rdoc_dir = 'rdoc'
49
- rdoc.title = "quaderno-ruby #{version}"
50
- rdoc.rdoc_files.include('README*')
51
- rdoc.rdoc_files.include('lib/**/*.rb')
52
- end
6
+ task :default => :spec
@@ -1,145 +1,171 @@
1
- #Changelog
2
- ##1.13.2
1
+ # Changelog
2
+
3
+ ## 1.17.0
4
+ * Added `rate_limit_info` method to each API response
5
+ * **Breaking change:** `.delete` methods no longer returns a boolean but an instance of the removed object with a `deleted` attribute set to `true`
6
+ * **Breaking change:** `Quaderno::Base.ping` no longer returns a boolean but a `Quaderno::Base` instance with a `status` attribute.
7
+ * **Breaking change:** `Quaderno::Base.authorization` no longer returns a `Hash` but a `Quaderno::Base` instance with an `identity` attribute.
8
+ * **Breaking change:** `Quaderno::Base.me` no longer returns a `Hash` but a `Quaderno::Base` instance with all the attributes contained in the previous format.
9
+ * **Breaking change:** `Quaderno::Tax.validate_vat_number` no longer returns a boolean but a `Quaderno::Tax` instance with a `valid` attribute.
10
+ * **Breaking change:** `.deliver` no longer returns a `Hash` but a `Quaderno::Base` instance with a `success` attribute.
11
+ * **Breaking change:** Removed `Quaderno::Base.rate_limit_info`. Now it's an alias of `Quaderno::Base.ping`.
12
+
13
+ ## 1.16.0
14
+ * Added `Quaderno::CheckoutSession`
15
+
16
+ ## 1.15.2
17
+ * Relax `httparty` version requirement.
18
+
19
+ ## 1.15.1
20
+ * Fix `Quaderno` load order.
21
+
22
+ ## 1.15.0
23
+ * Removed `jeweler` and updated the gem structure.
24
+
25
+ ## 1.14.0
26
+ * Added `domestic_taxes`, `sales_taxes`, `vat_moss`, `ec_sales` and `international_taxes` to `Quaderno::Report`
27
+
28
+ ## 1.13.2
3
29
  * Added index method to `Quaderno::Tax` as `Quaderno::Tax.all()`.
4
30
 
5
- ##1.13.1
31
+ ## 1.13.1
6
32
  * Added `taxes` report to `Quaderno::Report`.
7
33
 
8
- ##1.13.0
34
+ ## 1.13.0
9
35
  * Added `Quaderno::Report`.
10
36
 
11
- ##1.12.5
37
+ ## 1.12.5
12
38
  * Added `create` method to `Quaderno::Income`.
13
39
  * Fix `Quaderno::Base.ping` and `Quaderno::Base.me` methods.
14
40
 
15
- ##1.12.4
41
+ ## 1.12.4
16
42
  * Use version headers on taxes requests.
17
43
 
18
- ##1.12.3
44
+ ## 1.12.3
19
45
  * Return integers insteado of strings on pagination readers.
20
46
 
21
- ##1.12.2
47
+ ## 1.12.2
22
48
  * Added `me` method.
23
49
 
24
- ##1.12.0
50
+ ## 1.12.0
25
51
  * Added thread-safe credentials configuration.
26
52
  * `all` methods returns a `Quaderno::Object` with pagination info instead of an `Array`
27
53
 
28
- ##1.11.2
54
+ ## 1.11.2
29
55
  * Specify `Content-Type` header so `HTTParty` don't merge the elements within the body content.
30
56
 
31
- ##1.11.1
57
+ ## 1.11.1
32
58
  * Added `retrieve` method for `Quaderno::Contact`, `Quaderno::Invoice`, `Quaderno::Credit`
33
59
  * Deprecate `retrieve_customer` as an alias of `retrieve`
34
60
 
35
- ##1.11.0
61
+ ## 1.11.0
36
62
  * Added `Quaderno::Tax.validate_vat_number` method
37
63
 
38
- ##1.10.0
64
+ ## 1.10.0
39
65
  * Added location evidences support
40
66
 
41
- ##1.9.2
67
+ ## 1.9.2
42
68
  * Added `Quaderno::Contact.retrieve` method
43
69
  * Code cleanup
44
70
  * Update tests
45
71
 
46
- ##1.9.1
72
+ ## 1.9.1
47
73
  * `Quaderno::Base.authorization` raises `Quaderno::Exceptions::InvalidSubdomainOrToken` instead returning false on wrong credentials
48
74
  * Inherit from `StandardError` instead of `Exception` for `Quaderno::Exceptions` by **@mvelikov**
49
75
 
50
- ##1.9.0
76
+ ## 1.9.0
51
77
  * Add support for new versioning system
52
78
 
53
- ##1.8.0
79
+ ## 1.8.0
54
80
  * Add Quaderno::Receipt support
55
81
  * Fix errors in README
56
82
 
57
- ##1.7.3
83
+ ## 1.7.3
58
84
  * Raise exception on failed updates
59
85
 
60
- ##1.7.2
61
- * Fix URL in `Quaderno::Tax.calculate` by [**@jcxplorer**] (https://github.com/jcxplorer)
86
+ ## 1.7.2
87
+ * Fix URL in `Quaderno::Tax.calculate` by [**@jcxplorer**](https://github.com/jcxplorer)
62
88
 
63
- ##1.7.1
89
+ ## 1.7.1
64
90
  * Breaking change: change configuration options
65
91
 
66
- ##1.7.0
92
+ ## 1.7.0
67
93
  * Added recurring documents
68
94
  * Raise existent exception
69
95
 
70
- ##1.6.1
96
+ ## 1.6.1
71
97
  * Fixed typo from old version released as 1.6.0
72
98
 
73
- ##1.6.0 (yanked)
99
+ ## 1.6.0 (yanked)
74
100
  * Crud module refactor
75
101
  * Added support for credit notes
76
102
 
77
- ##1.5.5
103
+ ## 1.5.5
78
104
  * Move rdoc as a development dependency
79
105
 
80
- ##1.5.4
106
+ ## 1.5.4
81
107
  * Remove transaction class.
82
108
 
83
- ##1.5.3
109
+ ## 1.5.3
84
110
  * Update `rate_limit_info` to fit the new rate limit
85
111
  * Remove transaction information from README (future resource name change)
86
112
  * Added new throttle limit exception (will be activated in future releases)
87
113
 
88
- ##1.5.1 and 1.5.2
114
+ ## 1.5.1 and 1.5.2
89
115
  * Remove debugger
90
116
  * `Quaderno::Exceptions::RequiredFieldsEmpty` replaced with `Quaderno::Exceptions::RequiredFieldsEmptyOrInvalid`
91
117
 
92
- ##1.5.0
118
+ ## 1.5.0
93
119
  * Added transactions
94
120
  * Raise `Quaderno::Exceptions::RequiredFieldsEmpty` for 422 responses
95
121
 
96
- ##1.4.2
122
+ ## 1.4.2
97
123
  * Find method hotfix
98
124
 
99
- ##1.4.1
125
+ ## 1.4.1
100
126
  * Fix wrong method name
101
127
  * Use correct organization in url
102
128
  * Add short description of the gem
103
129
 
104
- ##1.4.0
130
+ ## 1.4.0
105
131
  * Added taxes calculations support
106
132
  * Added webhooks documentation
107
133
 
108
- ##1.3.2
134
+ ## 1.3.2
109
135
 
110
136
  * Use new urls format
111
137
 
112
- ##1.3.1
138
+ ## 1.3.1
113
139
 
114
140
  * Added sandbox environment
115
141
  * Added `to_hash` instance method
116
142
 
117
- ##1.3.0
143
+ ## 1.3.0
118
144
 
119
145
  * Removed debug mode
120
146
 
121
- ##1.2.2
147
+ ## 1.2.2
122
148
 
123
149
  * Added ruby 2.0.0 compatibility
124
150
 
125
- ##1.2.1
151
+ ## 1.2.1
126
152
 
127
153
  * Deleted debugger dependency
128
154
 
129
- ##1.2.0
155
+ ## 1.2.0
130
156
 
131
157
  * Added Quaderno webhooks as a resource
132
158
  * Added authorization method
133
159
 
134
- ##1.1.2
160
+ ## 1.1.2
135
161
 
136
162
  * Fixed minor bugs
137
163
 
138
- ##1.1.0
164
+ ## 1.1.0
139
165
 
140
166
  * Added Quaderno items as a resource
141
167
  * Added filter in index queries
142
168
 
143
- ##1.0.0
169
+ ## 1.0.0
144
170
 
145
171
  * Initial release
@@ -1,12 +1,12 @@
1
+ class Quaderno
2
+ end
3
+
1
4
  require 'ostruct'
2
5
 
6
+ require 'quaderno-ruby/helpers/rate_limit'
3
7
  require 'quaderno-ruby/exceptions/exceptions'
4
8
  require 'quaderno-ruby/helpers/authentication'
5
9
  require 'quaderno-ruby/collection'
6
10
 
7
11
  %w(block crud deliver payment retrieve).each { |filename| require "quaderno-ruby/behavior/#{filename}" }
8
- %w(base contact item invoice receipt credit income estimate expense recurring document_item report evidence payment webhook tax).each { |filename| require "quaderno-ruby/#{ filename }" }
9
-
10
- module Quaderno
11
-
12
- end
12
+ %w(base contact item invoice receipt credit income estimate expense recurring document_item report evidence payment webhook tax checkout_session).each { |filename| require "quaderno-ruby/#{ filename }" }
@@ -1,136 +1,141 @@
1
- module Quaderno
2
- require 'httparty'
3
- require 'json'
4
-
5
- class Base < OpenStruct
6
- include HTTParty
7
- include Quaderno::Exceptions
8
- include Quaderno::Behavior::Crud
9
- include Quaderno::Helpers::Authentication
10
-
11
- PRODUCTION_URL = 'https://quadernoapp.com/api/'
12
- SANDBOX_URL = 'http://sandbox-quadernoapp.com/api/'
13
-
14
- @@auth_token = nil
15
- @@rate_limit_info = nil
16
- @@api_version = nil
17
- @@url = PRODUCTION_URL
18
-
19
- # Class methods
20
- def self.api_model(klass)
21
- instance_eval <<-END
22
- def api_model
23
- #{klass}
24
- end
25
- END
26
- class_eval <<-END
27
- def api_model
28
- #{klass}
29
- end
30
- END
31
- end
32
-
33
- def self.configure
34
- yield self
35
- end
36
-
37
- def self.api_version=(api_version)
38
- @@api_version = api_version
39
- end
40
-
41
- def self.auth_token=(auth_token)
42
- @@auth_token = auth_token
43
- end
1
+ require 'httparty'
2
+ require 'json'
3
+
4
+ class Quaderno::Base < OpenStruct
5
+ include HTTParty
6
+ include Quaderno::Exceptions
7
+ include Quaderno::Behavior::Crud
8
+ include Quaderno::Helpers::Authentication
9
+ include Quaderno::Helpers::RateLimit
10
+
11
+ PRODUCTION_URL = 'https://quadernoapp.com/api/'
12
+ SANDBOX_URL = 'http://sandbox-quadernoapp.com/api/'
13
+
14
+ @@auth_token = nil
15
+ @@rate_limit_info = nil
16
+ @@api_version = nil
17
+ @@url = PRODUCTION_URL
18
+
19
+ # Class methods
20
+ def self.api_model(klass)
21
+ instance_eval <<-END
22
+ def api_model
23
+ #{klass}
24
+ end
25
+ END
26
+ class_eval <<-END
27
+ def api_model
28
+ #{klass}
29
+ end
30
+ END
31
+ end
44
32
 
45
- def self.url=(url)
46
- @@url = url
47
- end
33
+ def self.configure
34
+ yield self
35
+ end
48
36
 
49
- def self.authorization(auth_token, mode = nil)
50
- mode ||= :production
51
- url = mode == :sandbox ? SANDBOX_URL : PRODUCTION_URL
52
- response = get("#{url}authorization.json", basic_auth: { username: auth_token }, headers: version_header)
37
+ def self.api_version=(api_version)
38
+ @@api_version = api_version
39
+ end
53
40
 
54
- if response.code == 200
55
- response.parsed_response
56
- else
57
- raise(Quaderno::Exceptions::InvalidSubdomainOrToken, 'Invalid subdomain or token')
58
- end
59
- end
41
+ def self.auth_token=(auth_token)
42
+ @@auth_token = auth_token
43
+ end
60
44
 
61
- #Check the connection
62
- def self.ping(options = {})
63
- begin
64
- options[:auth_token] ||= auth_token
65
- options[:api_url] ||= url
45
+ def self.url=(url)
46
+ @@url = url
47
+ end
66
48
 
67
- authentication = get_authentication(options)
49
+ def self.authorization(auth_token, mode = nil)
50
+ mode ||= :production
51
+ url = mode == :sandbox ? SANDBOX_URL : PRODUCTION_URL
52
+ response = get("#{url}authorization.json", basic_auth: { username: auth_token }, headers: version_header)
68
53
 
69
- party_response = get("#{authentication[:url]}ping.json",
70
- basic_auth: authentication[:basic_auth],
71
- headers: version_header.merge(authentication[:headers])
72
- )
54
+ if response.code == 200
55
+ data = self.new(response.parsed_response)
56
+ data.rate_limit_info = response
73
57
 
74
- check_exception_for(party_response, { subdomain_or_token: true })
75
- rescue Errno::ECONNREFUSED
76
- return false
77
- end
78
- true
58
+ data
59
+ else
60
+ raise_exception(Quaderno::Exceptions::InvalidSubdomainOrToken, 'Invalid subdomain or token', response)
79
61
  end
62
+ end
80
63
 
81
- def self.me(options = {})
64
+ #Check the connection
65
+ def self.ping(options = {})
66
+ begin
82
67
  options[:auth_token] ||= auth_token
83
68
  options[:api_url] ||= url
84
69
 
85
70
  authentication = get_authentication(options)
86
71
 
87
- party_response = get("#{authentication[:url]}me.json",
72
+ party_response = get("#{authentication[:url]}ping.json",
88
73
  basic_auth: authentication[:basic_auth],
89
74
  headers: version_header.merge(authentication[:headers])
90
75
  )
91
76
 
92
77
  check_exception_for(party_response, { subdomain_or_token: true })
93
-
94
- party_response.parsed_response
78
+ rescue Errno::ECONNREFUSED
79
+ return Quaderno::Base.new({ status: false })
95
80
  end
96
81
 
97
- #Returns the rate limit information: limit and remaining requests
98
- def self.rate_limit_info
99
- party_response = get("#{@@url}ping.json", basic_auth: { username: auth_token }, headers: version_header)
100
- check_exception_for(party_response, { subdomain_or_token: true })
101
- @@rate_limit_info = { reset: party_response.headers['x-ratelimit-reset'].to_i, remaining: party_response.headers["x-ratelimit-remaining"].to_i }
102
- end
82
+ data = self.new({ status: true })
83
+ data.rate_limit_info = party_response
103
84
 
104
- # Instance methods
105
- def to_hash
106
- self.marshal_dump
107
- end
85
+ data
86
+ end
87
+ class <<self
88
+ alias_method :rate_limit_info, :ping
89
+ end
108
90
 
109
- private
110
- # Class methods
111
- def self.auth_token
112
- @@auth_token
113
- end
91
+ def self.me(options = {})
92
+ options[:auth_token] ||= auth_token
93
+ options[:api_url] ||= url
114
94
 
115
- def self.url
116
- @@url
117
- end
95
+ authentication = get_authentication(options)
118
96
 
119
- def self.subdomain
120
- @_subdomain = @@subdomain
121
- end
97
+ party_response = get("#{authentication[:url]}me.json",
98
+ basic_auth: authentication[:basic_auth],
99
+ headers: version_header.merge(authentication[:headers])
100
+ )
122
101
 
123
- #Set or returns the model path for the url
124
- def self.api_path(api_path = nil)
125
- @_api_path ||= api_path
126
- end
102
+ check_exception_for(party_response, { subdomain_or_token: true })
127
103
 
128
- def self.is_a_document?(document = nil)
129
- @_document ||= document
130
- end
104
+ data = self.new(party_response.parsed_response)
105
+ data.rate_limit_info = party_response
131
106
 
132
- def self.version_header
133
- { 'Accept' => @@api_version.to_i.zero? ? "application/json" : "application/json; api_version=#{@@api_version.to_i}"}
134
- end
107
+ data
108
+ end
109
+
110
+ # Instance methods
111
+ def to_hash
112
+ self.marshal_dump
113
+ end
114
+
115
+ private
116
+ # Class methods
117
+ def self.auth_token
118
+ @@auth_token
119
+ end
120
+
121
+ def self.url
122
+ @@url
123
+ end
124
+
125
+ def self.subdomain
126
+ @_subdomain = @@subdomain
127
+ end
128
+
129
+ #Set or returns the model path for the url
130
+ def self.api_path(api_path = nil)
131
+ @_api_path ||= api_path
132
+ end
133
+
134
+ def self.is_a_document?(document = nil)
135
+ @_document ||= document
136
+ end
137
+
138
+ def self.version_header
139
+ { 'Accept' => @@api_version.to_i.zero? ? "application/json" : "application/json; api_version=#{@@api_version.to_i}"}
135
140
  end
136
- end
141
+ end