quaderno 1.14.0 → 1.15.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +56 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +2 -15
- data/README.md +1 -1
- data/Rakefile +4 -50
- data/changelog.md +9 -0
- data/lib/quaderno-ruby.rb +3 -4
- data/lib/quaderno-ruby/base.rb +106 -108
- data/lib/quaderno-ruby/behavior/block.rb +17 -19
- data/lib/quaderno-ruby/behavior/crud.rb +93 -95
- data/lib/quaderno-ruby/behavior/deliver.rb +16 -18
- data/lib/quaderno-ruby/behavior/payment.rb +32 -34
- data/lib/quaderno-ruby/behavior/retrieve.rb +23 -25
- data/lib/quaderno-ruby/contact.rb +6 -8
- data/lib/quaderno-ruby/credit.rb +10 -12
- data/lib/quaderno-ruby/document_item.rb +1 -3
- data/lib/quaderno-ruby/estimate.rb +5 -7
- data/lib/quaderno-ruby/evidence.rb +5 -7
- data/lib/quaderno-ruby/exceptions/exceptions.rb +42 -44
- data/lib/quaderno-ruby/expense.rb +6 -8
- data/lib/quaderno-ruby/helpers/authentication.rb +16 -18
- data/lib/quaderno-ruby/income.rb +8 -10
- data/lib/quaderno-ruby/invoice.rb +9 -11
- data/lib/quaderno-ruby/item.rb +3 -6
- data/lib/quaderno-ruby/payment.rb +1 -3
- data/lib/quaderno-ruby/receipt.rb +6 -8
- data/lib/quaderno-ruby/recurring.rb +4 -7
- data/lib/quaderno-ruby/report.rb +56 -58
- data/lib/quaderno-ruby/tax.rb +45 -47
- data/lib/quaderno-ruby/version.rb +3 -0
- data/lib/quaderno-ruby/webhook.rb +3 -5
- data/quaderno.gemspec +28 -148
- metadata +83 -84
- data/Gemfile.lock +0 -91
- data/VERSION +0 -1
- data/test/fixtures/quaderno_cassettes/.DS_Store +0 -0
- data/test/fixtures/quaderno_cassettes/all_contacts.yml +0 -52
- data/test/fixtures/quaderno_cassettes/all_contacts_by_access_token.yml +0 -56
- data/test/fixtures/quaderno_cassettes/all_contacts_by_authentication_token.yml +0 -57
- data/test/fixtures/quaderno_cassettes/all_estimates.yml +0 -52
- data/test/fixtures/quaderno_cassettes/all_expenses.yml +0 -55
- data/test/fixtures/quaderno_cassettes/all_invoices.yml +0 -56
- data/test/fixtures/quaderno_cassettes/all_items.yml +0 -46
- data/test/fixtures/quaderno_cassettes/all_receipts.yml +0 -53
- data/test/fixtures/quaderno_cassettes/all_webhooks.yml +0 -214
- data/test/fixtures/quaderno_cassettes/create_estimate_on_downgraded_API.yml +0 -156
- data/test/fixtures/quaderno_cassettes/create_expense_on_downgraded_API.yml +0 -278
- data/test/fixtures/quaderno_cassettes/create_invoice_on_downgraded_API.yml +0 -159
- data/test/fixtures/quaderno_cassettes/create_receipt_on_downgraded_API.yml +0 -196
- data/test/fixtures/quaderno_cassettes/deleted_contact.yml +0 -187
- data/test/fixtures/quaderno_cassettes/deleted_contact_by_access_token.yml +0 -199
- data/test/fixtures/quaderno_cassettes/deleted_contact_by_authentication_token.yml +0 -199
- data/test/fixtures/quaderno_cassettes/deleted_estimate.yml +0 -187
- data/test/fixtures/quaderno_cassettes/deleted_expense.yml +0 -189
- data/test/fixtures/quaderno_cassettes/deleted_invoice.yml +0 -190
- data/test/fixtures/quaderno_cassettes/deleted_item.yml +0 -128
- data/test/fixtures/quaderno_cassettes/deleted_receipt.yml +0 -223
- data/test/fixtures/quaderno_cassettes/deleted_webhook.yml +0 -257
- data/test/fixtures/quaderno_cassettes/delivered_estimate.yml +0 -136
- data/test/fixtures/quaderno_cassettes/delivered_invoice.yml +0 -143
- data/test/fixtures/quaderno_cassettes/delivered_receipt.yml +0 -140
- data/test/fixtures/quaderno_cassettes/evidence_invoice.yml +0 -98
- data/test/fixtures/quaderno_cassettes/found_contact.yml +0 -95
- data/test/fixtures/quaderno_cassettes/found_contact_by_access_token.yml +0 -99
- data/test/fixtures/quaderno_cassettes/found_contact_by_authentication_token.yml +0 -100
- data/test/fixtures/quaderno_cassettes/found_estimate.yml +0 -97
- data/test/fixtures/quaderno_cassettes/found_expense.yml +0 -99
- data/test/fixtures/quaderno_cassettes/found_invoice.yml +0 -100
- data/test/fixtures/quaderno_cassettes/found_item.yml +0 -91
- data/test/fixtures/quaderno_cassettes/found_receipt.yml +0 -98
- data/test/fixtures/quaderno_cassettes/found_webhook.yml +0 -130
- data/test/fixtures/quaderno_cassettes/new_contact.yml +0 -48
- data/test/fixtures/quaderno_cassettes/new_contact_by_access_token.yml +0 -48
- data/test/fixtures/quaderno_cassettes/new_contact_by_authentication_token.yml +0 -48
- data/test/fixtures/quaderno_cassettes/new_estimate.yml +0 -137
- data/test/fixtures/quaderno_cassettes/new_evidence.yml +0 -48
- data/test/fixtures/quaderno_cassettes/new_expense.yml +0 -189
- data/test/fixtures/quaderno_cassettes/new_invoice.yml +0 -137
- data/test/fixtures/quaderno_cassettes/new_item.yml +0 -48
- data/test/fixtures/quaderno_cassettes/new_receipt.yml +0 -173
- data/test/fixtures/quaderno_cassettes/new_webhook.yml +0 -87
- data/test/fixtures/quaderno_cassettes/paid_expense.yml +0 -98
- data/test/fixtures/quaderno_cassettes/paid_invoice.yml +0 -99
- data/test/fixtures/quaderno_cassettes/rate_limit.yml +0 -46
- data/test/fixtures/quaderno_cassettes/unpay_an_expense.yml +0 -138
- data/test/fixtures/quaderno_cassettes/unpay_an_invoice.yml +0 -138
- data/test/fixtures/quaderno_cassettes/updated_contact.yml +0 -97
- data/test/fixtures/quaderno_cassettes/updated_contact_by_access_token.yml +0 -101
- data/test/fixtures/quaderno_cassettes/updated_contact_by_authentication_token.yml +0 -102
- data/test/fixtures/quaderno_cassettes/updated_estimate.yml +0 -185
- data/test/fixtures/quaderno_cassettes/updated_expense.yml +0 -184
- data/test/fixtures/quaderno_cassettes/updated_invoice.yml +0 -184
- data/test/fixtures/quaderno_cassettes/updated_item.yml +0 -93
- data/test/fixtures/quaderno_cassettes/updated_receipt.yml +0 -220
- data/test/fixtures/quaderno_cassettes/updated_webhook.yml +0 -175
- data/test/fixtures/quaderno_cassettes/validate_invalid_VAT_number.yml +0 -44
- data/test/fixtures/quaderno_cassettes/validate_valid_VAT_number.yml +0 -44
- data/test/helper.rb +0 -32
- data/test/unit/test_quaderno_contacts.rb +0 -83
- data/test/unit/test_quaderno_contacts_thread_safe.rb +0 -104
- data/test/unit/test_quaderno_estimates.rb +0 -155
- data/test/unit/test_quaderno_evidences.rb +0 -41
- data/test/unit/test_quaderno_expenses.rb +0 -162
- data/test/unit/test_quaderno_invoices.rb +0 -177
- data/test/unit/test_quaderno_items.rb +0 -84
- data/test/unit/test_quaderno_receipts.rb +0 -156
- data/test/unit/test_quaderno_tax.rb +0 -46
- data/test/unit/test_quaderno_webhooks.rb +0 -93
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32220859b00bca2665db02c3b16b78b2c291d1d3
|
4
|
+
data.tar.gz: 9821325ecf15b3ff58ce8877ed6f160af1966fcb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5eafdb13dae89b85b6ffcb7123854a6f6a96c9ec7d4c8477541a05f9761cd0002d002aa5bdf31a64add59ec8395687df9dff4cfad05a41306dde474412399324
|
7
|
+
data.tar.gz: dbe323f4e55ca48b7c9a510eb63d685d474e2120261e8d77a3ad7ab789ef205cbbd989abb41e5918bea019154d2266170ab5fcc517d43e73cc8abfb9e14e2c8c
|
data/.gitignore
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# rcov generated
|
2
|
+
coverage
|
3
|
+
coverage.data
|
4
|
+
|
5
|
+
# rdoc generated
|
6
|
+
rdoc
|
7
|
+
|
8
|
+
# yard generated
|
9
|
+
doc
|
10
|
+
.yardoc
|
11
|
+
|
12
|
+
# bundler
|
13
|
+
.bundle
|
14
|
+
|
15
|
+
Gemfile.lock
|
16
|
+
|
17
|
+
# jeweler generated
|
18
|
+
pkg
|
19
|
+
|
20
|
+
/Gemfile.lock
|
21
|
+
|
22
|
+
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
|
23
|
+
#
|
24
|
+
# * Create a file at ~/.gitignore
|
25
|
+
# * Include files you want ignored
|
26
|
+
# * Run: git config --global core.excludesfile ~/.gitignore
|
27
|
+
#
|
28
|
+
# After doing this, these files will be ignored in all your git projects,
|
29
|
+
# saving you from having to 'pollute' every project you touch with them
|
30
|
+
#
|
31
|
+
# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
|
32
|
+
#
|
33
|
+
# For MacOS:
|
34
|
+
#
|
35
|
+
#.DS_Store
|
36
|
+
|
37
|
+
# For TextMate
|
38
|
+
#*.tmproj
|
39
|
+
#tmtags
|
40
|
+
|
41
|
+
# For emacs:
|
42
|
+
#*~
|
43
|
+
#\#*
|
44
|
+
#.\#*
|
45
|
+
|
46
|
+
# For vim:
|
47
|
+
#*.swp
|
48
|
+
|
49
|
+
# For redcar:
|
50
|
+
#.redcar
|
51
|
+
|
52
|
+
# For rubinius:
|
53
|
+
#*.rbc
|
54
|
+
|
55
|
+
*.gem
|
56
|
+
pkg/*
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
@@ -1,17 +1,4 @@
|
|
1
1
|
source 'http://rubygems.org'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
group :development do
|
6
|
-
gem 'jeweler', '~> 2.0.1'
|
7
|
-
gem 'rdoc', '~> 3.12'
|
8
|
-
end
|
9
|
-
|
10
|
-
group :test do
|
11
|
-
gem 'bundler', '>= 1.0.0'
|
12
|
-
gem 'fakeweb'
|
13
|
-
gem 'minitest', '~> 4.7.5 '
|
14
|
-
gem 'simplecov', '>= 0'
|
15
|
-
gem 'shoulda', '>= 0'
|
16
|
-
gem 'vcr', :require => 'vcr'
|
17
|
-
end
|
3
|
+
# Specify your gem's dependencies in valabn.gemspec
|
4
|
+
gemspec
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Quaderno-ruby is a ruby wrapper for [Quaderno API] (https://github.com/quaderno/quaderno-api).
|
4
4
|
|
5
|
-
Current version is 1.
|
5
|
+
Current version is 1.15.1 See the changelog [here](https://github.com/quaderno/quaderno-ruby/blob/master/changelog.md)
|
6
6
|
|
7
7
|
## Installation & Configuration
|
8
8
|
|
data/Rakefile
CHANGED
@@ -1,52 +1,6 @@
|
|
1
|
-
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
2
3
|
|
3
|
-
|
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
|
-
|
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
|
data/changelog.md
CHANGED
@@ -1,4 +1,13 @@
|
|
1
1
|
#Changelog
|
2
|
+
##1.15.1
|
3
|
+
* Fix `Quaderno` load order.
|
4
|
+
|
5
|
+
##1.15.0
|
6
|
+
* Removed `jeweler` and updated the gem structure.
|
7
|
+
|
8
|
+
##1.14.0
|
9
|
+
* Added `domestic_taxes`, `sales_taxes`, `vat_moss`, `ec_sales` and `international_taxes` to `Quaderno::Report`
|
10
|
+
|
2
11
|
##1.13.2
|
3
12
|
* Added index method to `Quaderno::Tax` as `Quaderno::Tax.all()`.
|
4
13
|
|
data/lib/quaderno-ruby.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
class Quaderno
|
2
|
+
end
|
3
|
+
|
1
4
|
require 'ostruct'
|
2
5
|
|
3
6
|
require 'quaderno-ruby/exceptions/exceptions'
|
@@ -6,7 +9,3 @@ require 'quaderno-ruby/collection'
|
|
6
9
|
|
7
10
|
%w(block crud deliver payment retrieve).each { |filename| require "quaderno-ruby/behavior/#{filename}" }
|
8
11
|
%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
|
data/lib/quaderno-ruby/base.rb
CHANGED
@@ -1,136 +1,134 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
44
|
-
|
45
|
-
def self.url=(url)
|
46
|
-
@@url = url
|
47
|
-
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
|
+
|
10
|
+
PRODUCTION_URL = 'https://quadernoapp.com/api/'
|
11
|
+
SANDBOX_URL = 'http://sandbox-quadernoapp.com/api/'
|
12
|
+
|
13
|
+
@@auth_token = nil
|
14
|
+
@@rate_limit_info = nil
|
15
|
+
@@api_version = nil
|
16
|
+
@@url = PRODUCTION_URL
|
17
|
+
|
18
|
+
# Class methods
|
19
|
+
def self.api_model(klass)
|
20
|
+
instance_eval <<-END
|
21
|
+
def api_model
|
22
|
+
#{klass}
|
23
|
+
end
|
24
|
+
END
|
25
|
+
class_eval <<-END
|
26
|
+
def api_model
|
27
|
+
#{klass}
|
28
|
+
end
|
29
|
+
END
|
30
|
+
end
|
48
31
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
response = get("#{url}authorization.json", basic_auth: { username: auth_token }, headers: version_header)
|
32
|
+
def self.configure
|
33
|
+
yield self
|
34
|
+
end
|
53
35
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
raise(Quaderno::Exceptions::InvalidSubdomainOrToken, 'Invalid subdomain or token')
|
58
|
-
end
|
59
|
-
end
|
36
|
+
def self.api_version=(api_version)
|
37
|
+
@@api_version = api_version
|
38
|
+
end
|
60
39
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
options[:auth_token] ||= auth_token
|
65
|
-
options[:api_url] ||= url
|
40
|
+
def self.auth_token=(auth_token)
|
41
|
+
@@auth_token = auth_token
|
42
|
+
end
|
66
43
|
|
67
|
-
|
44
|
+
def self.url=(url)
|
45
|
+
@@url = url
|
46
|
+
end
|
68
47
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
48
|
+
def self.authorization(auth_token, mode = nil)
|
49
|
+
mode ||= :production
|
50
|
+
url = mode == :sandbox ? SANDBOX_URL : PRODUCTION_URL
|
51
|
+
response = get("#{url}authorization.json", basic_auth: { username: auth_token }, headers: version_header)
|
73
52
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
true
|
53
|
+
if response.code == 200
|
54
|
+
response.parsed_response
|
55
|
+
else
|
56
|
+
raise(Quaderno::Exceptions::InvalidSubdomainOrToken, 'Invalid subdomain or token')
|
79
57
|
end
|
58
|
+
end
|
80
59
|
|
81
|
-
|
60
|
+
#Check the connection
|
61
|
+
def self.ping(options = {})
|
62
|
+
begin
|
82
63
|
options[:auth_token] ||= auth_token
|
83
64
|
options[:api_url] ||= url
|
84
65
|
|
85
66
|
authentication = get_authentication(options)
|
86
67
|
|
87
|
-
party_response = get("#{authentication[:url]}
|
68
|
+
party_response = get("#{authentication[:url]}ping.json",
|
88
69
|
basic_auth: authentication[:basic_auth],
|
89
70
|
headers: version_header.merge(authentication[:headers])
|
90
71
|
)
|
91
72
|
|
92
73
|
check_exception_for(party_response, { subdomain_or_token: true })
|
93
|
-
|
94
|
-
|
74
|
+
rescue Errno::ECONNREFUSED
|
75
|
+
return false
|
95
76
|
end
|
77
|
+
true
|
78
|
+
end
|
96
79
|
|
97
|
-
|
98
|
-
|
99
|
-
|
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
|
80
|
+
def self.me(options = {})
|
81
|
+
options[:auth_token] ||= auth_token
|
82
|
+
options[:api_url] ||= url
|
103
83
|
|
104
|
-
|
105
|
-
def to_hash
|
106
|
-
self.marshal_dump
|
107
|
-
end
|
84
|
+
authentication = get_authentication(options)
|
108
85
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
end
|
86
|
+
party_response = get("#{authentication[:url]}me.json",
|
87
|
+
basic_auth: authentication[:basic_auth],
|
88
|
+
headers: version_header.merge(authentication[:headers])
|
89
|
+
)
|
114
90
|
|
115
|
-
|
116
|
-
@@url
|
117
|
-
end
|
91
|
+
check_exception_for(party_response, { subdomain_or_token: true })
|
118
92
|
|
119
|
-
|
120
|
-
|
121
|
-
end
|
93
|
+
party_response.parsed_response
|
94
|
+
end
|
122
95
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
96
|
+
#Returns the rate limit information: limit and remaining requests
|
97
|
+
def self.rate_limit_info
|
98
|
+
party_response = get("#{@@url}ping.json", basic_auth: { username: auth_token }, headers: version_header)
|
99
|
+
check_exception_for(party_response, { subdomain_or_token: true })
|
100
|
+
@@rate_limit_info = { reset: party_response.headers['x-ratelimit-reset'].to_i, remaining: party_response.headers["x-ratelimit-remaining"].to_i }
|
101
|
+
end
|
127
102
|
|
128
|
-
|
129
|
-
|
130
|
-
|
103
|
+
# Instance methods
|
104
|
+
def to_hash
|
105
|
+
self.marshal_dump
|
106
|
+
end
|
131
107
|
|
132
|
-
|
133
|
-
|
134
|
-
|
108
|
+
private
|
109
|
+
# Class methods
|
110
|
+
def self.auth_token
|
111
|
+
@@auth_token
|
112
|
+
end
|
113
|
+
|
114
|
+
def self.url
|
115
|
+
@@url
|
116
|
+
end
|
117
|
+
|
118
|
+
def self.subdomain
|
119
|
+
@_subdomain = @@subdomain
|
120
|
+
end
|
121
|
+
|
122
|
+
#Set or returns the model path for the url
|
123
|
+
def self.api_path(api_path = nil)
|
124
|
+
@_api_path ||= api_path
|
125
|
+
end
|
126
|
+
|
127
|
+
def self.is_a_document?(document = nil)
|
128
|
+
@_document ||= document
|
129
|
+
end
|
130
|
+
|
131
|
+
def self.version_header
|
132
|
+
{ 'Accept' => @@api_version.to_i.zero? ? "application/json" : "application/json; api_version=#{@@api_version.to_i}"}
|
135
133
|
end
|
136
|
-
end
|
134
|
+
end
|
@@ -1,28 +1,26 @@
|
|
1
|
-
module Quaderno
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
end
|
1
|
+
module Quaderno::Behavior
|
2
|
+
module Block
|
3
|
+
def self.included(receiver)
|
4
|
+
receiver.send :extend, ClassMethods
|
5
|
+
end
|
7
6
|
|
8
|
-
|
9
|
-
|
7
|
+
module ClassMethods
|
8
|
+
include Quaderno::Helpers::Authentication
|
10
9
|
|
11
|
-
|
12
|
-
|
10
|
+
def block(id, options = {})
|
11
|
+
authentication = get_authentication(options.merge(api_model: api_model))
|
13
12
|
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
response = put("#{authentication[:url]}#{api_model.api_path}/#{id}/block.json",
|
15
|
+
basic_auth: authentication[:basic_auth],
|
16
|
+
headers: version_header.merge(authentication[:headers])
|
17
|
+
)
|
19
18
|
|
20
|
-
|
21
|
-
|
19
|
+
check_exception_for(response, { rate_limit: true, subdomain_or_token: true, id: true })
|
20
|
+
doc = response.parsed_response
|
22
21
|
|
23
|
-
|
24
|
-
end
|
22
|
+
new doc
|
25
23
|
end
|
26
24
|
end
|
27
25
|
end
|
28
|
-
end
|
26
|
+
end
|