jortt 3.0.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/jortt.gemspec +3 -3
- data/lib/jortt/client.rb +17 -14
- data/lib/jortt/client/customers.rb +72 -0
- data/lib/jortt/client/invoice.rb +50 -0
- data/lib/jortt/client/invoices.rb +50 -0
- data/lib/jortt/client/version.rb +1 -1
- data/spec/jortt/client/customers_spec.rb +31 -0
- data/spec/jortt/client/invoice_spec.rb +23 -0
- data/spec/jortt/client/invoices_spec.rb +22 -0
- data/spec/jortt/client_spec.rb +7 -6
- data/spec/{freemle_spec.rb → jortt_spec.rb} +0 -0
- metadata +20 -13
- data/lib/jortt/client/resource.rb +0 -140
- data/spec/jortt/client/resource_spec.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7faec2150bcc8753be6af239ea3efcb49ca5d5c3
|
4
|
+
data.tar.gz: 3d5e611607ae2e4bfe21a2dd24419ea355cd4c61
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1d1e1c59783b565a28c4056006811288e007b27860a41a67a3b75bcc29f0cc7560a23fe7f16193e9267f589bab2260bed4e73c02f93d4faf349a65c2b7543d1
|
7
|
+
data.tar.gz: 35e95f431f5a10dd0fa92c13caeef7125ec6e7bb19862d139885adc97ba030709612c1c022f6a304d476b8fc1350bc99077e4e18e8a8a5b0a81b4258d9b93362
|
data/jortt.gemspec
CHANGED
@@ -32,9 +32,9 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.add_development_dependency 'bundler', '~> 1.0'
|
33
33
|
spec.add_development_dependency 'codecov', '~> 0.1'
|
34
34
|
spec.add_development_dependency 'rake', '~> 10.0'
|
35
|
-
spec.add_development_dependency 'rspec', '~> 3.4
|
36
|
-
spec.add_development_dependency 'rspec-its', '~> 1.2
|
35
|
+
spec.add_development_dependency 'rspec', '~> 3.4'
|
36
|
+
spec.add_development_dependency 'rspec-its', '~> 1.2'
|
37
37
|
spec.add_development_dependency 'webmock', '~> 1.17'
|
38
38
|
spec.add_development_dependency 'rubocop', '~> 0.24.1'
|
39
|
-
spec.add_development_dependency 'rubocop-rspec', '~> 1.1
|
39
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 1.1'
|
40
40
|
end
|
data/lib/jortt/client.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
-
require 'jortt/client/
|
2
|
+
require 'jortt/client/customers'
|
3
|
+
require 'jortt/client/invoices'
|
4
|
+
require 'jortt/client/invoice'
|
3
5
|
|
4
6
|
module Jortt
|
5
7
|
##
|
@@ -30,39 +32,40 @@ module Jortt
|
|
30
32
|
self.api_key = opts.fetch(:api_key)
|
31
33
|
end
|
32
34
|
|
33
|
-
# Access the customer resource.
|
35
|
+
# Access the customer resource to perform operations.
|
34
36
|
#
|
35
37
|
# @example
|
36
38
|
# client.customers
|
37
39
|
#
|
38
|
-
# @return [ Jortt::Client::
|
40
|
+
# @return [ Jortt::Client::Customers ] entry to the customer resource.
|
39
41
|
#
|
40
42
|
# @since 1.0.0
|
41
43
|
def customers
|
42
|
-
@customers ||=
|
44
|
+
@customers ||= Jortt::Client::Customers.new(self)
|
43
45
|
end
|
44
46
|
|
45
|
-
# Access the
|
47
|
+
# Access the invoices resource to perform operations.
|
46
48
|
#
|
47
49
|
# @example
|
48
50
|
# client.invoices
|
49
51
|
#
|
50
|
-
# @return [ Jortt::Client::
|
52
|
+
# @return [ Jortt::Client::Invoices ] entry to the invoice resource.
|
51
53
|
#
|
52
54
|
# @since 1.0.0
|
53
55
|
def invoices
|
54
|
-
@invoices ||=
|
56
|
+
@invoices ||= Jortt::Client::Invoices.new(self)
|
55
57
|
end
|
56
58
|
|
57
|
-
|
58
|
-
|
59
|
-
#
|
59
|
+
# Access a single invoice resource to perform operations.
|
60
|
+
#
|
61
|
+
# @example
|
62
|
+
# client.invoice('abc')
|
60
63
|
#
|
61
|
-
# @
|
64
|
+
# @params [ String ] invoice_id The id of an invoice.
|
62
65
|
#
|
63
|
-
# @
|
64
|
-
def
|
65
|
-
Jortt::Client::
|
66
|
+
# @return [ Jortt::Client::Invoice ] entry to the invoice resource.
|
67
|
+
def invoice(invoice_id)
|
68
|
+
Jortt::Client::Invoice.new(self, invoice_id)
|
66
69
|
end
|
67
70
|
|
68
71
|
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rest-client'
|
3
|
+
|
4
|
+
module Jortt # :nodoc:
|
5
|
+
class Client # :nodoc:
|
6
|
+
|
7
|
+
##
|
8
|
+
# Exposes the operations available for a collection of customers.
|
9
|
+
#
|
10
|
+
# @see { Jortt::Client.customers }
|
11
|
+
class Customers
|
12
|
+
|
13
|
+
def initialize(config)
|
14
|
+
@resource = RestClient::Resource.new(
|
15
|
+
"#{config.base_url}/customers",
|
16
|
+
user: config.app_name,
|
17
|
+
password: config.api_key,
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
##
|
22
|
+
# Creates a Customer using the POST /customers endpoint.
|
23
|
+
# See https://app.jortt.nl/api-documentatie#klant-aanmaken
|
24
|
+
#
|
25
|
+
# @example
|
26
|
+
# Jortt::Client.customers.create(
|
27
|
+
# company_name: "Jortt B.V.", # mandatory
|
28
|
+
# attn: "Finance department", # optional
|
29
|
+
# email: "support@jortt.nl", # optional
|
30
|
+
# extra_information: "Our valued customer", # optional
|
31
|
+
# address: {
|
32
|
+
# street: "Street 100", # mandatory
|
33
|
+
# postal_code: "1000 AA", # mandatory
|
34
|
+
# city: "Amsterdam", # mandatory
|
35
|
+
# country_code: "NL" # mandatory
|
36
|
+
# }
|
37
|
+
# )
|
38
|
+
def create(payload)
|
39
|
+
resource.post(JSON.generate('customer' => payload)) do |response|
|
40
|
+
JSON.parse(response.body)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Performs a search on this resource, given a query.
|
45
|
+
#
|
46
|
+
# @example
|
47
|
+
# customers.search('Zilverline')
|
48
|
+
#
|
49
|
+
# @example
|
50
|
+
# customers.search('Zilverline') do |response|
|
51
|
+
# # Roll your own response handler
|
52
|
+
# end
|
53
|
+
#
|
54
|
+
# @param [ Hash ] query A hash containing the fields to search for.
|
55
|
+
# @param [ Proc ] block A custom response handler.
|
56
|
+
#
|
57
|
+
# @return [ Array<Hash> ] By default, a JSON parsed response body.
|
58
|
+
#
|
59
|
+
# @since 1.0.0
|
60
|
+
def search(query)
|
61
|
+
resource.get(params: {query: query}) do |response|
|
62
|
+
JSON.parse(response.body)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
attr_reader :resource
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rest-client'
|
3
|
+
|
4
|
+
module Jortt # :nodoc:
|
5
|
+
class Client # :nodoc:
|
6
|
+
|
7
|
+
##
|
8
|
+
# Exposes the operations available for a single invoice.
|
9
|
+
#
|
10
|
+
# @see { Jortt::Client.invoice }
|
11
|
+
class Invoice
|
12
|
+
|
13
|
+
def initialize(config, id)
|
14
|
+
@config = config
|
15
|
+
@id = id
|
16
|
+
end
|
17
|
+
|
18
|
+
##
|
19
|
+
# Sends an Invoice using the POST /invoices/id/:invoice_id/send endpoint.
|
20
|
+
#
|
21
|
+
# @example
|
22
|
+
# Jortt::Client.invoice(:invoice_id).send(
|
23
|
+
# mail_data: {
|
24
|
+
# to: 'ben@jortt.nl', # optional
|
25
|
+
# subject: 'Thank you for your assignment', # optional
|
26
|
+
# body: 'I hereby send you the invoice', # optional
|
27
|
+
# },
|
28
|
+
# invoice_date: Date.today, # optional
|
29
|
+
# payment_term: 7, # optional
|
30
|
+
# language: 'nl', # optional
|
31
|
+
# send_method: 'email', # optional
|
32
|
+
# )
|
33
|
+
def send_invoice(payload = {})
|
34
|
+
resource = RestClient::Resource.new(
|
35
|
+
"#{config.base_url}/invoices/id/#{id}/send",
|
36
|
+
user: config.app_name,
|
37
|
+
password: config.api_key,
|
38
|
+
)
|
39
|
+
resource.post(JSON.generate(payload)) do |response|
|
40
|
+
JSON.parse(response.body)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
attr_reader :config, :id
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rest-client'
|
3
|
+
|
4
|
+
module Jortt # :nodoc:
|
5
|
+
class Client # :nodoc:
|
6
|
+
|
7
|
+
##
|
8
|
+
# Exposes the operations available for a collection of invoices.
|
9
|
+
#
|
10
|
+
# @see { Jortt::Client.invoices }
|
11
|
+
class Invoices
|
12
|
+
|
13
|
+
def initialize(config)
|
14
|
+
@resource = RestClient::Resource.new(
|
15
|
+
"#{config.base_url}/invoices",
|
16
|
+
user: config.app_name,
|
17
|
+
password: config.api_key,
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
##
|
22
|
+
# Creates an Invoice using the POST /invoices endpoint.
|
23
|
+
# See https://app.jortt.nl/api-documentatie#factuur-aanmaken
|
24
|
+
#
|
25
|
+
# @example
|
26
|
+
# Jortt::Client.invoices.create(
|
27
|
+
# customer_id: 'customer_id', # optional
|
28
|
+
# delivery_period: '31-12-2015', # optional
|
29
|
+
# reference: 'reference', # optional
|
30
|
+
# line_items: [{
|
31
|
+
# vat: 21, # mandatory, percentage
|
32
|
+
# amount: 499, # mandatory, ex vat
|
33
|
+
# quantity: 4, # mandatory
|
34
|
+
# description: 'Your Thinkas' # mandatory
|
35
|
+
# }]
|
36
|
+
# )
|
37
|
+
def create(payload)
|
38
|
+
resource.post(JSON.generate('invoice' => payload)) do |response|
|
39
|
+
JSON.parse(response.body)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
attr_reader :resource
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
data/lib/jortt/client/version.rb
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Jortt::Client::Customers do
|
5
|
+
let(:customers) do
|
6
|
+
described_class.new(
|
7
|
+
double(base_url: 'foo', app_name: 'app', api_key: 'secret'),
|
8
|
+
)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#create' do
|
12
|
+
let(:request_body) { JSON.generate(customer: {line_items: []}) }
|
13
|
+
let(:response_body) { JSON.generate(customer_id: 'abc') }
|
14
|
+
subject { customers.create(line_items: []) }
|
15
|
+
before do
|
16
|
+
stub_request(:post, 'http://app:secret@foo/customers').
|
17
|
+
with(body: request_body).
|
18
|
+
to_return(status: 200, body: response_body)
|
19
|
+
end
|
20
|
+
it { should eq('customer_id' => 'abc') }
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#search' do
|
24
|
+
subject { customers.search('terms') }
|
25
|
+
before do
|
26
|
+
stub_request(:get, 'http://app:secret@foo/customers?query=terms').
|
27
|
+
to_return(status: 200, body: '{"customers": []}')
|
28
|
+
end
|
29
|
+
it { should eq('customers' => []) }
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Jortt::Client::Invoice do
|
5
|
+
let(:invoice) do
|
6
|
+
described_class.new(
|
7
|
+
double(base_url: 'foo', app_name: 'app', api_key: 'secret'),
|
8
|
+
'bar',
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#send_invoice' do
|
13
|
+
let(:request_body) { JSON.generate(mail_data: {to: 'ben@jortt.nl'}) }
|
14
|
+
let(:response_body) { JSON.generate(invoice_number: '2016-001') }
|
15
|
+
subject { invoice.send_invoice(mail_data: {to: 'ben@jortt.nl'}) }
|
16
|
+
before do
|
17
|
+
stub_request(:post, 'http://app:secret@foo/invoices/id/bar/send').
|
18
|
+
with(body: request_body).
|
19
|
+
to_return(status: 200, body: response_body)
|
20
|
+
end
|
21
|
+
it { should eq('invoice_number' => '2016-001') }
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Jortt::Client::Invoices do
|
5
|
+
let(:invoices) do
|
6
|
+
described_class.new(
|
7
|
+
double(base_url: 'foo', app_name: 'app', api_key: 'secret'),
|
8
|
+
)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#create' do
|
12
|
+
let(:request_body) { JSON.generate(invoice: {line_items: []}) }
|
13
|
+
let(:response_body) { JSON.generate(invoice_id: 'abc') }
|
14
|
+
subject { invoices.create(line_items: []) }
|
15
|
+
before do
|
16
|
+
stub_request(:post, 'http://app:secret@foo/invoices').
|
17
|
+
with(body: request_body).
|
18
|
+
to_return(status: 200, body: response_body)
|
19
|
+
end
|
20
|
+
it { should eq('invoice_id' => 'abc') }
|
21
|
+
end
|
22
|
+
end
|
data/spec/jortt/client_spec.rb
CHANGED
@@ -28,16 +28,17 @@ describe Jortt::Client do
|
|
28
28
|
|
29
29
|
describe '#customers' do
|
30
30
|
subject { client.customers }
|
31
|
-
it { should be_instance_of(described_class::
|
32
|
-
its(:singular) { should eq(:customer) }
|
33
|
-
its(:plural) { should eq(:customers) }
|
31
|
+
it { should be_instance_of(described_class::Customers) }
|
34
32
|
end
|
35
33
|
|
36
34
|
describe '#invoices' do
|
37
35
|
subject { client.invoices }
|
38
|
-
it { should be_instance_of(described_class::
|
39
|
-
|
40
|
-
|
36
|
+
it { should be_instance_of(described_class::Invoices) }
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#invoice' do
|
40
|
+
subject { client.invoice('foo') }
|
41
|
+
it { should be_instance_of(described_class::Invoice) }
|
41
42
|
end
|
42
43
|
end
|
43
44
|
end
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jortt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bob Forma
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2016-
|
14
|
+
date: 2016-07-05 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rest-client
|
@@ -75,28 +75,28 @@ dependencies:
|
|
75
75
|
requirements:
|
76
76
|
- - "~>"
|
77
77
|
- !ruby/object:Gem::Version
|
78
|
-
version: 3.4
|
78
|
+
version: '3.4'
|
79
79
|
type: :development
|
80
80
|
prerelease: false
|
81
81
|
version_requirements: !ruby/object:Gem::Requirement
|
82
82
|
requirements:
|
83
83
|
- - "~>"
|
84
84
|
- !ruby/object:Gem::Version
|
85
|
-
version: 3.4
|
85
|
+
version: '3.4'
|
86
86
|
- !ruby/object:Gem::Dependency
|
87
87
|
name: rspec-its
|
88
88
|
requirement: !ruby/object:Gem::Requirement
|
89
89
|
requirements:
|
90
90
|
- - "~>"
|
91
91
|
- !ruby/object:Gem::Version
|
92
|
-
version: 1.2
|
92
|
+
version: '1.2'
|
93
93
|
type: :development
|
94
94
|
prerelease: false
|
95
95
|
version_requirements: !ruby/object:Gem::Requirement
|
96
96
|
requirements:
|
97
97
|
- - "~>"
|
98
98
|
- !ruby/object:Gem::Version
|
99
|
-
version: 1.2
|
99
|
+
version: '1.2'
|
100
100
|
- !ruby/object:Gem::Dependency
|
101
101
|
name: webmock
|
102
102
|
requirement: !ruby/object:Gem::Requirement
|
@@ -131,14 +131,14 @@ dependencies:
|
|
131
131
|
requirements:
|
132
132
|
- - "~>"
|
133
133
|
- !ruby/object:Gem::Version
|
134
|
-
version: 1.1
|
134
|
+
version: '1.1'
|
135
135
|
type: :development
|
136
136
|
prerelease: false
|
137
137
|
version_requirements: !ruby/object:Gem::Requirement
|
138
138
|
requirements:
|
139
139
|
- - "~>"
|
140
140
|
- !ruby/object:Gem::Version
|
141
|
-
version: 1.1
|
141
|
+
version: '1.1'
|
142
142
|
description:
|
143
143
|
email:
|
144
144
|
- bforma@zilverline.com
|
@@ -160,11 +160,15 @@ files:
|
|
160
160
|
- jortt.gemspec
|
161
161
|
- lib/jortt.rb
|
162
162
|
- lib/jortt/client.rb
|
163
|
-
- lib/jortt/client/
|
163
|
+
- lib/jortt/client/customers.rb
|
164
|
+
- lib/jortt/client/invoice.rb
|
165
|
+
- lib/jortt/client/invoices.rb
|
164
166
|
- lib/jortt/client/version.rb
|
165
|
-
- spec/
|
166
|
-
- spec/jortt/client/
|
167
|
+
- spec/jortt/client/customers_spec.rb
|
168
|
+
- spec/jortt/client/invoice_spec.rb
|
169
|
+
- spec/jortt/client/invoices_spec.rb
|
167
170
|
- spec/jortt/client_spec.rb
|
171
|
+
- spec/jortt_spec.rb
|
168
172
|
- spec/spec_helper.rb
|
169
173
|
homepage: https://app.jortt.nl/api-documentatie
|
170
174
|
licenses:
|
@@ -191,7 +195,10 @@ signing_key:
|
|
191
195
|
specification_version: 4
|
192
196
|
summary: jortt.nl REST API client
|
193
197
|
test_files:
|
194
|
-
- spec/
|
195
|
-
- spec/jortt/client/
|
198
|
+
- spec/jortt/client/customers_spec.rb
|
199
|
+
- spec/jortt/client/invoice_spec.rb
|
200
|
+
- spec/jortt/client/invoices_spec.rb
|
196
201
|
- spec/jortt/client_spec.rb
|
202
|
+
- spec/jortt_spec.rb
|
197
203
|
- spec/spec_helper.rb
|
204
|
+
has_rdoc:
|
@@ -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
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe Jortt::Client::Resource do
|
5
|
-
let(:resource) do
|
6
|
-
described_class.new(
|
7
|
-
double('client', base_url: 'foo', app_name: 'app', api_key: 'secret'),
|
8
|
-
:person,
|
9
|
-
:people,
|
10
|
-
)
|
11
|
-
end
|
12
|
-
|
13
|
-
describe '#search' do
|
14
|
-
subject { resource.search('terms') }
|
15
|
-
before do
|
16
|
-
stub_request(:get, 'http://app:secret@foo/people?query=terms').
|
17
|
-
to_return(status: 200, body: '{"people": []}')
|
18
|
-
end
|
19
|
-
it { should eq('people' => []) }
|
20
|
-
end
|
21
|
-
|
22
|
-
describe '#create' do
|
23
|
-
subject { resource.create(foo: :bar) }
|
24
|
-
before do
|
25
|
-
stub_request(:post, 'http://app:secret@foo/people').
|
26
|
-
with(body: '{"person":{"foo":"bar"}}').
|
27
|
-
to_return(status: 201, body: '{"person_id": "123"}')
|
28
|
-
end
|
29
|
-
it { should eq('person_id' => '123') }
|
30
|
-
end
|
31
|
-
end
|