groupme-cli 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 18fcbc0d6cfbc6fd26ec557663510cfcb320415c
4
+ data.tar.gz: 9479775598e0ef5ea40c74b2fff3b3c75c92f59e
5
+ SHA512:
6
+ metadata.gz: 2056c738b97ca23823e59716134c500a93bd5172642210e71356f1f0096d7e42b321898be184472147336d1e54a07950971aa7310324a7769823596c10e9f244
7
+ data.tar.gz: a5a09cb08473633b7befa4c9ad007d50f6eb88e8831c04bbdfb03d07929feda79003405e55360f1e100129f8a5c06c9a3b0fa95dd5562b67679e5e7f8b6fc419
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.3.3
7
+ before_install: gem install bundler -v 1.16.4
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in groupme-cli.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,57 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ groupme-cli (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ colorize (0.8.1)
10
+ diff-lcs (1.3)
11
+ faraday (0.9.2)
12
+ multipart-post (>= 1.2, < 3)
13
+ faraday_middleware (0.9.2)
14
+ faraday (>= 0.7.4, < 0.10)
15
+ fastimage (2.1.5)
16
+ groupme (0.0.7)
17
+ faraday (~> 0.9.0)
18
+ faraday_middleware (~> 0.9.0)
19
+ hashie (~> 3.0)
20
+ multi_json (~> 1.3)
21
+ simple_oauth (~> 0.2)
22
+ hashie (3.0.0)
23
+ multi_json (1.13.1)
24
+ multipart-post (2.0.0)
25
+ rake (10.5.0)
26
+ rspec (3.8.0)
27
+ rspec-core (~> 3.8.0)
28
+ rspec-expectations (~> 3.8.0)
29
+ rspec-mocks (~> 3.8.0)
30
+ rspec-core (3.8.0)
31
+ rspec-support (~> 3.8.0)
32
+ rspec-expectations (3.8.2)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.8.0)
35
+ rspec-mocks (3.8.0)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.8.0)
38
+ rspec-support (3.8.0)
39
+ ruby-terminfo (0.1.1)
40
+ simple_oauth (0.3.1)
41
+
42
+ PLATFORMS
43
+ ruby
44
+
45
+ DEPENDENCIES
46
+ bundler (~> 1.16)
47
+ colorize (~> 0.8.1)
48
+ fastimage (~> 2.1.5)
49
+ groupme (~> 0.0.7)
50
+ groupme-cli!
51
+ hashie (~> 3.0, <= 3.0)
52
+ rake (~> 10.0)
53
+ rspec (~> 3.0)
54
+ ruby-terminfo (~> 0.1.1)
55
+
56
+ BUNDLED WITH
57
+ 1.16.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 TODO: Write your name
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.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # Groupme::Cli
2
+
3
+ This is a command-line interface for the [GroupMe](https://groupme.com) app. It lets you open chats in your terminal, post to them, send images, and switch which chat you're on.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'groupme-cli'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install groupme-cli
20
+
21
+ ## Usage
22
+ There's a little script in this app's bin/ directory called bin/groupme that wraps the gem's runner method. Simply execute
23
+
24
+ $ bin/groupme MY_ACCESS_TOKEN
25
+
26
+ Where MY_ACCESS_TOKEN is obtained from the [GroupMe developer site](https://dev.groupme.com) (You'll have to log in to get your token).
27
+ When you run the app, it will ask you to open a chat. Just do `%open chat_name` to open a chat. You can repeat that command to switch to a different chat.
28
+ To send normal messages, just type your message and hit enter, and it should send and show up. To send images, do `%image /path/to/the/image`.
29
+ You can exit by either typing `%quit`, Ctrl+C, or dousing your computer with orange juice until it turns off (the program is equipped to handle sudden termination, but I still don't advise the last method).
30
+
31
+ ## Development
32
+
33
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
34
+
35
+ 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).
36
+
37
+ ## Contributing
38
+
39
+ Bug reports and pull requests are welcome on GitHub at https://gitlab.com/Bleu-Box/groupme-cli.
40
+
41
+ ## License
42
+
43
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
44
+
45
+ ## Note
46
+
47
+ I am not affiliated with GroupMe. Additionally, this gem is not an official way of accessing GroupMe, so GroupMe is not liable for any problems you experience specifically with this gem.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/groupme ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "groupme/cli"
5
+
6
+ if ARGV.length == 1
7
+ Groupme::Cli.run ARGV[0]
8
+ else
9
+ puts "Usage: groupme [access token]"
10
+ end
data/bin/setup ADDED
@@ -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,34 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "groupme/cli/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "groupme-cli"
7
+ spec.version = Groupme::Cli::VERSION
8
+ spec.authors = ["Benjamin Duchild"]
9
+ spec.email = ["xxarcajethxx@gmail.com"]
10
+
11
+ spec.summary = %q{A command-line interface for GroupMe}
12
+ spec.homepage = "https://gitlab.com/Bleu-Box/groupme-cli"
13
+ spec.license = "MIT"
14
+
15
+ # Specify which files should be added to the gem when it is released.
16
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
17
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
18
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ end
20
+
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.16"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ spec.add_development_dependency "colorize", "~> 0.8.1"
29
+ spec.add_development_dependency "ruby-terminfo", "~> 0.1.1"
30
+ spec.add_development_dependency "groupme", "~> 0.0.7"
31
+ # Hashie has obnoxious warning messages when using the groupme gem above,
32
+ # so I'm holding its version as far back as possible so warnings don't clog up the CLI output.
33
+ spec.add_development_dependency "hashie", "~> 3.0", "<= 3.0"
34
+ end
@@ -0,0 +1,66 @@
1
+ require 'colorize'
2
+
3
+ require "groupme/cli/version"
4
+ require "groupme/cli/session"
5
+
6
+ module Groupme
7
+ module Cli
8
+ def self.run token
9
+ puts "Welcome to the GroupMe CLI v#{VERSION}"
10
+ puts "Start by entering '%open chat_name', where chat_name is the name of the chat you want to open."
11
+
12
+ sesh = Session.new token
13
+
14
+ begin
15
+ # For status messages coming from the input thread
16
+ status_buffer = Array.new
17
+
18
+ # input loop/thread
19
+ input_thread = Thread.new do
20
+ loop do
21
+ input = gets
22
+ if input[0..6] == "%image "
23
+ sesh.send_msg("", input[7..-1].strip)
24
+ elsif input[0..4] == "%quit"
25
+ exit
26
+ elsif input[0..5] == "%open "
27
+ name = input[6..-1].chomp
28
+
29
+ if sesh.open_chat(name)
30
+ status_buffer << "<Opened #{name}>"
31
+ else
32
+ status_buffer << "That group does not exist. Check the name you entered to make sure it's correct."
33
+ end
34
+ else
35
+ sesh.send_msg input
36
+ end
37
+ end
38
+ end
39
+
40
+ # output loop
41
+ loop do
42
+ # check for signals and catch them in order to exit gracefully
43
+ Signal.trap("INT") { exit }
44
+ Signal.trap("TERM") { exit }
45
+
46
+ status_buffer.each { |m| puts m }
47
+ status_buffer.clear
48
+
49
+ if sesh.chat_is_open?
50
+ # fetch new messages
51
+ sesh.update_messages
52
+ msgs = sesh.new_messages
53
+ msgs.each {|m| puts m}
54
+ end
55
+ end
56
+
57
+ rescue SystemExit
58
+ puts "Goodbye"
59
+ rescue Exception => e
60
+ puts "Something went horribly wrong! See ya later."
61
+ puts "Exception details: #{e}"
62
+ end
63
+
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,26 @@
1
+ require 'colorize'
2
+
3
+ module Groupme
4
+ module Cli
5
+ class Message
6
+ attr_reader :sender, :time, :text
7
+
8
+ def initialize(sender:, time:, text:)
9
+ @sender, @time, @text = sender, time, text
10
+ end
11
+
12
+ def to_s
13
+ "<#{@sender.colorize :blue}[#{fmt_time.colorize :red}]>:\n\t#{fmt_text}"
14
+ end
15
+
16
+ private
17
+ def fmt_time
18
+ @time.strftime "%I:%M%p"
19
+ end
20
+
21
+ def fmt_text
22
+ @text.lines.join "\t"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,140 @@
1
+ require 'groupme'
2
+ require 'json'
3
+ require 'net/http'
4
+ require 'net/https'
5
+
6
+ require "groupme/cli/message"
7
+
8
+ module Groupme
9
+ module Cli
10
+ # Represents a GroupMe session. This wraps the GroupMe API gem and has methods for accessing the data for
11
+ # a specific session and sending messages.
12
+ class Session
13
+ def initialize token
14
+ @token = token
15
+ @client = GroupMe::Client.new(token: token)
16
+ @current_chat_id = nil
17
+ @new_msgs = Array.new
18
+ @last_msg_id = 0
19
+ end
20
+
21
+ # "Open" a chat with the specified name. This means that the CLI will display live messages from the
22
+ # chat, and any messages you write will go to that chat as well.
23
+ # Returns true if it succeeds and false otherwise.
24
+ def open_chat name
25
+ group = @client.groups.select {|g| g[:name] == name}[0]
26
+
27
+ if group.nil?
28
+ return false
29
+ else
30
+ @current_chat_id = group[:id]
31
+ return true
32
+ end
33
+ end
34
+
35
+ # Send a message to the current chat.
36
+ def send_msg(msg, image=nil)
37
+ with_valid_group do
38
+ attachments = []
39
+ # process image attachments
40
+ unless image.nil?
41
+ url = make_img_url image
42
+ attachments << {type: "image", url: url}
43
+ end
44
+
45
+ @client.create_message(@current_chat_id, msg, attachments)
46
+ end
47
+ end
48
+
49
+ # Fetch messages from the currently open group that haven't been fetched yet.
50
+ def new_messages
51
+ # save the new messages
52
+ messages = @new_msgs.clone
53
+ # flush @new_msgs since we've seen these already now
54
+ @new_msgs.clear
55
+
56
+ return messages
57
+ end
58
+
59
+ # Query the API for "new" messages. In this case, "new" messages are ones that the programmer has not
60
+ # been given (via a call to Session#new_messages) yet.
61
+ def update_messages
62
+ with_valid_group do
63
+ messages = @client.messages(@current_chat_id, {since_id: @last_msg_id, limit: 20})
64
+
65
+ # look through the messages and save the new ones
66
+ messages.each do |msg|
67
+ sender = abbrev_name msg[:name]
68
+ time = Time.at msg[:created_at]
69
+ text = msg[:text] || ""
70
+
71
+ # create a new Message object and push it onto the front of the new_msgs array
72
+ message_obj = Message.new(sender: sender, time: time, text: text)
73
+ @new_msgs.unshift message_obj
74
+
75
+ # replace attachments with their types/urls since images and stuff aren't terminal-friendly
76
+ replacements = msg[:attachments].map do |att|
77
+ att[:type] == "image"? "[image @ #{att[:url]}]" : att[:type]
78
+ end
79
+
80
+ # add in the replacements, separated by newlines
81
+ text << replacements.join("\n")
82
+
83
+ # save the ID of the newest message
84
+ unless messages.empty?
85
+ @last_msg_id = messages[0][:id]
86
+ end
87
+ end
88
+ end
89
+ end
90
+
91
+ def chat_is_open?
92
+ !@current_chat_id.nil?
93
+ end
94
+
95
+ private
96
+ # Make sure that a chat has been selected. If there's a valid chat open, execute the block; otherwise,
97
+ # show a warning message and skip the block. This method assumes that the block being called depends on
98
+ # the session having a group open.
99
+ def with_valid_group
100
+ if !chat_is_open?
101
+ puts "You must open a chat before sending a message!"
102
+ return
103
+ end
104
+
105
+ yield
106
+ end
107
+
108
+ # Abbreviate a user's name so it doesn't take up a ton of space
109
+ def abbrev_name name
110
+ name.split(' ')
111
+ .map {|word| word.length > 8? word[0..3]+"." : word}
112
+ .join(' ')
113
+ end
114
+
115
+ # Upload an image to GroupMe's image service and return the URL for it
116
+ def make_img_url path
117
+ # Obtain image file type (needed for the request)
118
+ type = File.extname(path)[1..-1]
119
+
120
+ # creat HTTP request
121
+ uri = URI.parse "https://image.groupme.com/pictures"
122
+ https = Net::HTTP.new(uri.host, uri.port)
123
+ https.use_ssl = true
124
+ headers = Hash.new
125
+ # make headers
126
+ headers['X-Access-Token'] = @token
127
+ headers['Content-Type'] = "image/#{type}"
128
+
129
+ # get the response and extract the image URL from it, or handle an error
130
+ resp = https.post2(uri.path, File.read(path), headers)
131
+ if resp.class == Net::HTTPOK
132
+ data = JSON.parse resp.body
133
+ return data["payload"]["picture_url"]
134
+ else
135
+ puts "An HTTP error occurred while trying to upload your image. We're profoundly sorry."
136
+ end
137
+ end
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,5 @@
1
+ module Groupme
2
+ module Cli
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: groupme-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Benjamin Duchild
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-03-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: colorize
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.8.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.8.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: ruby-terminfo
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.1.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.1.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: groupme
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.0.7
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.0.7
97
+ - !ruby/object:Gem::Dependency
98
+ name: hashie
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ - - "<="
105
+ - !ruby/object:Gem::Version
106
+ version: '3.0'
107
+ type: :development
108
+ prerelease: false
109
+ version_requirements: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - "~>"
112
+ - !ruby/object:Gem::Version
113
+ version: '3.0'
114
+ - - "<="
115
+ - !ruby/object:Gem::Version
116
+ version: '3.0'
117
+ description:
118
+ email:
119
+ - xxarcajethxx@gmail.com
120
+ executables: []
121
+ extensions: []
122
+ extra_rdoc_files: []
123
+ files:
124
+ - ".gitignore"
125
+ - ".rspec"
126
+ - ".travis.yml"
127
+ - Gemfile
128
+ - Gemfile.lock
129
+ - LICENSE.txt
130
+ - README.md
131
+ - Rakefile
132
+ - bin/groupme
133
+ - bin/setup
134
+ - groupme-cli.gemspec
135
+ - lib/groupme/cli.rb
136
+ - lib/groupme/cli/message.rb
137
+ - lib/groupme/cli/session.rb
138
+ - lib/groupme/cli/version.rb
139
+ homepage: https://gitlab.com/Bleu-Box/groupme-cli
140
+ licenses:
141
+ - MIT
142
+ metadata: {}
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ requirements: []
158
+ rubyforge_project:
159
+ rubygems_version: 2.5.2.1
160
+ signing_key:
161
+ specification_version: 4
162
+ summary: A command-line interface for GroupMe
163
+ test_files: []