Class: Pinboard::Post

Inherits:
Struct
  • Object
show all
Defined in:
lib/pinboard/post.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Post

Returns a new instance of Post.



10
11
12
13
14
15
16
17
# File 'lib/pinboard/post.rb', line 10

def initialize(attributes={})
  self.time = Util.parse_time(attributes.delete(:time))
  self.tag  = attributes.delete(:tag).split(" ")

  attributes.each do |attribute, value|
    send("#{attribute}=", value) if respond_to?("#{attribute}=")
  end
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description

Returns:

  • (Object)

    the current value of description



2
3
4
# File 'lib/pinboard/post.rb', line 2

def description
  @description
end

#extendedObject

Returns the value of attribute extended

Returns:

  • (Object)

    the current value of extended



2
3
4
# File 'lib/pinboard/post.rb', line 2

def extended
  @extended
end

#hrefObject

Returns the value of attribute href

Returns:

  • (Object)

    the current value of href



2
3
4
# File 'lib/pinboard/post.rb', line 2

def href
  @href
end

#replaceObject

Returns the value of attribute replace

Returns:

  • (Object)

    the current value of replace



2
3
4
# File 'lib/pinboard/post.rb', line 2

def replace
  @replace
end

#sharedObject

Returns the value of attribute shared

Returns:

  • (Object)

    the current value of shared



2
3
4
# File 'lib/pinboard/post.rb', line 2

def shared
  @shared
end

#tagObject

Returns the value of attribute tag

Returns:

  • (Object)

    the current value of tag



2
3
4
# File 'lib/pinboard/post.rb', line 2

def tag
  @tag
end

#timeObject

Returns the value of attribute time

Returns:

  • (Object)

    the current value of time



2
3
4
# File 'lib/pinboard/post.rb', line 2

def time
  @time
end

#toreadObject

Returns the value of attribute toread

Returns:

  • (Object)

    the current value of toread



2
3
4
# File 'lib/pinboard/post.rb', line 2

def toread
  @toread
end

Class Method Details

.all(options = {}) ⇒ Object



3
4
5
6
7
8
# File 'lib/pinboard/post.rb', line 3

def self.all(options={})
  client = Pinboard::Client.new(options)
  posts = client.class.get('/posts/all',
            :basic_auth => options)['posts']['post']
  posts.map { |p| Post.new(Util.symbolize_keys(p)) }
end

Instance Method Details

#api_hash(replace = nil) ⇒ Hash

Creates hash for API (e.g. pass it to ‘/posts/add’)

Parameters:

  • replace (Boolean, nil) (defaults to: nil)

    Overwrite replace attribute if not nil

Returns:

  • (Hash)


36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/pinboard/post.rb', line 36

def api_hash(replace = nil)
  self.replace = replace unless replace.nil?
  {
    url:          href,
    description:  description,
    extended:     extended,
    tags:         tag.join(" "),
    replace:      replace,
    shared:       shared,
    toread:       toread
  }.select { |key, value| ! value.nil? }
end

#to_json(*args) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pinboard/post.rb', line 19

def to_json(*args)
  {
    href:         href,
    description:  description,
    extended:     extended,
    tag:          tag,
    time:         time,
    replace:      replace,
    shared:       shared,
    toread:       toread
  }.to_json(*args)
end