group_me_bot 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 49d6b36814777899542c58c53bb96a36fba436bd
4
+ data.tar.gz: d395b742195efcdc9a95245af7d4d098852bfecf
5
+ SHA512:
6
+ metadata.gz: db67f7b4e8e03b5bdd56ed08959cd03b9aff8e5a4b850b33fcdf3860cba2d87d5a5d0f7cac75209ca5cdf8199cb841c658f702e7c47c4af5cd425c55d284a060
7
+ data.tar.gz: b221056ccb87c329506967108d03a81732b53518a11b8d06ae7b15f9b2c2c561ac0256a75c6b9ad3490cfce547b93f423a8ff448a5409cb979d39785c8fc0e56
@@ -0,0 +1,85 @@
1
+ require "json"
2
+ require "net/http"
3
+ require "socket"
4
+ require "uri"
5
+
6
+ module GroupMeBot
7
+ class Bot
8
+ attr_accessor :bot_id, :callback_port, :post_uri
9
+ POST_URI = "https://api.groupme.com/v3/bots/post"
10
+
11
+ def initialize(bot_id = nil, callback_port = 8080, post_uri = POST_URI)
12
+ @bot_id = bot_id
13
+ @callback_port = callback_port
14
+ @post_uri = URI.parse(post_uri)
15
+ end
16
+
17
+ def send_message(message)
18
+ req = Net::HTTP::Post.new(self.post_uri, initheader = { "Content-Type" => "application/json" })
19
+
20
+ req.body = {
21
+ "bot_id" => self.bot_id,
22
+ "text" => message
23
+ }.to_json
24
+
25
+ res = Net::HTTP.start(self.post_uri.host, self.post_uri.port, :use_ssl => self.post_uri.scheme == "https") do |http|
26
+ http.request(req)
27
+ end
28
+ end
29
+
30
+ def send_image(url)
31
+ req = Net::HTTP::Post.new(self.post_uri, initheader = { "Content-Type" => "application/json" })
32
+
33
+ req.body = {
34
+ "bot_id" => self.bot_id,
35
+ "attachments" => [{
36
+ "type" => "image",
37
+ "url" => url
38
+ }]
39
+ }.to_json
40
+
41
+ res = Net::HTTP.start(self.post_uri.host, self.post_uri.port, :use_ssl => self.post_uri.scheme == "https") do |http|
42
+ http.request(req)
43
+ end
44
+ end
45
+
46
+ def send_location(long, lat, name)
47
+ req = Net::HTTP::Post.new(self.post_uri, initheader = { "Content-Type" => "application/json" })
48
+
49
+ req.body = {
50
+ "bot_id" => self.bot_id,
51
+ "attachments" => [{
52
+ "type" => "location",
53
+ "lng" => long.to_s,
54
+ "lat" => lat.to_s,
55
+ "name" => name
56
+ }]
57
+ }.to_json
58
+
59
+ res = Net::HTTP.start(self.post_uri.host, self.post_uri.port, :use_ssl => self.post_uri.scheme == "https") do |http|
60
+ http.request(req)
61
+ end
62
+ end
63
+
64
+ def run_callback_server(&callback_block)
65
+ Thread.start do
66
+ server = TCPServer.new("0.0.0.0", self.callback_port)
67
+ puts "Callback server running on port #{self.callback_port}"
68
+ loop do
69
+ Thread.start(server.accept) do |client|
70
+ res = []
71
+
72
+ while line = client.gets
73
+ res.push(line.chomp)
74
+ end
75
+
76
+ client.close
77
+ callback_body = JSON.parse(res.last)
78
+ callback_block.call(self, callback_body)
79
+ res.clear
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1 @@
1
+ require 'group_me_bot/bot'
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: group_me_bot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.1
5
+ platform: ruby
6
+ authors:
7
+ - Richard Rowe
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-23 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A GroupMe API for Ruby supporting message/image/location sending, with
14
+ callback server feature.
15
+ email: roweprogrammer@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/group_me_bot.rb
21
+ - lib/group_me_bot/bot.rb
22
+ homepage:
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: 2.0.0p481
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.4.4
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: A simple GroupMe bot API for Ruby.
46
+ test_files: []