Question

How can I add a post with more than one tag?

I'm doing this. The post is added to my Delicious collection but without tags.

require 'www/delicious'

d_api = WWW::Delicious.new('username', 'password')

d_api.posts_add(:tags=> "tools,ruby,online",:url => 'http://rubular.com/', :title => 'Rubular', :notes=>'a Ruby regular expression editor')

I'm currently using www/Delicious gem but I'm open to other suggestion.

I also try the

:tags=> ["tools","ruby","online"]

or event use the constructor

tag = WWW::Delicious::Tag.new(:name => "tools")

but the result is the same the tags are mixted in oneDelicious screenshot of the tag

thanks

Was it helpful?

Solution

Inspired by Delicious API with HTTParty Gem code I create a class like this

require 'rubygems'
require 'httparty'

class Delicious
  include HTTParty
  base_uri 'https://api.del.icio.us/v1'

  def initialize(auth)
    @auth = auth
  end

  # query params that filter the posts are:
  #   url      = (required) the url of the item.
  #   description= (required) the description of the item. 
  #   extended     = (optional) notes for the item.
  #   tags         = (optional) tags for the item (comma delimited).
  #   dt       = {CCYY-MM-DDThh:mm:ssZ}(optional) datestamp of the item (format "CCYY-MM-DDThh:mm:ssZ").
  #   replace  = no(optional) don't replace post if given url has already been posted. 
  #   shared   = no(optional) make the item private
  def add(options={}))
    options.merge!({:basic_auth => @auth})
    self.class.get('/posts/add', options)
  end
end

Then I can call it like this:

delicious = Delicious.new( :username => 'myUsername', :password => 'myPassword' )
puts delicious.add(:query => {:url => 'http://rubular.com/', :description => 'Rubular', :tags => "tools,ruby,online"})

OTHER TIPS

If you look at the API for WWW::Delicious::Post, tags are an instance attribute. My guess is that it is an array. Try:

d_api.posts_add(:tags=>["tools","ruby","online"],:url => 'http://rubular.com/', :title => 'Rubular', :notes=>'a Ruby regular expression editor')

It's possible it's an array of Tag objects, so another thing to try is:

my_tags = ["tools","ruby","online"].map {|t| WWW::Delicious::Tag.new(t)}
d_api.posts_add(:tags => my_tags,:url => 'http://rubular.com/', :title => 'Rubular', :notes=>'a Ruby regular expression editor')

Strangely, what works is this:

delicious.posts_add(
  :url   => 'http://www.test2.com',
  :title => 'test',
  :tags => ['test1, test2']
)

An array with a single entry being a comma-separated tag list.

As an alternative, the Temboo SDK (which comes in Ruby, as well as several other languages) includes methods for the Delicious API in addition to 100+ other public APIs. The AddBookmark method supports multiple tags: just provide a comma-separated list as the input value.

Take a look at https://www.temboo.com/library/Library/Delicious/AddBookmark/

(Full disclosure: I work at Temboo)

I've created delicious gem which is a ruby wrapper for Delicious oAuth API. You can add a bookmark easily:

client = Delicious::Client.new do |c|
  c.access_token = 'your-access-token'
end

client.bookmarks.create tags: 'tools,ruby,online',
                        url: 'http://rubular.com/',
                        description: 'Rubular',
                        extended: 'a Ruby regular expression editor'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top