Module: Ldp::Client::Methods
- Included in:
- Ldp::Client
- Defined in:
- lib/ldp/client/methods.rb
Overview
HTTP client methods for making requests to an LDP resource and getting a response back.
Instance Attribute Summary collapse
-
#http ⇒ Object
readonly
Returns the value of attribute http.
Instance Method Summary collapse
-
#delete(url) ⇒ Object
Delete a LDP Resource by URI.
-
#get(url, options = {}) ⇒ Object
Get a LDP Resource by URI.
- #head(url) ⇒ Object
- #initialize_http_client(*http_client) ⇒ Object
-
#patch(url, body, headers = {}) ⇒ Object
Update an LDP resource with TTL by URI.
-
#post(url, body = nil, headers = {}) ⇒ Object
Post TTL to an LDP Resource.
-
#put(url, body, headers = {}) ⇒ Object
Update an LDP resource with TTL by URI.
Instance Attribute Details
#http ⇒ Object (readonly)
Returns the value of attribute http.
7 8 9 |
# File 'lib/ldp/client/methods.rb', line 7 def http @http end |
Instance Method Details
#delete(url) ⇒ Object
Delete a LDP Resource by URI
58 59 60 61 62 63 64 65 66 |
# File 'lib/ldp/client/methods.rb', line 58 def delete url logger.debug "LDP: DELETE [#{url}]" resp = http.delete do |req| req.url munge_to_relative_url(url) yield req if block_given? end check_for_errors(resp) end |
#get(url, options = {}) ⇒ Object
Get a LDP Resource by URI
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/ldp/client/methods.rb', line 28 def get url, = {} logger.debug "LDP: GET [#{url}]" resp = http.get do |req| req.url munge_to_relative_url(url) prefer_headers = ::Ldp::PreferHeaders.new if [:minimal] prefer_headers.return = "minimal" else prefer_headers.return = "representation" includes = Array([:include]).map { |x| Ldp.send("prefer_#{x}") if Ldp.respond_to? "prefer_#{x}" } omits = Array([:omit]).map { |x| Ldp.send("prefer_#{x}") if Ldp.respond_to? "prefer_#{x}" } prefer_headers.include = includes prefer_headers.omit = omits end req.headers["Prefer"] = prefer_headers.to_s yield req if block_given? end if Ldp::Response.resource? resp Ldp::Response.wrap self, resp else resp end check_for_errors(resp) end |
#head(url) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ldp/client/methods.rb', line 16 def head url logger.debug "LDP: HEAD [#{url}]" resp = http.head do |req| req.url munge_to_relative_url(url) yield req if block_given? end check_for_errors(resp) end |
#initialize_http_client(*http_client) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/ldp/client/methods.rb', line 8 def initialize_http_client *http_client if http_client.length == 1 and http_client.first.is_a? Faraday::Connection @http = http_client.first else @http = Faraday.new *http_client end end |
#patch(url, body, headers = {}) ⇒ Object
Update an LDP resource with TTL by URI
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/ldp/client/methods.rb', line 93 def patch url, body, headers = {} logger.debug "LDP: PATCH [#{url}]" resp = http.patch do |req| req.url munge_to_relative_url(url) req.headers.merge!(default_patch_headers).merge!(headers) req.body = body yield req if block_given? end check_for_errors(resp) end |
#post(url, body = nil, headers = {}) ⇒ Object
Post TTL to an LDP Resource
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ldp/client/methods.rb', line 69 def post url, body = nil, headers = {} logger.debug "LDP: POST [#{url}]" resp = http.post do |req| req.url munge_to_relative_url(url) req.headers.merge!(default_headers).merge!(headers) req.body = body yield req if block_given? end check_for_errors(resp) end |
#put(url, body, headers = {}) ⇒ Object
Update an LDP resource with TTL by URI
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/ldp/client/methods.rb', line 81 def put url, body, headers = {} logger.debug "LDP: PUT [#{url}]" resp = http.put do |req| req.url munge_to_relative_url(url) req.headers.merge!(default_headers).merge!(headers) req.body = body yield req if block_given? end check_for_errors(resp) end |