Class: RubySesame::Server
- Inherits:
-
Object
- Object
- RubySesame::Server
- Defined in:
- lib/ruby-sesame.rb
Instance Attribute Summary collapse
-
#repositories ⇒ Object
readonly
Returns the value of attribute repositories.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(url, query_server_information = false) ⇒ Server
constructor
Initialize a Server object at the given URL.
- #protocol_version ⇒ Object
- #query_repositories ⇒ Object
- #query_version ⇒ Object
-
#repository(id) ⇒ Object
Get a Repository by id.
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
#repositories ⇒ Object (readonly)
Returns the value of attribute repositories.
54 55 56 |
# File 'lib/ruby-sesame.rb', line 54 def repositories @repositories end |
#url ⇒ Object (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_version ⇒ Object
77 78 79 |
# File 'lib/ruby-sesame.rb', line 77 def protocol_version @protocol_version || query_version end |
#query_repositories ⇒ Object
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_version ⇒ Object
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 |