ldp 0.0.2 → 0.0.3

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: 85a6fa5082ce00c5b29780ec58bdc216286a5cfe
4
- data.tar.gz: 884e4e0ea864ddf64270eff48c9ae1fca7d7d70b
3
+ metadata.gz: 8ea0daaba00e2614ee8dc9597db049fb7081e3ae
4
+ data.tar.gz: e15f930db252d3dbe6fc03a638f29d703ea53da1
5
5
  SHA512:
6
- metadata.gz: 7061275707496fd834cc225c3fe6ff1ac6eaf7bd8d01ef63677b8fbd30c24c1038a16ee0646c35b59e452f2c988d2c8d908c1c1011c200812dc3b379cbcc7212
7
- data.tar.gz: 40a58400110d941f10212a0b56bfa4cca92d0244372a4e7769a9fdda746c7444de04eefac95cf3f04863d4d31b52ab980b25ed5a2c1562b2424113951a1a4c05
6
+ metadata.gz: 976bd681a8322b5c1a1780b27caf56dd5e65cc09420fea41a2db234fec392c4d63c4ad3eb1f2272c87b9b49927af2bfd98931f60ec1bd623d9b970183a6db2b4
7
+ data.tar.gz: 9de1c9c88954f66e2856cbf6c10a6624396667bb1f5efda080c983d40e382ef855ab42e39372c65c45417221ee1d0d069a52d2444f05e4545d107f10d172503d
data/lib/ldp.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'ldp/version'
2
2
  require 'linkeddata'
3
+ require 'logger'
3
4
 
4
5
  module Ldp
5
6
  RDF::Graph.send(:include, RDF::Isomorphic)
@@ -16,5 +17,15 @@ module Ldp
16
17
  autoload :Orm, 'ldp/orm'
17
18
 
18
19
  class NotFound < StandardError; end
20
+
21
+ class << self
22
+ def logger
23
+ @logger ||= Logger.new(STDOUT).tap do |log|
24
+ log.level = Logger::WARN
25
+ end
26
+ end
27
+
28
+ attr_writer :logger
29
+ end
19
30
 
20
31
  end
@@ -1,4 +1,7 @@
1
1
  module Ldp::Client::Methods
2
+ def logger
3
+ Ldp.logger
4
+ end
2
5
 
3
6
  # Get a LDP Resource by URI
4
7
  def get url
@@ -24,21 +27,29 @@ module Ldp::Client::Methods
24
27
 
25
28
  # Post TTL to an LDP Resource
26
29
  def post url, body = nil, headers = {}
30
+ logger.debug "POST [#{url}] #{body}"
27
31
  http.post do |req|
28
32
  req.url url
29
- req.headers = {"Content-Type"=>"text/turtle"}.merge headers
33
+ req.headers = default_headers.merge headers
30
34
  req.body = body
31
35
  yield req if block_given?
32
36
  end
33
37
  end
34
38
 
35
39
  # Update an LDP resource with TTL by URI
36
- def put url, body
40
+ def put url, body, headers = {}
41
+ logger.debug "PUT [#{url}] #{body}"
37
42
  http.put do |req|
38
43
  req.url url
39
- req.headers['Content-Type'] = 'text/turtle'
44
+ req.headers = default_headers.merge headers
40
45
  req.body = body
41
46
  yield req if block_given?
42
47
  end
43
48
  end
49
+
50
+ private
51
+
52
+ def default_headers
53
+ {"Content-Type"=>"text/turtle"}
54
+ end
44
55
  end
data/lib/ldp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ldp
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -123,6 +123,12 @@ describe "Ldp::Client" do
123
123
  it "should accept a block to change the HTTP request" do
124
124
  expect { |b| subject.put "a_resource", "some-payload", &b }.to yield_control
125
125
  end
126
+
127
+ it "should set headers" do
128
+ subject.put "a_resource", 'payload', {'Content-Type' => 'application/pdf'} do |req|
129
+ expect(req.headers).to eq({ "Content-Type" => "application/pdf" })
130
+ end
131
+ end
126
132
  end
127
133
 
128
134
 
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.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Beer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-21 00:00:00.000000000 Z
11
+ date: 2014-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday