Class: Rflak::Entry
- Inherits:
-
DummyEntry
- Object
- DummyEntry
- Rflak::Entry
- Defined in:
- lib/entry.rb
Overview
Class represents single entry in flaker.pl website. Entry is assigned with user to wich it belongs and can have many comments assigned to it.
Constant Summary collapse
- ATTR_LIST =
[:user, :permalink, :timestamp, :comments, :time, :text, :title, :has_video, :id, :has_photo, :link, :has_link, :datetime, :source, :data, :subsource, :comments, :parent_id, :is_private, :tags, :is_favorited, :is_bookmark ]
Class Method Summary collapse
-
.create(user, content) ⇒ Object
Create new entry.
Instance Method Summary collapse
-
#bookmark(user) ⇒ Object
Mark entry as bookmark.
-
#comment(user, content) ⇒ Object
Add comment to entry.
-
#good(user) ⇒ Object
Mark entry as good “fajne!”.
-
#initialize(options = {}) ⇒ Entry
constructor
A new instance of Entry.
-
#lans(user) ⇒ Object
Mark entry as lans “lans!”.
-
#not_good(user) ⇒ Object
Mark entry as not good “niefajne!”.
-
#stupid(user) ⇒ Object
Mark entry as stupid “głupie!”.
-
#unbookmark(user) ⇒ Object
Unmark entry as bookmark.
Constructor Details
#initialize(options = {}) ⇒ Entry
Returns a new instance of Entry.
24 25 26 27 28 |
# File 'lib/entry.rb', line 24 def initialize( = {}) .each_pair do |key, value| send("#{ key }=", value) end end |
Class Method Details
.create(user, content) ⇒ Object
Create new entry. Method raises NotAuthorized exception when passed user is not authorized. If operation is successfull new entry will be returned.
Rflak::Entry.create(User.auth('good_login','good_api_key', { 'text' => 'some test content')
- user
-
User
- content
-
Hash
- returns
-
Entry
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/entry.rb', line 41 def self.create(user, content) raise NotAuthorized.new('Not authorized') unless user. url = URI.parse('http://api.flaker.pl/api/type:submit') post = Net::HTTP::Post.new(url.path) post.basic_auth(user.login, user.api_key) post.set_form_data(content) response = Net::HTTP.start(url.host,url.port) do |http| http.request(post) end entry_id = JSON.parse(response.body)['status']['info'].split('/').last Flaker.fetch('show') { |f| f.entry_id(entry_id) }.first end |
Instance Method Details
#bookmark(user) ⇒ Object
Mark entry as bookmark
- user
-
Rflak::User
91 92 93 94 95 96 97 98 99 |
# File 'lib/entry.rb', line 91 def bookmark(user) resp = Flaker.auth_connection(user) do |connection| connection.get("/type:bookmark/action:set/entry_id:#{ self.id }") end if resp['status']['code'].to_i == 200 user.bookmarks end end |
#comment(user, content) ⇒ Object
Add comment to entry. NotAuthorized
exception will be raised if passed user is not authorized.
- user
-
User
- content
-
String
- returns
-
Entry
124 125 126 127 128 129 130 131 132 |
# File 'lib/entry.rb', line 124 def comment(user, content) if Comment.create(self.id, user, content) entry = Flaker.fetch("show") { |f| f.entry_id(self.id) ; f.comments(true) }.first self.comments = entry.comments return entry else self end end |
#good(user) ⇒ Object
Mark entry as good “fajne!”
- user
-
User
60 61 62 |
# File 'lib/entry.rb', line 60 def good(user) Entry.create(user, { 'text' => "@#{ self.id } fajne" }) end |
#lans(user) ⇒ Object
Mark entry as lans “lans!”
- user
-
User
75 76 77 |
# File 'lib/entry.rb', line 75 def lans(user) Entry.create(user, { 'text' => "@#{ self.id } lans" }) end |
#not_good(user) ⇒ Object
Mark entry as not good “niefajne!”
- user
-
User
68 69 70 |
# File 'lib/entry.rb', line 68 def not_good(user) Entry.create(user, { 'text' => "@#{ self.id } niefajne" }) end |
#stupid(user) ⇒ Object
Mark entry as stupid “głupie!”
- user
-
User
83 84 85 |
# File 'lib/entry.rb', line 83 def stupid(user) Entry.create(user, { 'text' => "@#{ self.id } głupie" }) end |
#unbookmark(user) ⇒ Object
Unmark entry as bookmark
- user
-
Rflak::User
105 106 107 108 109 110 111 112 113 |
# File 'lib/entry.rb', line 105 def unbookmark(user) resp = Flaker.auth_connection(user) do |connection| connection.get("/type:bookmark/action:unset/entry_id:#{ self.id }") end if resp['status']['code'].to_i == 200 user.bookmarks end end |