jortt 3.0.0 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/rspec.yml +40 -0
- data/.ruby-version +1 -1
- data/README.md +81 -46
- data/Rakefile +0 -1
- data/jortt.gemspec +10 -10
- data/lib/jortt.rb +0 -1
- data/lib/jortt/client.rb +75 -23
- data/lib/jortt/client/customers.rb +91 -0
- data/lib/jortt/client/error.rb +33 -0
- data/lib/jortt/client/invoices.rb +80 -0
- data/lib/jortt/client/ledger_accounts.rb +27 -0
- data/lib/jortt/client/version.rb +1 -2
- data/spec/fixtures/vcr_cassettes/Jortt/_client/1_1_1.yml +64 -0
- data/spec/fixtures/vcr_cassettes/Jortt_Client/configured/_customers/1_1_1_1.yml +64 -0
- data/spec/fixtures/vcr_cassettes/Jortt_Client/configured/_invoices/1_1_2_1.yml +64 -0
- data/spec/fixtures/vcr_cassettes/Jortt_Client/configured/_ledger_accounts/1_1_3_1.yml +64 -0
- data/spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_create/faulty_payload/shows_a_nice_error.yml +413 -0
- data/spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_create/valid_payload/creates_the_customer.yml +505 -0
- data/spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_delete/deletes_the_customer.yml +505 -0
- data/spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_direct_debit_mandate/sends_direct_debit_mandate_to_the_customer_or_responds_with_an_error_when_not_possible.yml +470 -0
- data/spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_index/query/returns_the_queried_customers.yml +464 -0
- data/spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_index/without_params/returns_customers.yml +415 -0
- data/spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_show/returns_the_customer.yml +464 -0
- data/spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_update/updates_the_customer.yml +603 -0
- data/spec/fixtures/vcr_cassettes/Jortt_Client_Invoices/_create/creates_the_invoice.yml +170 -0
- data/spec/fixtures/vcr_cassettes/Jortt_Client_Invoices/_credit/credits_the_invoice.yml +374 -0
- data/spec/fixtures/vcr_cassettes/Jortt_Client_Invoices/_download/returns_the_invoice_download_link.yml +168 -0
- data/spec/fixtures/vcr_cassettes/Jortt_Client_Invoices/_index/invoice_status/returns_those_invoices.yml +776 -0
- data/spec/fixtures/vcr_cassettes/Jortt_Client_Invoices/_index/query/returns_the_queried_invoices.yml +315 -0
- data/spec/fixtures/vcr_cassettes/Jortt_Client_Invoices/_show/returns_the_invoice.yml +421 -0
- data/spec/fixtures/vcr_cassettes/Jortt_Client_LedgerAccounts/_index/returns_invoices.yml +118 -0
- data/spec/jortt/client/customers_spec.rb +104 -0
- data/spec/jortt/client/invoices_spec.rb +129 -0
- data/spec/jortt/client/ledger_accounts_spec.rb +19 -0
- data/spec/jortt/client_spec.rb +9 -30
- data/spec/{freemle_spec.rb → jortt_spec.rb} +2 -3
- data/spec/spec_helper.rb +18 -4
- metadata +95 -46
- data/.rubocop.yml +0 -26
- data/.travis.yml +0 -7
- data/lib/jortt/client/resource.rb +0 -140
- data/spec/jortt/client/resource_spec.rb +0 -31
metadata
CHANGED
@@ -1,158 +1,163 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jortt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 6.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bob Forma
|
8
|
-
-
|
8
|
+
- Michael Franken
|
9
9
|
- Lars Vonk
|
10
10
|
- Stephan van Diepen
|
11
|
-
autorequire:
|
11
|
+
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2021-02-24 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rest-client
|
18
18
|
requirement: !ruby/object:Gem::Requirement
|
19
19
|
requirements:
|
20
|
-
- - "
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '2.0'
|
23
|
+
- - "<"
|
21
24
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
25
|
+
version: '2.2'
|
23
26
|
type: :runtime
|
24
27
|
prerelease: false
|
25
28
|
version_requirements: !ruby/object:Gem::Requirement
|
26
29
|
requirements:
|
27
|
-
- - "
|
30
|
+
- - ">="
|
28
31
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
32
|
+
version: '2.0'
|
33
|
+
- - "<"
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '2.2'
|
30
36
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
37
|
+
name: oauth2
|
32
38
|
requirement: !ruby/object:Gem::Requirement
|
33
39
|
requirements:
|
34
40
|
- - "~>"
|
35
41
|
- !ruby/object:Gem::Version
|
36
|
-
version:
|
37
|
-
type: :
|
42
|
+
version: 1.4.4
|
43
|
+
type: :runtime
|
38
44
|
prerelease: false
|
39
45
|
version_requirements: !ruby/object:Gem::Requirement
|
40
46
|
requirements:
|
41
47
|
- - "~>"
|
42
48
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
49
|
+
version: 1.4.4
|
44
50
|
- !ruby/object:Gem::Dependency
|
45
|
-
name:
|
51
|
+
name: bundler
|
46
52
|
requirement: !ruby/object:Gem::Requirement
|
47
53
|
requirements:
|
48
54
|
- - "~>"
|
49
55
|
- !ruby/object:Gem::Version
|
50
|
-
version: '0
|
56
|
+
version: '2.0'
|
51
57
|
type: :development
|
52
58
|
prerelease: false
|
53
59
|
version_requirements: !ruby/object:Gem::Requirement
|
54
60
|
requirements:
|
55
61
|
- - "~>"
|
56
62
|
- !ruby/object:Gem::Version
|
57
|
-
version: '0
|
63
|
+
version: '2.0'
|
58
64
|
- !ruby/object:Gem::Dependency
|
59
|
-
name:
|
65
|
+
name: codecov
|
60
66
|
requirement: !ruby/object:Gem::Requirement
|
61
67
|
requirements:
|
62
68
|
- - "~>"
|
63
69
|
- !ruby/object:Gem::Version
|
64
|
-
version: '
|
70
|
+
version: '0.1'
|
65
71
|
type: :development
|
66
72
|
prerelease: false
|
67
73
|
version_requirements: !ruby/object:Gem::Requirement
|
68
74
|
requirements:
|
69
75
|
- - "~>"
|
70
76
|
- !ruby/object:Gem::Version
|
71
|
-
version: '
|
77
|
+
version: '0.1'
|
72
78
|
- !ruby/object:Gem::Dependency
|
73
|
-
name:
|
79
|
+
name: rake
|
74
80
|
requirement: !ruby/object:Gem::Requirement
|
75
81
|
requirements:
|
76
82
|
- - "~>"
|
77
83
|
- !ruby/object:Gem::Version
|
78
|
-
version:
|
84
|
+
version: '13.0'
|
79
85
|
type: :development
|
80
86
|
prerelease: false
|
81
87
|
version_requirements: !ruby/object:Gem::Requirement
|
82
88
|
requirements:
|
83
89
|
- - "~>"
|
84
90
|
- !ruby/object:Gem::Version
|
85
|
-
version:
|
91
|
+
version: '13.0'
|
86
92
|
- !ruby/object:Gem::Dependency
|
87
|
-
name: rspec
|
93
|
+
name: rspec
|
88
94
|
requirement: !ruby/object:Gem::Requirement
|
89
95
|
requirements:
|
90
96
|
- - "~>"
|
91
97
|
- !ruby/object:Gem::Version
|
92
|
-
version:
|
98
|
+
version: '3.7'
|
93
99
|
type: :development
|
94
100
|
prerelease: false
|
95
101
|
version_requirements: !ruby/object:Gem::Requirement
|
96
102
|
requirements:
|
97
103
|
- - "~>"
|
98
104
|
- !ruby/object:Gem::Version
|
99
|
-
version:
|
105
|
+
version: '3.7'
|
100
106
|
- !ruby/object:Gem::Dependency
|
101
|
-
name:
|
107
|
+
name: rspec-its
|
102
108
|
requirement: !ruby/object:Gem::Requirement
|
103
109
|
requirements:
|
104
110
|
- - "~>"
|
105
111
|
- !ruby/object:Gem::Version
|
106
|
-
version: '1.
|
112
|
+
version: '1.2'
|
107
113
|
type: :development
|
108
114
|
prerelease: false
|
109
115
|
version_requirements: !ruby/object:Gem::Requirement
|
110
116
|
requirements:
|
111
117
|
- - "~>"
|
112
118
|
- !ruby/object:Gem::Version
|
113
|
-
version: '1.
|
119
|
+
version: '1.2'
|
114
120
|
- !ruby/object:Gem::Dependency
|
115
|
-
name:
|
121
|
+
name: webmock
|
116
122
|
requirement: !ruby/object:Gem::Requirement
|
117
123
|
requirements:
|
118
124
|
- - "~>"
|
119
125
|
- !ruby/object:Gem::Version
|
120
|
-
version:
|
126
|
+
version: '3.3'
|
121
127
|
type: :development
|
122
128
|
prerelease: false
|
123
129
|
version_requirements: !ruby/object:Gem::Requirement
|
124
130
|
requirements:
|
125
131
|
- - "~>"
|
126
132
|
- !ruby/object:Gem::Version
|
127
|
-
version:
|
133
|
+
version: '3.3'
|
128
134
|
- !ruby/object:Gem::Dependency
|
129
|
-
name:
|
135
|
+
name: vcr
|
130
136
|
requirement: !ruby/object:Gem::Requirement
|
131
137
|
requirements:
|
132
138
|
- - "~>"
|
133
139
|
- !ruby/object:Gem::Version
|
134
|
-
version:
|
140
|
+
version: '6.0'
|
135
141
|
type: :development
|
136
142
|
prerelease: false
|
137
143
|
version_requirements: !ruby/object:Gem::Requirement
|
138
144
|
requirements:
|
139
145
|
- - "~>"
|
140
146
|
- !ruby/object:Gem::Version
|
141
|
-
version:
|
142
|
-
description:
|
147
|
+
version: '6.0'
|
148
|
+
description:
|
143
149
|
email:
|
144
150
|
- bforma@zilverline.com
|
145
|
-
-
|
151
|
+
- mfranken@zilverline.com
|
146
152
|
- lvonk@zilverline.com
|
147
153
|
- svdiepen@zilverline.com
|
148
154
|
executables: []
|
149
155
|
extensions: []
|
150
156
|
extra_rdoc_files: []
|
151
157
|
files:
|
158
|
+
- ".github/workflows/rspec.yml"
|
152
159
|
- ".gitignore"
|
153
|
-
- ".rubocop.yml"
|
154
160
|
- ".ruby-version"
|
155
|
-
- ".travis.yml"
|
156
161
|
- Gemfile
|
157
162
|
- LICENSE.txt
|
158
163
|
- README.md
|
@@ -160,17 +165,41 @@ files:
|
|
160
165
|
- jortt.gemspec
|
161
166
|
- lib/jortt.rb
|
162
167
|
- lib/jortt/client.rb
|
163
|
-
- lib/jortt/client/
|
168
|
+
- lib/jortt/client/customers.rb
|
169
|
+
- lib/jortt/client/error.rb
|
170
|
+
- lib/jortt/client/invoices.rb
|
171
|
+
- lib/jortt/client/ledger_accounts.rb
|
164
172
|
- lib/jortt/client/version.rb
|
165
|
-
- spec/
|
166
|
-
- spec/
|
173
|
+
- spec/fixtures/vcr_cassettes/Jortt/_client/1_1_1.yml
|
174
|
+
- spec/fixtures/vcr_cassettes/Jortt_Client/configured/_customers/1_1_1_1.yml
|
175
|
+
- spec/fixtures/vcr_cassettes/Jortt_Client/configured/_invoices/1_1_2_1.yml
|
176
|
+
- spec/fixtures/vcr_cassettes/Jortt_Client/configured/_ledger_accounts/1_1_3_1.yml
|
177
|
+
- spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_create/faulty_payload/shows_a_nice_error.yml
|
178
|
+
- spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_create/valid_payload/creates_the_customer.yml
|
179
|
+
- spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_delete/deletes_the_customer.yml
|
180
|
+
- spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_direct_debit_mandate/sends_direct_debit_mandate_to_the_customer_or_responds_with_an_error_when_not_possible.yml
|
181
|
+
- spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_index/query/returns_the_queried_customers.yml
|
182
|
+
- spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_index/without_params/returns_customers.yml
|
183
|
+
- spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_show/returns_the_customer.yml
|
184
|
+
- spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_update/updates_the_customer.yml
|
185
|
+
- spec/fixtures/vcr_cassettes/Jortt_Client_Invoices/_create/creates_the_invoice.yml
|
186
|
+
- spec/fixtures/vcr_cassettes/Jortt_Client_Invoices/_credit/credits_the_invoice.yml
|
187
|
+
- spec/fixtures/vcr_cassettes/Jortt_Client_Invoices/_download/returns_the_invoice_download_link.yml
|
188
|
+
- spec/fixtures/vcr_cassettes/Jortt_Client_Invoices/_index/invoice_status/returns_those_invoices.yml
|
189
|
+
- spec/fixtures/vcr_cassettes/Jortt_Client_Invoices/_index/query/returns_the_queried_invoices.yml
|
190
|
+
- spec/fixtures/vcr_cassettes/Jortt_Client_Invoices/_show/returns_the_invoice.yml
|
191
|
+
- spec/fixtures/vcr_cassettes/Jortt_Client_LedgerAccounts/_index/returns_invoices.yml
|
192
|
+
- spec/jortt/client/customers_spec.rb
|
193
|
+
- spec/jortt/client/invoices_spec.rb
|
194
|
+
- spec/jortt/client/ledger_accounts_spec.rb
|
167
195
|
- spec/jortt/client_spec.rb
|
196
|
+
- spec/jortt_spec.rb
|
168
197
|
- spec/spec_helper.rb
|
169
198
|
homepage: https://app.jortt.nl/api-documentatie
|
170
199
|
licenses:
|
171
200
|
- MIT
|
172
201
|
metadata: {}
|
173
|
-
post_install_message:
|
202
|
+
post_install_message:
|
174
203
|
rdoc_options: []
|
175
204
|
require_paths:
|
176
205
|
- lib
|
@@ -185,13 +214,33 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
185
214
|
- !ruby/object:Gem::Version
|
186
215
|
version: '0'
|
187
216
|
requirements: []
|
188
|
-
|
189
|
-
|
190
|
-
signing_key:
|
217
|
+
rubygems_version: 3.2.3
|
218
|
+
signing_key:
|
191
219
|
specification_version: 4
|
192
220
|
summary: jortt.nl REST API client
|
193
221
|
test_files:
|
194
|
-
- spec/
|
195
|
-
- spec/
|
222
|
+
- spec/fixtures/vcr_cassettes/Jortt/_client/1_1_1.yml
|
223
|
+
- spec/fixtures/vcr_cassettes/Jortt_Client/configured/_customers/1_1_1_1.yml
|
224
|
+
- spec/fixtures/vcr_cassettes/Jortt_Client/configured/_invoices/1_1_2_1.yml
|
225
|
+
- spec/fixtures/vcr_cassettes/Jortt_Client/configured/_ledger_accounts/1_1_3_1.yml
|
226
|
+
- spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_create/faulty_payload/shows_a_nice_error.yml
|
227
|
+
- spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_create/valid_payload/creates_the_customer.yml
|
228
|
+
- spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_delete/deletes_the_customer.yml
|
229
|
+
- spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_direct_debit_mandate/sends_direct_debit_mandate_to_the_customer_or_responds_with_an_error_when_not_possible.yml
|
230
|
+
- spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_index/query/returns_the_queried_customers.yml
|
231
|
+
- spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_index/without_params/returns_customers.yml
|
232
|
+
- spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_show/returns_the_customer.yml
|
233
|
+
- spec/fixtures/vcr_cassettes/Jortt_Client_Customers/_update/updates_the_customer.yml
|
234
|
+
- spec/fixtures/vcr_cassettes/Jortt_Client_Invoices/_create/creates_the_invoice.yml
|
235
|
+
- spec/fixtures/vcr_cassettes/Jortt_Client_Invoices/_credit/credits_the_invoice.yml
|
236
|
+
- spec/fixtures/vcr_cassettes/Jortt_Client_Invoices/_download/returns_the_invoice_download_link.yml
|
237
|
+
- spec/fixtures/vcr_cassettes/Jortt_Client_Invoices/_index/invoice_status/returns_those_invoices.yml
|
238
|
+
- spec/fixtures/vcr_cassettes/Jortt_Client_Invoices/_index/query/returns_the_queried_invoices.yml
|
239
|
+
- spec/fixtures/vcr_cassettes/Jortt_Client_Invoices/_show/returns_the_invoice.yml
|
240
|
+
- spec/fixtures/vcr_cassettes/Jortt_Client_LedgerAccounts/_index/returns_invoices.yml
|
241
|
+
- spec/jortt/client/customers_spec.rb
|
242
|
+
- spec/jortt/client/invoices_spec.rb
|
243
|
+
- spec/jortt/client/ledger_accounts_spec.rb
|
196
244
|
- spec/jortt/client_spec.rb
|
245
|
+
- spec/jortt_spec.rb
|
197
246
|
- spec/spec_helper.rb
|
data/.rubocop.yml
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require: rubocop-rspec
|
2
|
-
|
3
|
-
Style/AccessModifierIndentation:
|
4
|
-
EnforcedStyle: outdent
|
5
|
-
|
6
|
-
Style/AlignParameters:
|
7
|
-
EnforcedStyle: with_fixed_indentation
|
8
|
-
|
9
|
-
Style/DotPosition:
|
10
|
-
EnforcedStyle: trailing
|
11
|
-
|
12
|
-
Style/TrailingComma:
|
13
|
-
EnforcedStyleForMultiline: comma
|
14
|
-
|
15
|
-
Style/EmptyLinesAroundBody:
|
16
|
-
Description: "Keeps track of empty lines around expression bodies."
|
17
|
-
Enabled: false
|
18
|
-
|
19
|
-
Style/RegexpLiteral:
|
20
|
-
MaxSlashes: 0
|
21
|
-
|
22
|
-
Style/HashSyntax:
|
23
|
-
EnforcedStyle: ruby19
|
24
|
-
|
25
|
-
Style/SpaceInsideHashLiteralBraces:
|
26
|
-
EnforcedStyle: no_space
|
data/.travis.yml
DELETED
@@ -1,140 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require 'rest-client'
|
3
|
-
|
4
|
-
module Jortt # :nodoc:
|
5
|
-
class Client # :nodoc:
|
6
|
-
##
|
7
|
-
# This class is used by {Jortt::Client} internally.
|
8
|
-
# It wraps rest API calls of a single resource,
|
9
|
-
# so they can easily be used using the client DSL.
|
10
|
-
#
|
11
|
-
# @see { Jortt::Client.customer }
|
12
|
-
class Resource
|
13
|
-
|
14
|
-
# Details needed to connect to this resource, see
|
15
|
-
# +Jortt::Client#initialize+
|
16
|
-
#
|
17
|
-
# @since 1.0.0
|
18
|
-
attr_accessor :config
|
19
|
-
|
20
|
-
# The singular form, posted to and returned when describing
|
21
|
-
# a single member of this resource.
|
22
|
-
#
|
23
|
-
# @since 1.0.0
|
24
|
-
attr_accessor :singular
|
25
|
-
|
26
|
-
# Used to describe multiple members of this resource.
|
27
|
-
#
|
28
|
-
# @since 1.0.0
|
29
|
-
attr_accessor :plural
|
30
|
-
|
31
|
-
# Creates a new resource instance.
|
32
|
-
#
|
33
|
-
# @see { Jortt::Client#new_resource }
|
34
|
-
#
|
35
|
-
# @returns [ Jortt::Client::Resource ] bound to the resource
|
36
|
-
# defined by +singular+ & +plural+
|
37
|
-
#
|
38
|
-
# @since 1.0.0
|
39
|
-
def initialize(config, singular, plural)
|
40
|
-
self.config = config
|
41
|
-
self.singular = singular
|
42
|
-
self.plural = plural
|
43
|
-
end
|
44
|
-
|
45
|
-
# Performs a search on this resource, given a query.
|
46
|
-
#
|
47
|
-
# @example
|
48
|
-
# customers.search('Zilverline')
|
49
|
-
#
|
50
|
-
# @example
|
51
|
-
# customers.search('Zilverline') do |response|
|
52
|
-
# # Roll your own response handler
|
53
|
-
# end
|
54
|
-
#
|
55
|
-
# @param [ Hash ] query A hash containing the fields to search for.
|
56
|
-
# @param [ Proc ] block A custom response handler.
|
57
|
-
#
|
58
|
-
# @return [ Array<Hash> ] By default, a JSON parsed response body.
|
59
|
-
#
|
60
|
-
# @since 1.0.0
|
61
|
-
def search(query, &block)
|
62
|
-
block = default_handler unless block_given?
|
63
|
-
request.get(params: {query: query}, &block)
|
64
|
-
end
|
65
|
-
|
66
|
-
# Persists a resource on app.jortt.nl, given a payload.
|
67
|
-
#
|
68
|
-
# @example
|
69
|
-
# customers.create(
|
70
|
-
# company_name: "Zilverline B.V.",
|
71
|
-
# address: {
|
72
|
-
# street: "Cruquiusweg 109 F",
|
73
|
-
# postal_code: "1019 AG",
|
74
|
-
# city: "Amsterdam",
|
75
|
-
# country_code: "NL"
|
76
|
-
# }
|
77
|
-
# )
|
78
|
-
#
|
79
|
-
# @example
|
80
|
-
# customers.create(
|
81
|
-
# company_name: "Zilverline B.V.",
|
82
|
-
# address: {
|
83
|
-
# street: "Cruquiusweg 109 F",
|
84
|
-
# postal_code: "1019 AG",
|
85
|
-
# city: "Amsterdam",
|
86
|
-
# country_code: "NL"
|
87
|
-
# }
|
88
|
-
# ) do |response|
|
89
|
-
# # Roll your own response handler
|
90
|
-
# end
|
91
|
-
#
|
92
|
-
# @param [ Hash ] payload A hash containing the fields to set.
|
93
|
-
# @param [ Proc ] block A custom response handler.
|
94
|
-
#
|
95
|
-
# @return [ Hash ] By default, a JSON parsed response body.
|
96
|
-
#
|
97
|
-
# @since 1.0.0
|
98
|
-
def create(payload, &block)
|
99
|
-
block = default_handler unless block_given?
|
100
|
-
request.post(json.generate(singular => payload), &block)
|
101
|
-
end
|
102
|
-
|
103
|
-
private
|
104
|
-
|
105
|
-
# Returns a response handler, which parses the response body as JSON.
|
106
|
-
#
|
107
|
-
# @return [ Proc ] Default response handler.
|
108
|
-
#
|
109
|
-
# @since 1.0.0
|
110
|
-
def default_handler
|
111
|
-
proc { |response| json.parse(response.body) }
|
112
|
-
end
|
113
|
-
|
114
|
-
# Returns a new request handler for this resource.
|
115
|
-
#
|
116
|
-
# @return [ RestClient::Resource ] A request handler.
|
117
|
-
#
|
118
|
-
# @since 1.0.0
|
119
|
-
def request
|
120
|
-
RestClient::Resource.new(
|
121
|
-
"#{config.base_url}/#{plural}",
|
122
|
-
user: config.app_name,
|
123
|
-
password: config.api_key,
|
124
|
-
)
|
125
|
-
end
|
126
|
-
|
127
|
-
# Returns the JSON library used in request/default-response handling.
|
128
|
-
#
|
129
|
-
# @return [ Class ] A JSON library.
|
130
|
-
#
|
131
|
-
# @since 1.0.0
|
132
|
-
def json
|
133
|
-
return @json if @json
|
134
|
-
require 'json'
|
135
|
-
@json = JSON
|
136
|
-
end
|
137
|
-
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|