lib/ldp/client.rb in ldp-0.0.3 vs lib/ldp/client.rb in ldp-0.0.4

- old
+ new

@@ -1,36 +1,33 @@ -require 'faraday' - +## +# LDP client for presenting an ORM on top of an LDP resource module Ldp class Client require 'ldp/client/methods' - include Ldp::Client::Methods - - attr_reader :http def initialize *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 + initialize_http_client *http_client end # Find or initialize a new LDP resource by URI - def find_or_initialize subject - data = get(subject) + def find_or_initialize subject, options = {} + data = get(subject, options = {}) - unless data.is_a? Response - raise "#{subject} is not an LDP Resource" + case + when !data.is_a?(Ldp::Response) + Resource::BinarySource.new self, subject, data + when data.container? + Ldp::Container.new_from_response self, subject, data + when data.resource? + Resource::RdfSource.new self, subject, data + else + Resource::BinarySource.new self, subject, data end - - if data.container? - Container.new self, subject, data - else - Resource.new self, subject, data - end end + def logger + Ldp.logger + end end end