Class | Simpy::Client |
In: |
lib/simpy.rb
|
Parent: | ClientBase |
A Simpy client interface
This class provides an interface to the Simpy web system. It includes native Ruby methods that wrap individual Simpy REST API calls. The methods are designed to enable developers to effectively leverage Ruby and minimize verbosity while interacting with Simpy.
This class inherits Simpy::ClientBase and uses Simpy::ClientBase.command to interact with the Simpy server. At present, it supports many of Simpy’s link and tag features, but it does not yet support notes or watchlists.
client.links "test", 5
client["test"].map {|l| l["title"]}
client << {"href" => "http://www.simpy.com", "title" => "The Simpy Web Site", "accessType" => 1) client << Simpy::Link.new("The Simpy Web Site", "http://www.simpy.com", ["tagA", "tagB"], "This is a note", "The Simpy Web Site")
client.deleteLink client.links[0] client.deleteLink "http://www.simpy.com"
Add a link to Simpy
This method adds a link to the user’s Simpy account.
args: | This method accepts either a single Link instance, or the arguments required by Simpy::Link#new. If multiple arguments are provided, they are used to instantiate a new Link instance which is then used for the operation. |
client.addLink "Simpy", "http://www.simpy.com", ["tag"] client << Simpy::Link.new("Simpy", "http://www.simpy.com", ["tag"])
# File lib/simpy.rb, line 602 602: def addLink *args 603: command "SaveLink", (args.length > 1 ? Link.new(*args) : args[0]).values 604: end
Delete a link from a Simpy account
This method deletes a link from the user’s Simpy account.
link: | This argument can be either a string containing the URL of the link to delete, a Link instance. |
client.deleteLink client.links[0] client.deleteLink "http://www.simpy.com"
# File lib/simpy.rb, line 623 623: def deleteLink link 624: command "DeleteLink", "href" => case link 625: when String then link 626: when Link then link["href"] 627: end 628: end
Get links from Simpy
This method returns an array of links acquired from the Simpy server. When called without an argument, it will return all links. A link query and a limit can optionally be specified.
query: | The query is used to filter links from Simpy. This can be either a string, a date, or a date range. If a date range is provided, Simpy will return all links added within that range. If a single date is provided, Simpy will return all links added on that date. If a string is provided, Simpy will return all links that match the string. Simpy’s search syntax can be used in the string. |
limit: | The number of links to acquire from Simpy. If no value is provided for this argument, all links that match the query will be returned. |
client.links.each {|l| puts l["href"]} client.links Time.now, 5 client[Time.now] client.links "title:Paris tags:map" client["title:Paris tags:map"] client.links Time.mktime(2006, 05, 12)..Time.now
# File lib/simpy.rb, line 568 568: def links query = nil, limit = nil 569: REXML::XPath.match(command("GetLinks", case query 570: when Time 571: {"date" => query.to_simpy} 572: when String 573: {"q" => query} 574: when Range 575: {"afterDate" => query.begin.to_simpy, "beforeDate" => query.last.to_simpy} 576: else {} 577: end.update("limit" => limit)), "links/link").map do |e| 578: Simpy::Link.parse e 579: end 580: end
Remove a Simpy tag
This method removes a Simpy tag from the user’s account.
During tests, I have found that this feature of the Simpy REST API doesn’t seem to work consistently. It may just be the way I am trying to use it. I haven’t been able to identify any pattern or any reason for why when this fails. I may update this method in the future if I discover the source of the problem.
tag: | The tag to remove from the user’s Simpy account |
client.removeTag "tag"
# File lib/simpy.rb, line 701 701: def removeTag tag 702: command "RemoveTag", "tag" => tag 703: end
Rename a Simpy tag
This method renames a Simpy tag in the user’s account.
from: | The tag to rename. |
to: | The new name for the tag. |
client.renameTag "test1", "test2"
# File lib/simpy.rb, line 674 674: def renameTag from, to 675: command "RenameTag", "fromTag" => from, "toTag" => to 676: end
Get tags from a Simpy account
This method returns a hash table that includes tag names and the number of links associated with each tag.
limit: | Optionally specify the maximum number of tags to return. |
client.tags(5) client.tags["test"] # => 3
# File lib/simpy.rb, line 649 649: def tags limit = nil 650: Hash[*REXML::XPath.match( 651: command("GetTags", "limit" => limit), "//tag").map do |e| 652: [e.attributes["name"], e.attributes["count"]] 653: end.flatten] 654: end