Class: FbUtils::Comment
- Inherits:
-
Object
- Object
- FbUtils::Comment
- Defined in:
- lib/fb_utils/comment.rb
Constant Summary collapse
- LINK =
"http://graph.facebook.com/comments/?ids="
Instance Attribute Summary collapse
-
#created_time ⇒ Object
Returns the value of attribute created_time.
-
#from_id ⇒ Object
Returns the value of attribute from_id.
-
#from_name ⇒ Object
Returns the value of attribute from_name.
-
#id ⇒ Object
Returns the value of attribute id.
-
#message ⇒ Object
Returns the value of attribute message.
Class Method Summary collapse
-
.get(href) ⇒ Object
Get comments related to href Return array of comments.
-
.save(href, filename, *args) ⇒ Object
Get comments and save these in file system.
Instance Method Summary collapse
-
#initialize(hash = {}) ⇒ Comment
constructor
A new instance of Comment.
- #to_array ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(hash = {}) ⇒ Comment
Returns a new instance of Comment.
7 8 9 10 11 12 13 14 |
# File 'lib/fb_utils/comment.rb', line 7 def initialize(hash={}) return if hash.empty? @id = hash["id"] @from_name = hash["from"]["name"] @from_id = hash["from"]["id"] @message = hash["message"] @created_time = hash["created_time"] end |
Instance Attribute Details
#created_time ⇒ Object
Returns the value of attribute created_time.
5 6 7 |
# File 'lib/fb_utils/comment.rb', line 5 def created_time @created_time end |
#from_id ⇒ Object
Returns the value of attribute from_id.
5 6 7 |
# File 'lib/fb_utils/comment.rb', line 5 def from_id @from_id end |
#from_name ⇒ Object
Returns the value of attribute from_name.
5 6 7 |
# File 'lib/fb_utils/comment.rb', line 5 def from_name @from_name end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/fb_utils/comment.rb', line 5 def id @id end |
#message ⇒ Object
Returns the value of attribute message.
5 6 7 |
# File 'lib/fb_utils/comment.rb', line 5 def @message end |
Class Method Details
.get(href) ⇒ Object
Get comments related to href Return array of comments
51 52 53 54 55 56 57 |
# File 'lib/fb_utils/comment.rb', line 51 def self.get(href) result = JSON.parse(Net::HTTP.get_response(URI(LINK + href)).body) data = result[href]["data"] data.inject([]) do |comments, c| comments << Comment.new(c) end end |
.save(href, filename, *args) ⇒ Object
Get comments and save these in file system
The rightmost argument is an optional hash of options, which is pass further to particular writer, specified from :format key Default is: :format => ‘txt’
For example:
FbUtils::Comment.save('http://www.example.com', 'example_com')
FbUtils::Comment.save('http://www.example.com', 'example_com',
:format => :csv,
:fields_terminated_by => ";",
:fields_enclosed_by => "'",
:lines_terminated_by => "\n"
39 40 41 42 43 44 45 46 47 |
# File 'lib/fb_utils/comment.rb', line 39 def self.save(href, filename, *args) = args. [:format] ||= "txt" comments = get(href) writer = "FbUtils::Writer::#{[:format].to_s.camelize}".constantize.new(filename, ) writer.write(comments) comments end |
Instance Method Details
#to_array ⇒ Object
20 21 22 |
# File 'lib/fb_utils/comment.rb', line 20 def to_array [@id, @message, @from_name, @from_id, @created_time] end |
#to_s ⇒ Object
16 17 18 |
# File 'lib/fb_utils/comment.rb', line 16 def to_s to_array.join(' ') end |