如何在ruby中添加带有多个标签的Delicious帖子

时间:2012-01-30 12:06:29

标签: ruby delicious-api

如何添加包含多个标记的帖子?

我这样做。该帖子已添加到我的Delicious系列中,但没有标签。

  

要求'www / delicious'

     

d_api = WWW :: Delicious.new('用户名','密码')

     

d_api.posts_add(:tags =>“tools,ruby,online”,:url =>   'http://rubular.com/',:title => 'Rubular',:notes =>'Ruby常规   表达式编辑器')

我目前正在使用www/Delicious gem,但我愿意接受其他建议。

我也试试

  

:标签=> [ “工具”, “红宝石”, “在线”]

或事件使用构造函数

  

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

但结果与标签混合在一个Delicious screenshot of the tag

相同

感谢

5 个答案:

答案 0 :(得分:1)

Delicious API with HTTParty Gem代码的启发,我创建了一个类似

的类
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

然后我可以这样称呼它:

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

答案 1 :(得分:0)

如果您查看WWW::Delicious::Post的API,则标记是实例属性。我的猜测是它是一个数组。尝试:

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

它可能是一个Tag对象数组,所以另外要尝试的是:

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

答案 2 :(得分:0)

奇怪的是,有效的是:

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

一个数组,其中一个条目是以逗号分隔的标记列表。

答案 3 :(得分:0)

作为替代方案,Temboo SDK(包含Ruby以及其他几种语言)包括Delicious API的方法以及100多个其他公共API。 AddBookmark方法支持多个标记:只提供以逗号分隔的列表作为输入值。

查看https://www.temboo.com/library/Library/Delicious/AddBookmark/

(完全披露:我在Temboo工作)

答案 4 :(得分:0)

我创建了delicious gem,这是Delicious oAuth API的ruby包装器。您可以轻松添加书签:

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'