Class: Tweetwine::Twitter
- Inherits:
-
Object
- Object
- Tweetwine::Twitter
- Defined in:
- lib/tweetwine/twitter.rb
Constant Summary collapse
- MAX_STATUS_LENGTH =
140
- REST_API_STATUS_PATHS =
{ :from_user => %w{user screen_name}, :to_user => %w{in_reply_to_screen_name}, :retweet => %w{retweeted_status}, :created_at => %w{created_at}, :status => %w{text} }
- REST_API_USER_PATHS =
{ :from_user => %w{screen_name}, :to_user => %w{status in_reply_to_screen_name}, :retweet => %w{retweeted_status}, :created_at => %w{status created_at}, :status => %w{status text} }
- SEARCH_API_STATUS_PATHS =
{ :from_user => %w{from_user}, :to_user => %w{to_user}, :retweet => %w{retweeted_status}, :created_at => %w{created_at}, :status => %w{text} }
Instance Attribute Summary collapse
-
#num_tweets ⇒ Object
readonly
Returns the value of attribute num_tweets.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #followers ⇒ Object
- #friends ⇒ Object
- #home ⇒ Object
-
#initialize(options = {}) ⇒ Twitter
constructor
A new instance of Twitter.
- #mentions ⇒ Object
- #search(words = [], operator = nil) ⇒ Object
- #update(msg = nil) ⇒ Object
- #user(who = username) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Twitter
Returns a new instance of Twitter.
35 36 37 38 39 40 41 |
# File 'lib/tweetwine/twitter.rb', line 35 def initialize( = {}) @num_tweets = Support.parse_int_gt([:num_tweets], CLI::DEFAULT_CONFIG[:num_tweets], 1, "number of tweets to show") @page = Support.parse_int_gt([:page], CLI::DEFAULT_CONFIG[:page], 1, "page number") @username = [:username].to_s rescue ArgumentError => e raise CommandLineError, e end |
Instance Attribute Details
#num_tweets ⇒ Object (readonly)
Returns the value of attribute num_tweets.
33 34 35 |
# File 'lib/tweetwine/twitter.rb', line 33 def num_tweets @num_tweets end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
33 34 35 |
# File 'lib/tweetwine/twitter.rb', line 33 def page @page end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
33 34 35 |
# File 'lib/tweetwine/twitter.rb', line 33 def username @username end |
Instance Method Details
#followers ⇒ Object
43 44 45 |
# File 'lib/tweetwine/twitter.rb', line 43 def followers show_users_from_rest_api(get_from_rest_api("statuses/followers")) end |
#friends ⇒ Object
47 48 49 |
# File 'lib/tweetwine/twitter.rb', line 47 def friends show_users_from_rest_api(get_from_rest_api("statuses/friends")) end |
#home ⇒ Object
51 52 53 |
# File 'lib/tweetwine/twitter.rb', line 51 def home show_tweets_from_rest_api(get_from_rest_api("statuses/home_timeline")) end |
#mentions ⇒ Object
55 56 57 |
# File 'lib/tweetwine/twitter.rb', line 55 def mentions show_tweets_from_rest_api(get_from_rest_api("statuses/mentions")) end |
#search(words = [], operator = nil) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/tweetwine/twitter.rb', line 59 def search(words = [], operator = nil) raise ArgumentError, "No search words" if words.empty? operator = :and unless operator query = operator == :and ? words.join(' ') : words.join(' OR ') response = get_from_search_api query show_tweets_from_search_api(response["results"]) end |
#update(msg = nil) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/tweetwine/twitter.rb', line 67 def update(msg = nil) new_status = create_status_update(msg) completed = false unless new_status.empty? CLI.ui.show_status_preview(new_status) status_in_utf8 = CharacterEncoding.to_utf8 new_status if CLI.ui.confirm("Really send?") response = post_to_rest_api("statuses/update", :status => status_in_utf8) CLI.ui.info "Sent status update.\n\n" show_tweets_from_rest_api([response]) completed = true end end CLI.ui.info "Cancelled." unless completed end |
#user(who = username) ⇒ Object
83 84 85 86 87 88 |
# File 'lib/tweetwine/twitter.rb', line 83 def user(who = username) show_tweets_from_rest_api(get_from_rest_api( "statuses/user_timeline", common_rest_api_query_params.merge!({ :screen_name => who }) )) end |