flumtter 5.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/CODE_OF_CONDUCT.md +74 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +21 -0
  6. data/README.md +41 -0
  7. data/Rakefile +2 -0
  8. data/bin/console +14 -0
  9. data/bin/setup +8 -0
  10. data/exe/flumtter +5 -0
  11. data/flumtter.gemspec +31 -0
  12. data/lib/flumtter.rb +2 -0
  13. data/lib/flumtter/app/core/account_selector.rb +88 -0
  14. data/lib/flumtter/app/core/client.rb +148 -0
  15. data/lib/flumtter/app/core/command.rb +24 -0
  16. data/lib/flumtter/app/core/command/dm.rb +12 -0
  17. data/lib/flumtter/app/core/command/tweet.rb +24 -0
  18. data/lib/flumtter/app/core/command/user.rb +52 -0
  19. data/lib/flumtter/app/core/command/userlist.rb +8 -0
  20. data/lib/flumtter/app/core/core.rb +58 -0
  21. data/lib/flumtter/app/core/curses.rb +90 -0
  22. data/lib/flumtter/app/core/hash.rb +29 -0
  23. data/lib/flumtter/app/core/initializer.rb +28 -0
  24. data/lib/flumtter/app/core/keyboard.rb +54 -0
  25. data/lib/flumtter/app/core/plugins.rb +27 -0
  26. data/lib/flumtter/app/core/string.rb +148 -0
  27. data/lib/flumtter/app/core/terminal.rb +13 -0
  28. data/lib/flumtter/app/core/thread.rb +29 -0
  29. data/lib/flumtter/app/core/toast.rb +26 -0
  30. data/lib/flumtter/app/core/util.rb +107 -0
  31. data/lib/flumtter/app/core/windows/base.rb +16 -0
  32. data/lib/flumtter/app/core/windows/buf_window.rb +194 -0
  33. data/lib/flumtter/app/core/windows/dialog.rb +62 -0
  34. data/lib/flumtter/app/core/windows/dmbase.rb +28 -0
  35. data/lib/flumtter/app/core/windows/dynamic_view.rb +43 -0
  36. data/lib/flumtter/app/core/windows/favorite.rb +31 -0
  37. data/lib/flumtter/app/core/windows/follower.rb +20 -0
  38. data/lib/flumtter/app/core/windows/following.rb +20 -0
  39. data/lib/flumtter/app/core/windows/mention.rb +29 -0
  40. data/lib/flumtter/app/core/windows/popup.rb +35 -0
  41. data/lib/flumtter/app/core/windows/tweet.rb +31 -0
  42. data/lib/flumtter/app/core/windows/tweetbase.rb +24 -0
  43. data/lib/flumtter/app/core/windows/userbase.rb +43 -0
  44. data/lib/flumtter/app/main.rb +3 -0
  45. data/lib/flumtter/app/plugins/commands.rb +15 -0
  46. data/lib/flumtter/app/plugins/commands/account_changer.rb +9 -0
  47. data/lib/flumtter/app/plugins/commands/change_profile.rb +69 -0
  48. data/lib/flumtter/app/plugins/commands/conversation.rb +39 -0
  49. data/lib/flumtter/app/plugins/commands/delete.rb +26 -0
  50. data/lib/flumtter/app/plugins/commands/directmessage.rb +35 -0
  51. data/lib/flumtter/app/plugins/commands/directmessages.rb +33 -0
  52. data/lib/flumtter/app/plugins/commands/favorite.rb +22 -0
  53. data/lib/flumtter/app/plugins/commands/mention.rb +7 -0
  54. data/lib/flumtter/app/plugins/commands/new_tweet.rb +17 -0
  55. data/lib/flumtter/app/plugins/commands/reply.rb +26 -0
  56. data/lib/flumtter/app/plugins/commands/retweet.rb +30 -0
  57. data/lib/flumtter/app/plugins/commands/unfavorite.rb +26 -0
  58. data/lib/flumtter/app/plugins/commands/user.rb +77 -0
  59. data/lib/flumtter/app/plugins/commands/utility.rb +17 -0
  60. data/lib/flumtter/app/plugins/load.rb +16 -0
  61. data/lib/flumtter/app/plugins/pry.rb +12 -0
  62. data/lib/flumtter/app/plugins/timeline.rb +42 -0
  63. data/lib/flumtter/app/plugins/timeline/base.rb +74 -0
  64. data/lib/flumtter/app/plugins/timeline/deleted_tweet.rb +23 -0
  65. data/lib/flumtter/app/plugins/timeline/dm.rb +23 -0
  66. data/lib/flumtter/app/plugins/timeline/event.rb +11 -0
  67. data/lib/flumtter/app/plugins/timeline/fav.rb +43 -0
  68. data/lib/flumtter/app/plugins/timeline/tweet.rb +51 -0
  69. data/lib/flumtter/app/plugins/toast.rb +45 -0
  70. data/lib/flumtter/version.rb +3 -0
  71. metadata +213 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6b639c3634cce614cbec5b5e8b4ec4b06cf056bc
4
+ data.tar.gz: 526d3adf8606a231aaf1f25e0f15f361c7c695eb
5
+ SHA512:
6
+ metadata.gz: a3447b8fd5f98b4ec4837e29764a5fb9bdb996f0741b62d27027653a73f62abf69a6673a1a97ed42b503f4dfafffb5e91b61f18ae844c8ebd85fc9d1cb49984c
7
+ data.tar.gz: 706a37e36a35fe5ff2f9997261f1cd3a3ffd49db34c29e2a87add430b2d57a46d1ecba1518a30c0ed7e22fc43aeec95fa29763158dc5a92c5755e027aa365b62
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /**/.DS_Store
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at flum.1025@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in flumtter.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 flum1025
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # Flumtter
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/flumtter`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'flumtter'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install flumtter
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/flum1025/flumtter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "flumtter"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ if $0 == __FILE__
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+ end
4
+
5
+ require 'flumtter'
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'flumtter/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "flumtter"
8
+ spec.version = Flumtter::VERSION
9
+ spec.authors = ["flum1025"]
10
+ spec.email = ["flum.1025@gmail.com"]
11
+
12
+ spec.summary = %q{Twitter Client on Terminal}
13
+ spec.description = spec.summary
14
+ spec.homepage = "https://github.com/flum1025/flumtter4"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = ['flumtter']
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.14"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_dependency 'pry', '~> 0.10.4'
27
+ spec.add_dependency 'oauth', '~> 0.5.1'
28
+ spec.add_dependency 'dispel', '~> 0.0.8'
29
+ spec.add_dependency 'terminal-notifier', '~> 1.7.1'
30
+ spec.add_dependency 'twitter', '~> 6.1.0'
31
+ end
@@ -0,0 +1,2 @@
1
+ require "flumtter/version"
2
+ require "flumtter/app/main"
@@ -0,0 +1,88 @@
1
+ require 'oauth'
2
+ require 'oauth/consumer'
3
+ require 'twitter'
4
+ require_relative 'hash'
5
+
6
+ module Flumtter
7
+ class Account
8
+ attr_reader :id, :screen_name, :keys
9
+ def initialize(options)
10
+ raise ArgumentError, "Argument is not hash" unless options.is_a?(Hash)
11
+ keys = %i(consumer_key consumer_secret access_token access_token_secret)
12
+ options.requires(*%i(screen_name)+keys)
13
+ @screen_name = options[:screen_name]
14
+ @id = options[:id]
15
+ @keys = Hash[keys.zip options.values_at(*keys)]
16
+ end
17
+ end
18
+
19
+ class AccountSelector
20
+ @@account_list = (Config[:accounts] ||= []).map{|a|Account.new(a)}
21
+
22
+ class << self
23
+ def select(options={})
24
+ if options[:id]
25
+ @@account_list[options[:id]]
26
+ elsif options[:name]
27
+ @@account_list.select{|a|a.screen_name == options[:name]}.first
28
+ elsif @@account_list.empty?
29
+ regist
30
+ @@account_list.first
31
+ else
32
+ dialog = Window::Dialog.new("Account Selector", <<~EOF)
33
+ Please input your account number.
34
+ Input 'regist' if you want to regist new account.
35
+
36
+ #{@@account_list.map.with_index{|a,i|"#{i}: #{a.screen_name}"}.join("\n")}
37
+ EOF
38
+ dialog.command(/^regist$/, "account registration"){|m|regist}
39
+ dialog.command(/^([#{@@account_list.size.times.to_a.join(",")}])$/, "account index"){|m|@@account_list[m[1].to_i]}
40
+ dialog.show(true)
41
+ end
42
+ end
43
+
44
+ def regist
45
+ dialog = Window::Dialog.new("Register Twitter Account", <<~EOF, 6, 70)
46
+ Please enter according to the screen.
47
+ EOF
48
+ keys = {}
49
+ dialog.show do |win|
50
+ Curses.echo
51
+ win.setpos(win.cury+2, 1)
52
+ win.addstr("consumer_key: ")
53
+ keys[:consumer_key] = win.getstr
54
+ win.setpos(win.cury, 1)
55
+ win.addstr("consumer_secret: ")
56
+ keys[:consumer_secret] = win.getstr
57
+ end
58
+ if keys[:consumer_key].empty? && !@@account_list.empty?
59
+ keys[:consumer_key], keys[:consumer_secret] =
60
+ @@account_list.last.keys.values_at(*%i(consumer_key consumer_secret))
61
+ end
62
+
63
+ consumer = OAuth::Consumer.new(keys[:consumer_key], keys[:consumer_secret], {:site=>"https://api.twitter.com"})
64
+ request_token = consumer.get_request_token
65
+
66
+ dialog = Window::Dialog.new("Register Twitter Account", <<~EOF)
67
+ Please access the following URL.
68
+ And get the Pin code.
69
+
70
+ #{request_token.authorize_url}
71
+
72
+ Enter your Pin code:
73
+ EOF
74
+ dialog.command(/(.+)/) do |m|
75
+ access_token = request_token.get_access_token(:oauth_verifier => m[1])
76
+ keys[:access_token] = access_token.token
77
+ keys[:access_token_secret] = access_token.secret
78
+ user = Twitter::REST::Client.new(keys).user
79
+ keys[:id], keys[:screen_name] = user.id, user.screen_name
80
+ Config[:accounts] << keys
81
+ @@account_list = Config[:accounts].map{|a|Account.new(a)}
82
+ end
83
+ dialog.show(false, false)
84
+ select
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,148 @@
1
+ require 'twitter'
2
+
3
+ module Flumtter
4
+ class Client
5
+ include Util
6
+ attr_reader :account, :sthread, :ethread, :rest
7
+
8
+ @@events = []
9
+ def self.on_event(*filter,&blk)
10
+ @@events << [filter, blk]
11
+ end
12
+
13
+ def callback(object, events=nil)
14
+ events ||= object.type(@account)
15
+ @@events.each do |filter, blk|
16
+ blk.call(object, self) if (filter - events).empty?
17
+ end
18
+ end
19
+
20
+ def initialize(account)
21
+ debug if Setting[:debug]
22
+ @queue = Queue.new
23
+ @mutex = Mutex.new
24
+ set(account)
25
+ start
26
+ Keyboard.input(self)
27
+ end
28
+
29
+ def set(account)
30
+ @account = account
31
+ @rest = Twitter::REST::Client.new(@account.keys)
32
+ @stream = Twitter::Streaming::Client.new(@account.keys)
33
+ end
34
+
35
+ def start
36
+ Flumtter.callback(:init, self)
37
+ stream unless Setting[:non_stream]
38
+ end
39
+
40
+ def stream
41
+ execute
42
+ @sthread = Thread.new do
43
+ puts "#{@account.screen_name}'s stream_start!"
44
+ "#{@account.screen_name} #{TITLE}".title
45
+ begin
46
+ @stream.user(Setting[:stream_option] || {}) do |object|
47
+ @queue.push object
48
+ end
49
+ rescue Twitter::Error::TooManyRequests => e
50
+ puts e.class.to_s.color
51
+ end
52
+ end
53
+ end
54
+
55
+ def execute
56
+ @ethread = Thread.new do
57
+ loop do
58
+ handler do
59
+ object = @queue.pop
60
+ begin
61
+ @mutex.lock
62
+ callback(object)
63
+ ensure
64
+ @mutex.unlock
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ def kill
72
+ @sthread.kill
73
+ @ethread.kill
74
+ @queue.clear
75
+ end
76
+
77
+ def pause
78
+ @mutex.lock
79
+ end
80
+
81
+ def resume
82
+ @mutex.unlock
83
+ end
84
+
85
+ private
86
+ def handler
87
+ yield
88
+ rescue => e
89
+ error e
90
+ rescue Exception => e
91
+ error e
92
+ raise e
93
+ end
94
+
95
+ def debug
96
+ update = %i(update update_with_media retweet block unblock create_direct_message follow unfollow favorite unfavorite)
97
+ Twitter::REST::Client.class_eval do
98
+ update.each do |sym|
99
+ define_method sym do |*args|
100
+ puts "Debug: :#{sym} #{args}"
101
+ sleep 1
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end
108
+
109
+ class Twitter::Tweet
110
+ def type(account)
111
+ type = [:tweet]
112
+ type << (retweet? ? :retweet : :retweet!)
113
+ type << (user.id == account.id ? :self_tweet : :self_tweet!)
114
+ type << (reply? ? :reply : :reply!)
115
+ type << (quote? ? :quote : :quote!)
116
+ type << (in_reply_to_user_id == account.id ? :reply_to_me : :reply_to_me!)
117
+ type
118
+ end
119
+
120
+ def via
121
+ source.gsub(/<(.+)\">/,"").gsub(/<\/a>/,"")
122
+ end
123
+ end
124
+
125
+ class Twitter::Streaming::Event
126
+ def type(account)
127
+ [:event, name]
128
+ end
129
+ end
130
+
131
+ class Twitter::Streaming::FriendList
132
+ def type(account)
133
+ [:friendlist]
134
+ end
135
+ end
136
+
137
+ class Twitter::Streaming::DeletedTweet
138
+ def type(account)
139
+ [:deletedtweet]
140
+ end
141
+ end
142
+
143
+ class Twitter::DirectMessage
144
+ def type(account)
145
+ type = [:directmessage]
146
+ type << (sender.id == account.id ? :self_message : :self_message!)
147
+ end
148
+ end