Class: RubySesame::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-sesame.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, query_server_information = false) ⇒ Server

Initialize a Server object at the given URL. Sesame uses a stateless REST protocol, so this will not actually do anything over the network unless query_server_information is true. Loads the protocol version and repositories available on the server if it is.



63
64
65
66
67
68
69
70
# File 'lib/ruby-sesame.rb', line 63

def initialize(url, query_server_information=false)
  url = url + "/" unless url[-1..-1] == "/"
  @url = url

  if query_server_information
    query_version
  end
end

Instance Attribute Details

#repositoriesObject (readonly)

Returns the value of attribute repositories.



54
55
56
# File 'lib/ruby-sesame.rb', line 54

def repositories
  @repositories
end

#urlObject (readonly)

Returns the value of attribute url.



54
55
56
# File 'lib/ruby-sesame.rb', line 54

def url
  @url
end

Instance Method Details

#protocol_versionObject



77
78
79
# File 'lib/ruby-sesame.rb', line 77

def protocol_version
  @protocol_version || query_version
end

#query_repositoriesObject



90
91
92
93
94
95
96
# File 'lib/ruby-sesame.rb', line 90

def query_repositories
  easy = Curl::Easy.new
  easy.headers["Accept"] = DATA_TYPES[:JSON]
  easy.url = @url + "repositories"
  easy.http_get
  @repositories = JSON.parse(easy.body_str)["results"]["bindings"].map{|x| Repository.new(self, x) }
end

#query_versionObject



73
74
75
# File 'lib/ruby-sesame.rb', line 73

def query_version
  @protocol_version = Curl::Easy.http_get(@url + "protocol").body_str.to_i
end

#repository(id) ⇒ Object

Get a Repository by id. Returns the first repository if there is more than one.



86
87
88
# File 'lib/ruby-sesame.rb', line 86

def repository(id)
  self.repositories.select {|r| r.id == id}.first
end