Class: WWW::Delicious::Post
- Defined in:
- lib/www/delicious/post.rb
Instance Attribute Summary collapse
-
#notes ⇒ Object
The extended description for the Post.
-
#others ⇒ Object
The number of other users who saved this Post.
-
#replace ⇒ Object
Returns the value for
replace
attribute. -
#shared ⇒ Object
Returns the value for
shared
attribute. -
#tags ⇒ Object
Tags for this Post.
-
#time ⇒ Object
Timestamp this Post was last saved at.
-
#title ⇒ Object
The title of the Post.
-
#uid ⇒ Object
The unique Id for this Post.
-
#url ⇒ Object
The Post URL.
Class Method Summary collapse
-
.from_rexml(element) ⇒ Object
Creates and returns new instance from a REXML
element
.
Instance Method Summary collapse
-
#api_valid? ⇒ Boolean
Returns whether this object is valid for an API request.
-
#to_params ⇒ Object
Returns a params-style representation suitable for API calls.
Methods inherited from Element
Constructor Details
This class inherits a constructor from WWW::Delicious::Element
Instance Attribute Details
#notes ⇒ Object
The extended description for the Post
32 33 34 |
# File 'lib/www/delicious/post.rb', line 32 def notes @notes end |
#others ⇒ Object
The number of other users who saved this Post
35 36 37 |
# File 'lib/www/delicious/post.rb', line 35 def others @others end |
#replace ⇒ Object
Returns the value for replace
attribute.
47 48 49 |
# File 'lib/www/delicious/post.rb', line 47 def replace @replace end |
#shared ⇒ Object
Returns the value for shared
attribute.
50 51 52 |
# File 'lib/www/delicious/post.rb', line 50 def shared @shared end |
#tags ⇒ Object
Tags for this Post
41 42 43 |
# File 'lib/www/delicious/post.rb', line 41 def @tags end |
#time ⇒ Object
Timestamp this Post was last saved at
44 45 46 |
# File 'lib/www/delicious/post.rb', line 44 def time @time end |
#title ⇒ Object
The title of the Post
29 30 31 |
# File 'lib/www/delicious/post.rb', line 29 def title @title end |
#uid ⇒ Object
The unique Id for this Post
38 39 40 |
# File 'lib/www/delicious/post.rb', line 38 def uid @uid end |
Class Method Details
.from_rexml(element) ⇒ Object
Creates and returns new instance from a REXML element
.
Implements Element#from_rexml.
104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/www/delicious/post.rb', line 104 def from_rexml(element) raise ArgumentError, "`element` expected to be a `REXML::Element`" unless element.kind_of? REXML::Element self.new do |instance| instance.url = element.if_attribute_value(:href) { |v| URI.parse(v) } instance.title = element.if_attribute_value(:description) instance.notes = element.if_attribute_value(:extended) instance.others = element.if_attribute_value(:others).to_i # cast nil to 0 instance.uid = element.if_attribute_value(:hash) instance. = element.if_attribute_value(:tag) { |v| v.split(' ') }.to_a instance.time = element.if_attribute_value(:time) { |v| Time.parse(v) } instance.shared = element.if_attribute_value(:shared) { |v| v == 'no' ? false : true } end end |
Instance Method Details
#api_valid? ⇒ Boolean
Returns whether this object is valid for an API request.
To be valid url
and title
must not be empty.
Examples
post = WWW::Delicious::Post.new(:url => 'http://localhost', :title => 'foo')
post.api_valid?
# => true
post = WWW::Delicious::Post.new(:url => 'http://localhost')
post.api_valid?
# => false
92 93 94 |
# File 'lib/www/delicious/post.rb', line 92 def api_valid? return !(url.nil? or url.empty? or title.nil? or title.empty?) end |
#to_params ⇒ Object
Returns a params-style representation suitable for API calls.
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/www/delicious/post.rb', line 64 def to_params() params = {} params[:url] = url params[:description] = title params[:extended] = notes if notes params[:shared] = shared params[:tags] = params[:replace] = replace params[:dt] = WWW::Delicious::TIME_CONVERTER.call(time) if time params end |