Class: Ldp::Client

Inherits:
Object
  • Object
show all
Includes:
Methods
Defined in:
lib/ldp/client.rb

Defined Under Namespace

Modules: Methods

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Methods

#delete, #get, #post, #put

Constructor Details

#initialize(*http_client) ⇒ Client

Returns a new instance of Client.



12
13
14
15
16
17
18
# File 'lib/ldp/client.rb', line 12

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
end

Instance Attribute Details

#httpObject (readonly)

Returns the value of attribute http.



10
11
12
# File 'lib/ldp/client.rb', line 10

def http
  @http
end

Instance Method Details

#find_or_initialize(subject) ⇒ Object

Find or initialize a new LDP resource by URI



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ldp/client.rb', line 21

def find_or_initialize subject
  data = get(subject)

  unless data.is_a? Response
    raise "#{subject} is not an LDP Resource"
  end

  if data.container?
    Container.new self, subject, data
  else  
    Resource.new self, subject, data
  end
end