Class: Rflak::Comment

Inherits:
DummyEntry show all
Defined in:
lib/comment.rb

Overview

Class represents single comment assigned to ‘flak’

Constant Summary collapse

ATTR_LIST =
[:user, :permalink, :timestamp, :time, :text, :datetime, :source, :data, :subsource,
  :url, :related_id
]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Comment

Returns a new instance of Comment.



21
22
23
24
25
# File 'lib/comment.rb', line 21

def initialize(options = {})
  options.each_pair do |key, value|
    send("#{ key }=", value)
  end
end

Class Method Details

.create(entry, user, content) ⇒ Object

Create new comment entry. Method raises NotAuthorized exception when passed user is not authorized. As entry parameter method takes Entry object or its id value. Content is passed as simply text message. When new comment is created true is returned otherwise returns false

entry

Entry || Fixnum

user

User

returns

Boolean

Raises:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/comment.rb', line 38

def self.create(entry, user, content)
  raise NotAuthorized.new('Not authorized') unless user.authorized?

  url = URI.parse('http://api.flaker.pl/api/type:submit')
  post = Net::HTTP::Post.new(url.path)
  post.basic_auth(user., user.api_key)

  if entry.kind_of?(Entry)
    post.set_form_data('text' => "@#{ entry.id } #{ content }")
  else
    post.set_form_data('text' => "@#{ entry } #{ content }")
  end

  response = Net::HTTP.start(url.host,url.port) do |http|
    http.request(post)
  end
  response.code.to_i == 200
end