ldp 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 99bebef6b32281c8905d392e0f0fa8d721e68261
4
- data.tar.gz: 5433d136b94341c604498c9ba2e48beeb0e7339c
3
+ metadata.gz: 53b76804d5ae9a00e6d4801434481e5054b451ce
4
+ data.tar.gz: c63c931afd361d37207d88b336daf8c23e5db197
5
5
  SHA512:
6
- metadata.gz: bb175075b93c4d285900ce7699e905e191711cede50853e55b633c79f001e1f40a468eefcedf49ce02c4e4cc207d548f5802574d0d781718cf348df6bcdb2552
7
- data.tar.gz: b3ffc95e6771ba09ebfeb679da4a4351bbb1de5cfbfb382919c16780da40712f41dfcef8f0ae2a73f546961f515b7dcbaf79779a49494a0f7ffeb345a7e4ff07
6
+ metadata.gz: 724f8bda3e97e7fc24dcea133072b6d754ccfb40112edae54973b39f35878619e2973f920308cfa52ae87795ae7a6ffd125a68199a224cd8b625f9f574dd6b62
7
+ data.tar.gz: 0309e7ff339a512828c5c065bd6ff26bed7a283e2b457f3e9ca8e4d57504f73ce6efc6ed76df21433aeb527cb049022e7efddacb3e07f4264edd8e019f9a0d7a
data/lib/ldp.rb CHANGED
@@ -20,6 +20,7 @@ module Ldp
20
20
  class HttpError < RuntimeError; end
21
21
  class BadRequest < HttpError; end # 400
22
22
  class NotFound < HttpError; end # 404
23
+ class Conflict < HttpError; end # 409
23
24
  class Gone < HttpError; end # 410
24
25
  class EtagMismatch < HttpError; end # 412
25
26
 
@@ -14,92 +14,105 @@ module Ldp::Client::Methods
14
14
  end
15
15
 
16
16
  def head url
17
- logger.debug "LDP: HEAD [#{url}]"
18
- resp = http.head do |req|
19
- req.url munge_to_relative_url(url)
17
+ ActiveSupport::Notifications.instrument("http.ldp",
18
+ url: url, name: "HEAD", ldp_client: object_id) do
19
+ resp = http.head do |req|
20
+ req.url munge_to_relative_url(url)
20
21
 
21
- yield req if block_given?
22
- end
22
+ yield req if block_given?
23
+ end
23
24
 
24
- check_for_errors(resp)
25
+ check_for_errors(resp)
26
+ end
25
27
  end
26
28
 
27
29
  # Get a LDP Resource by URI
28
30
  def get url, options = {}
29
- logger.debug "LDP: GET [#{url}]"
30
- resp = http.get do |req|
31
- req.url munge_to_relative_url(url)
32
- prefer_headers = ::Ldp::PreferHeaders.new
31
+ ActiveSupport::Notifications.instrument("http.ldp",
32
+ url: url, name: "GET", ldp_client: object_id) do
33
+ resp = http.get do |req|
34
+ req.url munge_to_relative_url(url)
35
+ prefer_headers = ::Ldp::PreferHeaders.new
36
+
37
+ if options[:minimal]
38
+ prefer_headers.return = "minimal"
39
+ else
40
+ prefer_headers.return = "representation"
41
+ includes = Array(options[:include]).map { |x| Ldp.send("prefer_#{x}") if Ldp.respond_to? "prefer_#{x}" }
42
+ omits = Array(options[:omit]).map { |x| Ldp.send("prefer_#{x}") if Ldp.respond_to? "prefer_#{x}" }
43
+ prefer_headers.include = includes
44
+ prefer_headers.omit = omits
45
+ end
46
+ req.headers["Prefer"] = prefer_headers.to_s
47
+
48
+ yield req if block_given?
49
+ end
33
50
 
34
- if options[:minimal]
35
- prefer_headers.return = "minimal"
51
+ if Ldp::Response.resource? resp
52
+ Ldp::Response.wrap self, resp
36
53
  else
37
- prefer_headers.return = "representation"
38
- includes = Array(options[:include]).map { |x| Ldp.send("prefer_#{x}") if Ldp.respond_to? "prefer_#{x}" }
39
- omits = Array(options[:omit]).map { |x| Ldp.send("prefer_#{x}") if Ldp.respond_to? "prefer_#{x}" }
40
- prefer_headers.include = includes
41
- prefer_headers.omit = omits
54
+ resp
42
55
  end
43
- req.headers["Prefer"] = prefer_headers.to_s
44
56
 
45
- yield req if block_given?
57
+ check_for_errors(resp)
46
58
  end
47
-
48
- if Ldp::Response.resource? resp
49
- Ldp::Response.wrap self, resp
50
- else
51
- resp
52
- end
53
-
54
- check_for_errors(resp)
55
59
  end
56
60
 
57
61
  # Delete a LDP Resource by URI
58
62
  def delete url
59
- logger.debug "LDP: DELETE [#{url}]"
60
- resp = http.delete do |req|
61
- req.url munge_to_relative_url(url)
62
- yield req if block_given?
63
- end
63
+ ActiveSupport::Notifications.instrument("http.ldp",
64
+ url: url, name: "DELETE", ldp_client: object_id) do
65
+ resp = http.delete do |req|
66
+ req.url munge_to_relative_url(url)
67
+ yield req if block_given?
68
+ end
64
69
 
65
- check_for_errors(resp)
70
+ check_for_errors(resp)
71
+ end
66
72
  end
67
73
 
68
74
  # Post TTL to an LDP Resource
69
75
  def post url, body = nil, headers = {}
70
- logger.debug "LDP: POST [#{url}]"
71
- resp = http.post do |req|
72
- req.url munge_to_relative_url(url)
73
- req.headers.merge!(default_headers).merge!(headers)
74
- req.body = body
75
- yield req if block_given?
76
+ ActiveSupport::Notifications.instrument("http.ldp",
77
+ url: url, name: "POST", ldp_client: object_id) do
78
+ resp = http.post do |req|
79
+ req.url munge_to_relative_url(url)
80
+ req.headers.merge!(default_headers).merge!(headers)
81
+ req.body = body
82
+ yield req if block_given?
83
+ end
84
+ check_for_errors(resp)
76
85
  end
77
- check_for_errors(resp)
78
86
  end
79
87
 
80
88
  # Update an LDP resource with TTL by URI
81
89
  def put url, body, headers = {}
82
- logger.debug "LDP: PUT [#{url}]"
83
- resp = http.put do |req|
84
- req.url munge_to_relative_url(url)
85
- req.headers.merge!(default_headers).merge!(headers)
86
- req.body = body
87
- yield req if block_given?
90
+ ActiveSupport::Notifications.instrument("http.ldp",
91
+ url: url, name: "PUT", ldp_client: object_id) do
92
+ resp = http.put do |req|
93
+ req.url munge_to_relative_url(url)
94
+ req.headers.merge!(default_headers).merge!(headers)
95
+ req.body = body
96
+ yield req if block_given?
97
+ end
98
+ check_for_errors(resp)
88
99
  end
89
- check_for_errors(resp)
90
100
  end
91
101
 
92
102
  # Update an LDP resource with TTL by URI
93
103
  def patch url, body, headers = {}
94
- logger.debug "LDP: PATCH [#{url}]"
95
- resp = http.patch do |req|
96
- req.url munge_to_relative_url(url)
97
- req.headers.merge!(default_patch_headers).merge!(headers)
98
- req.body = body
99
- yield req if block_given?
104
+ ActiveSupport::Notifications.instrument("http.ldp",
105
+ url: url, name: "PATCH", ldp_client: object_id) do
106
+ resp = http.patch do |req|
107
+ req.url munge_to_relative_url(url)
108
+ req.headers.merge!(default_patch_headers).merge!(headers)
109
+ req.body = body
110
+ yield req if block_given?
111
+ end
112
+ check_for_errors(resp)
100
113
  end
101
- check_for_errors(resp)
102
114
  end
115
+
103
116
  private
104
117
 
105
118
  def check_for_errors resp
@@ -116,6 +129,8 @@ module Ldp::Client::Methods
116
129
  end
117
130
  when 404
118
131
  Ldp::NotFound.new(resp.body)
132
+ when 409
133
+ Ldp::Conflict.new(resp.body)
119
134
  when 410
120
135
  Ldp::Gone.new(resp.body)
121
136
  when 412
@@ -1,3 +1,3 @@
1
1
  module Ldp
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -34,6 +34,7 @@ describe "Ldp::Client" do
34
34
  stub.get("/test:1") { [200] }
35
35
  stub.get("http://test:8080/abc") { [200] }
36
36
  stub.put("/mismatch_resource") { [412] }
37
+ stub.put("/forbidden_resource") { [403, {}, ''] }
37
38
  stub.put("/conflict_resource") { [409, {}, ''] }
38
39
  stub.get("/deleted_resource") { [410, {}, 'Gone'] }
39
40
  end
@@ -72,6 +73,15 @@ describe "Ldp::Client" do
72
73
  expect(resp.resource?).to be true
73
74
  end
74
75
 
76
+ it "is instrumented" do
77
+ vals = []
78
+ ActiveSupport::Notifications.subscribe('http.ldp') do |name, start, finish, id, payload|
79
+ vals << payload[:name]
80
+ end
81
+ subject.get "a_resource"
82
+ expect(vals).to eq ['GET']
83
+ end
84
+
75
85
  it "should accept a block to change the HTTP request" do
76
86
  expect { |b| subject.get "a_resource", &b }.to yield_control
77
87
  end
@@ -113,6 +123,15 @@ describe "Ldp::Client" do
113
123
  expect(resp.status).to eq(204)
114
124
  end
115
125
 
126
+ it "is instrumented" do
127
+ vals = []
128
+ ActiveSupport::Notifications.subscribe('http.ldp') do |name, start, finish, id, payload|
129
+ vals << payload[:name]
130
+ end
131
+ subject.delete "a_resource"
132
+ expect(vals).to eq ['DELETE']
133
+ end
134
+
116
135
  it "should accept a block to change the HTTP request" do
117
136
  expect { |b| subject.delete "a_resource", &b }.to yield_control
118
137
  end
@@ -125,6 +144,15 @@ describe "Ldp::Client" do
125
144
  expect(resp.headers[:Location]).to eq("http://example.com/a_container/subresource")
126
145
  end
127
146
 
147
+ it "is instrumented" do
148
+ vals = []
149
+ ActiveSupport::Notifications.subscribe('http.ldp') do |name, start, finish, id, payload|
150
+ vals << payload[:name]
151
+ end
152
+ subject.post "a_container"
153
+ expect(vals).to eq ['POST']
154
+ end
155
+
128
156
  it "should set content" do
129
157
  subject.post "a_container", 'foo' do |req|
130
158
  expect(req.body).to eq 'foo'
@@ -166,6 +194,15 @@ describe "Ldp::Client" do
166
194
  expect(resp.status).to eq(204)
167
195
  end
168
196
 
197
+ it "is instrumented" do
198
+ vals = []
199
+ ActiveSupport::Notifications.subscribe('http.ldp') do |name, start, finish, id, payload|
200
+ vals << payload[:name]
201
+ end
202
+ subject.put "a_resource", "some-payload"
203
+ expect(vals).to eq ['PUT']
204
+ end
205
+
169
206
  it "should accept a block to change the HTTP request" do
170
207
  expect { |b| subject.put "a_resource", "some-payload", &b }.to yield_control
171
208
  end
@@ -177,15 +214,19 @@ describe "Ldp::Client" do
177
214
  end
178
215
 
179
216
  describe "error checking" do
180
- it "should check for 409 errors" do
181
- expect { subject.put "conflict_resource", "some-payload" }.to raise_error Ldp::HttpError
217
+ it "checks for other kinds of 4xx errors" do
218
+ expect { subject.put "forbidden_resource", "some-payload" }.to raise_error Ldp::HttpError
219
+ end
220
+
221
+ it "checks for 409 errors" do
222
+ expect { subject.put "conflict_resource", "some-payload" }.to raise_error Ldp::Conflict
182
223
  end
183
224
 
184
- it "should check for 410 errors" do
225
+ it "checks for 410 errors" do
185
226
  expect { subject.get "deleted_resource" }.to raise_error Ldp::Gone
186
227
  end
187
228
 
188
- it "should check for 412 errors" do
229
+ it "checks for 412 errors" do
189
230
  expect { subject.put "mismatch_resource", "some-payload" }.to raise_error Ldp::EtagMismatch
190
231
  end
191
232
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ldp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Beer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-12 00:00:00.000000000 Z
11
+ date: 2015-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -169,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
169
  version: '0'
170
170
  requirements: []
171
171
  rubyforge_project:
172
- rubygems_version: 2.4.5
172
+ rubygems_version: 2.4.5.1
173
173
  signing_key:
174
174
  specification_version: 4
175
175
  summary: Linked Data Platform client library
@@ -183,4 +183,3 @@ test_files:
183
183
  - spec/lib/ldp/resource_spec.rb
184
184
  - spec/lib/ldp/response_spec.rb
185
185
  - spec/spec_helper.rb
186
- has_rdoc: