Class: Kasabi::Storage::Client

Inherits:
BaseClient show all
Defined in:
lib/kasabi/api/store.rb

Instance Attribute Summary

Attributes inherited from BaseClient

#apikey, #client, #endpoint

Instance Method Summary collapse

Methods inherited from BaseClient

#client_options, #get, #post, #validate_response

Constructor Details

#initialize(endpoint, options = {}) ⇒ Client

Initialize the store client to work with a specific endpoint

The options hash can contain the following values:

  • :apikey: required. apikey authorized to use the API

  • :client: HTTPClient object instance



12
13
14
# File 'lib/kasabi/api/store.rb', line 12

def initialize(endpoint, options={})
  super(endpoint, options)
end

Instance Method Details

#applied?(update_uri) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
54
55
56
57
58
# File 'lib/kasabi/api/store.rb', line 51

def applied?(update_uri)
  response = get( update_uri, nil, {"Content-Type" => "application/json"} )
  if response.status != 200
      raise "Unable to determine update status. Status: #{response.status}. Message: #{response.content}"
  end
  json = JSON.parse(response.content)
  return json["status"] && json["status"] == "applied"
end

#apply_changeset(cs) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/kasabi/api/store.rb', line 43

def apply_changeset(cs)
  response = post(endpoint, cs, {"Content-Type" => "application/vnd.talis.changeset+xml"} )
  if response.status != 202
    raise "Unable to apply changeset. Status: #{response.status}. Message: #{response.content}"
  end
  return response.content      
end

#store_data(data, content_type = "application/rdf+xml") ⇒ Object

Store triples contained in the provided string



27
28
29
30
31
32
33
# File 'lib/kasabi/api/store.rb', line 27

def store_data(data, content_type="application/rdf+xml")
  response = post(endpoint, data, {"Content-Type" => content_type } )
  if response.status != 202
    raise "Unable to perform request. Status: #{response.status}. Message: #{response.content}"
  end
  return response.content               
end

#store_file(file, content_type = "application/rdf+xml") ⇒ Object

Store the contents of a File (or any IO stream) in the store associated with this dataset The client does not support streaming submissions of data, so the stream will be fully read before data is submitted to the platform

file

an IO object

content_type

mimetype of RDF serialization



20
21
22
23
24
# File 'lib/kasabi/api/store.rb', line 20

def store_file(file, content_type="application/rdf+xml")      
  data = file.read()
  file.close()
  return store_data(data, content_type)
end

#store_uri(uri, content_type = "application/rdf+xml") ⇒ Object



35
36
37
38
39
40
41
# File 'lib/kasabi/api/store.rb', line 35

def store_uri(uri, content_type="application/rdf+xml")
  response = post(endpoint, {"data_uri" => uri }, {"Content-Type" => content_type } )
  if response.status != 202
    raise "Unable to perform request. Status: #{response.status}. Message: #{response.content}"
  end
  return response.content               
end