Class Simpy::Client
In: lib/simpy.rb
Parent: ClientBase

A Simpy client interface

Description

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.

Usage

Getting five links that match a query string

  client.links "test", 5

Generating an array of titles from a set of links that match a query

  client["test"].map {|l| l["title"]}

Adding a link

  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")

Deleting a link

  client.deleteLink client.links[0]
  client.deleteLink "http://www.simpy.com"

Methods

<<   []   addLink   deleteLink   links   removeTag   renameTag   tags  

Public Instance methods

<<(*args)

Alias for addLink

[](query = nil, limit = nil)

Alias for links

Add a link to Simpy

Description

This method adds a link to the user’s Simpy account.

Args

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.

Usage

  client.addLink "Simpy", "http://www.simpy.com", ["tag"]

  client << Simpy::Link.new("Simpy", "http://www.simpy.com", ["tag"])

[Source]

     # 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

Description

This method deletes a link from the user’s Simpy account.

Args

link:This argument can be either a string containing the URL of the link to delete, a Link instance.

Usage

  client.deleteLink client.links[0]
  client.deleteLink "http://www.simpy.com"

[Source]

     # 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

Description

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.

Args

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.

Usage

  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

[Source]

     # 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

Description

This method removes a Simpy tag from the user’s account.

Issues

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.

Args

tag:The tag to remove from the user’s Simpy account

Usage

  client.removeTag "tag"

[Source]

     # File lib/simpy.rb, line 701
701:     def removeTag tag
702:       command "RemoveTag", "tag" => tag
703:     end

Rename a Simpy tag

Description

This method renames a Simpy tag in the user’s account.

Args

from:The tag to rename.
to:The new name for the tag.

Usage

client.renameTag "test1", "test2"

[Source]

     # 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

Description

This method returns a hash table that includes tag names and the number of links associated with each tag.

Args

limit:Optionally specify the maximum number of tags to return.

Usage

  client.tags(5)

  client.tags["test"]
  # => 3

[Source]

     # 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

[Validate]