Class: Featherdust
- Inherits:
-
Object
- Object
- Featherdust
- Defined in:
- lib/featherdust.rb
Constant Summary collapse
- VERSION =
'0.0.1'
Instance Attribute Summary collapse
-
#num_posts ⇒ Object
Returns the value of attribute num_posts.
-
#posts ⇒ Object
Returns the value of attribute posts.
-
#raw_posts ⇒ Object
Returns the value of attribute raw_posts.
-
#url ⇒ Object
Returns the value of attribute url.
-
#username ⇒ Object
Returns the value of attribute username.
Class Method Summary collapse
Instance Method Summary collapse
- #display_statuses ⇒ Object
- #get_statuses ⇒ Object
-
#initialize(username, num_posts = 20) ⇒ Featherdust
constructor
A new instance of Featherdust.
- #is_twitter_up? ⇒ Boolean
Constructor Details
#initialize(username, num_posts = 20) ⇒ Featherdust
Returns a new instance of Featherdust.
11 12 13 14 15 |
# File 'lib/featherdust.rb', line 11 def initialize(username, num_posts = 20) @username = username @num_posts = num_posts @raw_posts = Array.new end |
Instance Attribute Details
#num_posts ⇒ Object
Returns the value of attribute num_posts.
10 11 12 |
# File 'lib/featherdust.rb', line 10 def num_posts @num_posts end |
#posts ⇒ Object
Returns the value of attribute posts.
10 11 12 |
# File 'lib/featherdust.rb', line 10 def posts @posts end |
#raw_posts ⇒ Object
Returns the value of attribute raw_posts.
10 11 12 |
# File 'lib/featherdust.rb', line 10 def raw_posts @raw_posts end |
#url ⇒ Object
Returns the value of attribute url.
10 11 12 |
# File 'lib/featherdust.rb', line 10 def url @url end |
#username ⇒ Object
Returns the value of attribute username.
10 11 12 |
# File 'lib/featherdust.rb', line 10 def username @username end |
Class Method Details
.run(username, number) ⇒ Object
17 18 19 20 21 |
# File 'lib/featherdust.rb', line 17 def self.run(username, number) twitter_list = Featherdust.new(username, number) puts twitter_list.display_statuses end |
Instance Method Details
#display_statuses ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/featherdust.rb', line 54 def display_statuses tweets = get_statuses @posts = "<ul>" tweets.each do |tweet| @posts += "<li><p class=\"twitter_status\">#{tweet[:text]}</p>\n<span><a href=\"http://twitter.com/#{@username}/statuses/#{tweet[:id]}\" title=\"Status update on Twitter\"> on #{tweet[:created_at]}</a>\n</span></li>\n" end @posts += "</ul>" end |
#get_statuses ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/featherdust.rb', line 27 def get_statuses if is_twitter_up? != "true" raise "Twitter is having issues. Please check back later." else # status_list = Nokogiri::XML(Net::HTTP.get("twitter.com", "/statuses/user_timeline/#{@username}.xml?count=#{@num_posts}")) status_list = Nokogiri::XML(Net::HTTP.get("twitter.com", "/statuses/user_timeline/#{@username}.xml?count=#{@num_posts}")) status_list.xpath('/statuses/status').each do |statuses| status_hash = {} statuses.children.each do |status| if status.name == "user" status.children.each do |user| user.name == "id" ? key = "user_id".to_sym : key = user.name.to_sym value = user.inner_text status_hash.store(key,value) end else key = status.name.to_sym value = status.inner_text status_hash.store(key,value) end end @raw_posts << status_hash end end return @raw_posts end |
#is_twitter_up? ⇒ Boolean
63 64 65 66 |
# File 'lib/featherdust.rb', line 63 def is_twitter_up? twitter_status = Nokogiri::XML(Net::HTTP.get("twitter.com","/help/test.xml")) twitter_status.xpath("/ok").inner_text end |