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

发布于 2024-12-29 22:37:58 字数 787 浏览 1 评论 0 原文

如何添加带有多个标签的帖子?

我正在做这个。该帖子已添加到我的美味收藏中,但没有标签。

需要“www/delicious”

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

d_api.posts_add(:tags=> "工具,ruby,在线",:url =>; 'http://rubular.com/', :title =>; 'Rubular', :notes=>'Ruby 常规 表达式编辑器')

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

我也尝试了

:标签=> [“工具”,“ruby”,“在线”]

或事件使用构造函数

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

但结果是相同的,标签混合在一个 标签的美味截图

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

猫卆 2025-01-05 22:37:58

受到 Delicious API with HTTParty Gem 代码的启发,我创建了一个像这样的类

需要“rubygems”
需要“httpparty”

美味类
  包括 HTTParty
  base_uri 'https://api.del.icio.us/v1'

  def 初始化(验证)
    @auth = 验证
  结尾

  # 过滤帖子的查询参数是:
  # url =(必需)该项目的 url。
  #description=(必填)该项目的描述。 
  # 扩展=(可选)该项目的注释。
  # Tags =(可选)项目的标签(以逗号分隔)。
  # dt = {CCYY-MM-DDThh:mm:ssZ}(可选)项目的日期戳(格式“CCYY-MM-DDThh:mm:ssZ”)。
  # Replace = no(可选)如果给定的网址已经发布,则不替换帖子。 
  #共享=否(可选)将项目设为私有
  def 添加(选项={}))
    options.merge!({:basic_auth => @auth})
    self.class.get('/posts/add', 选项)
  结尾
结尾

然后我可以这样称呼它:

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

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"})
_蜘蛛 2025-01-05 22:37:58

如果您查看 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')

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')
貪欢 2025-01-05 22:37:58

奇怪的是,有效的是:

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

一个包含单个条目的数组,该条目是逗号分隔的标签列表。

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.

天赋异禀 2025-01-05 22:37:58

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

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

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

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)

無處可尋 2025-01-05 22:37:58

我创建了 delicious gem,它是 美味的 oAuth API。您可以轻松添加书签:

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'

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'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文