Class: IClassify::Client
- Inherits:
-
Object
- Object
- IClassify::Client
- Defined in:
- lib/iclassify-interface/client.rb
Constant Summary collapse
- UUID_REGEX =
/^[[:xdigit:]]{8}[:-][[:xdigit:]]{4}[:-][[:xdigit:]]{4}[:-][[:xdigit:]]{4}[:-][[:xdigit:]]{12}$/
Instance Method Summary collapse
- #delete_node(node) ⇒ Object
- #get_node(node_id) ⇒ Object
-
#initialize(service_url, username, password) ⇒ Client
constructor
A new instance of Client.
- #make_url(method, params) ⇒ Object
- #search(query, attribs = []) ⇒ Object
- #update_node(node) ⇒ Object
Constructor Details
#initialize(service_url, username, password) ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 17 |
# File 'lib/iclassify-interface/client.rb', line 12 def initialize(service_url, username, password) service_url = "#{service_url}/rest" unless service_url =~ /rest$/ @url = URI.parse(service_url) @username = username @password = password end |
Instance Method Details
#delete_node(node) ⇒ Object
45 46 47 |
# File 'lib/iclassify-interface/client.rb', line 45 def delete_node(node) delete_rest("nodes/#{node.node_id}") end |
#get_node(node_id) ⇒ Object
33 34 35 |
# File 'lib/iclassify-interface/client.rb', line 33 def get_node(node_id) IClassify::Node.new(:xml, get_rest("nodes/#{node_id}")) end |
#make_url(method, params) ⇒ Object
19 20 21 22 |
# File 'lib/iclassify-interface/client.rb', line 19 def make_url(method, params) params[:appid] = @appid super method, params end |
#search(query, attribs = []) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/iclassify-interface/client.rb', line 24 def search(query, attribs=[]) raise ArgumentError, "Attributes must be given as a list!" unless attribs.kind_of?(Array) querystring = "search" querystring << "?q=#{URI.escape(query)}" querystring << "&a=#{URI.escape(attribs.join(','))}" if attribs.length > 0 results = get_rest(querystring, "text/yaml") node_array = YAML.load(results).collect { |n| IClassify::Node.new(:yaml, n) } end |
#update_node(node) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/iclassify-interface/client.rb', line 37 def update_node(node) if node.node_id put_rest("nodes/#{node.node_id}", node.to_xml) else post_rest("nodes", node.to_xml) end end |