Module: Twido

Defined in:
lib/twido/version.rb,
lib/twido.rb,
lib/twido/authentication.rb

Overview

Copyright 2012 Cody Finn This file is part of Twido.

Twido is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Twido is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Twido. If not, see <www.gnu.org/licenses/>.

Defined Under Namespace

Modules: Authentication

Constant Summary collapse

VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.authenticateObject

Public: authenticates the user using the authenticate method of the Authentication module Returns a Twitter::Client Examples

self.authenticate

# => Twitter::Client


30
31
32
# File 'lib/twido.rb', line 30

def self.authenticate
  @twitter_client = Twido::Authentication.authenticate
end

.build_list(count = 10) ⇒ Object

Private: Gets a list of tweets with “#todo” Retruns Array of tweets Examples self.build_list

# => [tweet1, tweet2, ...]


144
145
146
147
148
# File 'lib/twido.rb', line 144

def self.build_list(count = 10)
  twitter_client = Authentication.authenticate
  user = twitter_client.user.screen_name
  twitter_client.search("#todo", count: count, from:user).statuses
end

.completeObject

Public: removes a task from the user’s to do list by deleting the tweet and confirming Returns a string stating if task was completed or not Examples

self.complete
  # => [0] Task #todo
       [1] Task2 #todo
       Enter task ID:
        1
          Are you sure you completed this task?:
            y
              TASK COMPLETED
self.complete
  # => [0] Task #todo
       [1] Task2 #todo
       Enter task ID:
        0
          Are you sure you completed this task?:
            n
              Have a good and productive day!


109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/twido.rb', line 109

def self.complete
  twitter_client = Authentication.authenticate
  tweets = self.build_list
  self.list
  complete_index = ask("Enter task ID: ")
  complete = Integer(complete_index)
  tweet_id = tweets[complete].id
  confirm = ask("Are you sure you completed this task?: ")
    case confirm.downcase.to_sym
    when :no, :n
      puts "Have a good and productive day!"
    when :yes, :y
  twitter_client.status_destroy(tweet_id)
  puts "TASK COMPLETED"
  end
end

.group(count = 20) ⇒ Object

Public: Gets list of tweets with the hash tag #“group”_todo Returns Array of tweets Examples self.group

#=> [tweet1, tweet2,...]


155
156
157
158
159
160
# File 'lib/twido.rb', line 155

def self.group(count = 20)
  twitter_client = Authentication.authenticate
  group_name = ask("Enter group name: ") + "_todo"
  tweets = twitter_client.search(group_name, count: count).statuses
  tweets.each_with_index { |tweet, index| puts "[#{index}] #{tweet.text}" }
end

.group_completeObject

Public: removes a task from the specified group’s to do list by deleting the tweet and confirming authorship Returns a string stating if task was completed or not Examples

self.group_complete
  # => [0] Task #todo
       [1] Task2 #todo
       Enter task ID:
        1
          Are you sure you completed this task?:
            y
              TASK COMPLETED
self.group_complete
  # => [0] Task #todo
       [1] Task2 #todo
       Enter task ID:
        0
          Are you sure you completed this task?:
            n
              Have a good and productive day!


182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/twido.rb', line 182

def self.group_complete
  twitter_client = Authentication.authenticate
  tweets = self.group
  complete_index = ask("Enter task ID: ")
  complete = Integer(complete_index)
  tweet_id = tweets[complete].id
  author = twitter_client.status(tweet_id,{"trim_user" => true})
  user = twitter_client.user
  confirm = ask("Are you sure you completed this task?: ")
  case confirm.downcase.to_sym
  when :no, :n
    puts "Have a good and productive day!"
  when :yes, :y
  confirm = ask("Is this your tweet?: ")
  case confirm.downcase.to_sym
  when :yes, :y  
    twitter_client.status_destroy(tweet_id)
    puts "TASK COMPLETED"
  when :no, :n
      twitter_client.update(" Task completed please delete task", {"in_reply_to_status_id" => tweet_id})
    end
  end
end

.group_taskObject

Public: adds a task to the specified group’s todo list by tweeting a tweet that the user defines and automaticly adds the “#group_name_todo” to the end Returns nil Examples

self.group_task
  # => What do you have to do?:
    task


213
214
215
216
217
218
# File 'lib/twido.rb', line 213

def self.group_task
  twitter_client = Authentication.authenticate
  group_name = ask("Enter group name: ") + "_todo"
  task = ask("What do you have to do?: ") + " #" + group_name
  twitter_client.update(task)
end

.list(tweets = self.build_list) ⇒ Object

self.list

  # => [0] task #todo
       [1] task 2 # todo
       Did you complete a task?:
        # => n
          # => Have a good and productive day!
self.list
  # => [0] task #todo
       [1] task 2 # todo
       Did you complete a task?:
        # => g
          # => TASK ERROR: ACTION NOT RECONIZED


85
86
87
# File 'lib/twido.rb', line 85

def self.list(tweets = self.build_list)
  tweets.each_with_index { |tweet, index| puts "[#{index}] #{tweet.text}" }
end

.setupObject

Public: propts the user to set up thier account with the information needed to register thier app Returns nil Examples



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/twido.rb', line 37

def self.setup
  messege=<<-MESSEGE
    Welcome! Before you can use Twido, you'll first need to register an
    application with Twitter. Just follow the steps below:
      1. Sign in to the Twitter Developer site and click
         "Create a new application".
      2. Complete the required fields and submit the form.
         Note: Your application must have a unique name.
         We recommend: "<your handle>/t".
      3. Go to the Settings tab of your application, and change the
         Access setting to "Read, Write and Access direct messages".
      4. Go to the Details tab to view the consumer key and secret,
         which you'll need to copy and paste below when prompted.
  MESSEGE

   = {}

  puts messege
  [:consumer_key] = ask("Enter consumer key: ") { |q| q.echo = true }
  [:consumer_secret] = ask("Enter consumer secret: ") { |q| q.echo = true }
  [:oauth_token] = ask("Enter Oauth token: ") { |q| q.echo = true }
  [:oauth_token_secret] = ask("Enter Oauth token secret: ") { |q| q.echo = true}

  Authentication.write_credentials_to_config()
end

.taskObject

Public: adds a task to the user’s todo list by tweeting a tweet that the user defines and automaticly adds the “#todo” to the end Returns nil Examples

self.task
  # => What do you have to do?:
    task


133
134
135
136
137
# File 'lib/twido.rb', line 133

def self.task
  twitter_client = Authentication.authenticate
  task = ask("What do you have to do?: ") + " #todo"
  twitter_client.update(task)
end