Class: WWW::Delicious::Post

Inherits:
Element show all
Defined in:
lib/www/delicious/post.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Element

#initialize

Constructor Details

This class inherits a constructor from WWW::Delicious::Element

Instance Attribute Details

#notesObject

The extended description for the Post



32
33
34
# File 'lib/www/delicious/post.rb', line 32

def notes
  @notes
end

#othersObject

The number of other users who saved this Post



35
36
37
# File 'lib/www/delicious/post.rb', line 35

def others
  @others
end

#replaceObject

Returns the value for replace attribute.



47
48
49
# File 'lib/www/delicious/post.rb', line 47

def replace
  @replace
end

#sharedObject

Returns the value for shared attribute.



50
51
52
# File 'lib/www/delicious/post.rb', line 50

def shared
  @shared
end

#tagsObject

Tags for this Post



41
42
43
# File 'lib/www/delicious/post.rb', line 41

def tags
  @tags
end

#timeObject

Timestamp this Post was last saved at



44
45
46
# File 'lib/www/delicious/post.rb', line 44

def time
  @time
end

#titleObject

The title of the Post



29
30
31
# File 'lib/www/delicious/post.rb', line 29

def title
  @title
end

#uidObject

The unique Id for this Post



38
39
40
# File 'lib/www/delicious/post.rb', line 38

def uid
  @uid
end

#urlObject

The Post URL



26
27
28
# File 'lib/www/delicious/post.rb', line 26

def url
  @url
end

Class Method Details

.from_rexml(element) ⇒ Object

Creates and returns new instance from a REXML element.

Implements Element#from_rexml.

Raises:

  • (ArgumentError)


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.tags   = 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

Returns:

  • (Boolean)


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_paramsObject

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]         = tags.join(' ') if tags.respond_to? :join
  params[:replace]      = replace
  params[:dt]           = WWW::Delicious::TIME_CONVERTER.call(time) if time
  params
end