boppers 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +14 -2
  3. data/README.md +282 -10
  4. data/Rakefile +1 -0
  5. data/boppers.gemspec +9 -1
  6. data/exe/boppers +1 -0
  7. data/gems.locked +98 -1
  8. data/images/boppers.png +0 -0
  9. data/images/boppers@2x.png +0 -0
  10. data/images/logo.png +0 -0
  11. data/images/logo.svg +10 -0
  12. data/lib/boppers.rb +35 -0
  13. data/lib/boppers/cli.rb +55 -0
  14. data/lib/boppers/configuration.rb +15 -0
  15. data/lib/boppers/generator/app.rb +28 -0
  16. data/lib/boppers/generator/app/Procfile +1 -0
  17. data/lib/boppers/generator/app/app.json +8 -0
  18. data/lib/boppers/generator/app/config/boppers.rb +83 -0
  19. data/lib/boppers/generator/app/gems.rb +7 -0
  20. data/lib/boppers/generator/plugin.rb +64 -0
  21. data/lib/boppers/generator/plugin/.gitignore +8 -0
  22. data/lib/boppers/generator/plugin/.rubocop.yml +116 -0
  23. data/lib/boppers/generator/plugin/.travis.yml +16 -0
  24. data/lib/boppers/generator/plugin/CODE_OF_CONDUCT.md +74 -0
  25. data/lib/boppers/generator/plugin/LICENSE.txt +21 -0
  26. data/lib/boppers/generator/plugin/README.erb +45 -0
  27. data/lib/boppers/generator/plugin/Rakefile +12 -0
  28. data/lib/boppers/generator/plugin/gems.rb +2 -0
  29. data/lib/boppers/generator/plugin/gemspec.erb +29 -0
  30. data/lib/boppers/generator/plugin/lib/entry.erb +4 -0
  31. data/lib/boppers/generator/plugin/lib/main.erb +10 -0
  32. data/lib/boppers/generator/plugin/lib/version.erb +7 -0
  33. data/lib/boppers/generator/plugin/test/test_file.erb +9 -0
  34. data/lib/boppers/generator/plugin/test/test_helper.erb +11 -0
  35. data/lib/boppers/http_client.rb +9 -0
  36. data/lib/boppers/notifier/hipchat.rb +26 -0
  37. data/lib/boppers/notifier/pushover.rb +27 -0
  38. data/lib/boppers/notifier/sendgrid.rb +40 -0
  39. data/lib/boppers/notifier/slack.rb +35 -0
  40. data/lib/boppers/notifier/stdout.rb +21 -0
  41. data/lib/boppers/notifier/telegram.rb +26 -0
  42. data/lib/boppers/notifier/twitter.rb +34 -0
  43. data/lib/boppers/runner.rb +37 -0
  44. data/lib/boppers/testing.rb +6 -0
  45. data/lib/boppers/testing/bopper_linter.rb +19 -0
  46. data/lib/boppers/testing/notifier_linter.rb +33 -0
  47. data/lib/boppers/utils.rb +11 -0
  48. data/lib/boppers/version.rb +1 -1
  49. data/setup/telegram.rb +20 -0
  50. metadata +142 -5
  51. data/Gemfile.lock +0 -24
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Boppers
4
+ module Notifier
5
+ class Twitter
6
+ attr_reader :consumer_key, :consumer_secret,
7
+ :access_token, :access_secret, :user, :subscribe
8
+
9
+ def initialize(consumer_key:, consumer_secret:, access_token:, access_secret:, user:, subscribe: nil)
10
+ require "twitter"
11
+
12
+ @consumer_key = consumer_key
13
+ @consumer_secret = consumer_secret
14
+ @access_token = access_token
15
+ @access_secret = access_secret
16
+ @user = user
17
+ @subscribe = subscribe
18
+ end
19
+
20
+ def call(title, message, _options)
21
+ client = ::Twitter::REST::Client.new do |config|
22
+ config.consumer_key = consumer_key
23
+ config.consumer_secret = consumer_secret
24
+ config.access_token = access_token
25
+ config.access_token_secret = access_secret
26
+ end
27
+
28
+ body = "#{title}\n\n#{message}"
29
+
30
+ client.create_direct_message(user, body)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Boppers
4
+ class Runner
5
+ def boppers
6
+ Boppers.configuration.boppers
7
+ end
8
+
9
+ def run_bopper(bopper)
10
+ interval = if bopper.respond_to?(:interval)
11
+ bopper.interval
12
+ else
13
+ 60
14
+ end
15
+
16
+ Thread.new do
17
+ loop do
18
+ begin
19
+ bopper.call
20
+ rescue StandardError => error
21
+ Boppers.configuration.handle_exception&.call(error)
22
+ end
23
+
24
+ sleep interval
25
+ end
26
+ end
27
+ end
28
+
29
+ def call
30
+ threads = boppers.each_with_object([]) do |bopper, buffer|
31
+ buffer << run_bopper(bopper)
32
+ end
33
+
34
+ threads.each(&:join)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "minitest"
4
+
5
+ require "boppers/testing/bopper_linter"
6
+ require "boppers/testing/notifier_linter"
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Boppers
4
+ module Testing
5
+ class BopperLinter
6
+ extend Minitest::Assertions
7
+
8
+ class << self
9
+ attr_accessor :assertions
10
+ end
11
+
12
+ @assertions = 0
13
+
14
+ def self.call(bopper)
15
+ assert_respond_to(bopper, :call)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Boppers
4
+ module Testing
5
+ class NotifierLinter
6
+ extend Minitest::Assertions
7
+
8
+ class << self
9
+ attr_accessor :assertions
10
+ end
11
+
12
+ @assertions = 0
13
+
14
+ def self.call(notifier)
15
+ assert_respond_to(notifier, :call)
16
+ assert_initialize_method(notifier)
17
+ assert_call_method(notifier)
18
+ end
19
+
20
+ def self.assert_initialize_method(notifier)
21
+ message = "Notifier must implement #{notifier.class}.new(subscribe: nil)"
22
+ initialize_method = notifier.method(:initialize)
23
+ assert_includes initialize_method.parameters, %i{key subscribe}, message
24
+ end
25
+
26
+ def self.assert_call_method(notifier)
27
+ message = "Notifier must implement #{notifier.class}#call(title, message, options)"
28
+ call_method = notifier.method(:call)
29
+ assert_equal 3, call_method.parameters.size, message
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Boppers
4
+ module Utils
5
+ def self.symbolize_keys(hash)
6
+ hash.each_with_object({}) do |(k, v), target|
7
+ target[k.to_sym] = v
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Boppers
4
- VERSION = "0.0.0"
4
+ VERSION = "0.0.1"
5
5
  end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "aitch"
4
+
5
+ $stdout << "What's your Telegram bot token? "
6
+ bot_token = gets.chomp
7
+
8
+ response = Aitch.get("https://api.telegram.org/bot#{bot_token}/getUpdates")
9
+ payload = response
10
+ .data["result"]
11
+ .sort_by {|result| result["update_id"] }
12
+ .last
13
+
14
+ if payload
15
+ channel_id = payload.dig("message", "chat", "id")
16
+ puts "The channel id is #{channel_id}"
17
+ else
18
+ puts "No messages found."
19
+ exit 1
20
+ end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boppers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-06 00:00:00.000000000 Z
11
+ date: 2017-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: aitch
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: bundler
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -52,7 +80,77 @@ dependencies:
52
80
  - - ">="
53
81
  - !ruby/object:Gem::Version
54
82
  version: '0'
55
- description: Bots.
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-meta
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: mail
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: telegram_bot
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: twitter
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: A simple bot framework for individuals.
56
154
  email:
57
155
  - fnando.vieira@gmail.com
58
156
  executables:
@@ -64,7 +162,6 @@ files:
64
162
  - ".rubocop.yml"
65
163
  - ".travis.yml"
66
164
  - CODE_OF_CONDUCT.md
67
- - Gemfile.lock
68
165
  - LICENSE.txt
69
166
  - README.md
70
167
  - Rakefile
@@ -74,8 +171,48 @@ files:
74
171
  - exe/boppers
75
172
  - gems.locked
76
173
  - gems.rb
174
+ - images/boppers.png
175
+ - images/boppers@2x.png
176
+ - images/logo.png
177
+ - images/logo.svg
77
178
  - lib/boppers.rb
179
+ - lib/boppers/cli.rb
180
+ - lib/boppers/configuration.rb
181
+ - lib/boppers/generator/app.rb
182
+ - lib/boppers/generator/app/Procfile
183
+ - lib/boppers/generator/app/app.json
184
+ - lib/boppers/generator/app/config/boppers.rb
185
+ - lib/boppers/generator/app/gems.rb
186
+ - lib/boppers/generator/plugin.rb
187
+ - lib/boppers/generator/plugin/.gitignore
188
+ - lib/boppers/generator/plugin/.rubocop.yml
189
+ - lib/boppers/generator/plugin/.travis.yml
190
+ - lib/boppers/generator/plugin/CODE_OF_CONDUCT.md
191
+ - lib/boppers/generator/plugin/LICENSE.txt
192
+ - lib/boppers/generator/plugin/README.erb
193
+ - lib/boppers/generator/plugin/Rakefile
194
+ - lib/boppers/generator/plugin/gems.rb
195
+ - lib/boppers/generator/plugin/gemspec.erb
196
+ - lib/boppers/generator/plugin/lib/entry.erb
197
+ - lib/boppers/generator/plugin/lib/main.erb
198
+ - lib/boppers/generator/plugin/lib/version.erb
199
+ - lib/boppers/generator/plugin/test/test_file.erb
200
+ - lib/boppers/generator/plugin/test/test_helper.erb
201
+ - lib/boppers/http_client.rb
202
+ - lib/boppers/notifier/hipchat.rb
203
+ - lib/boppers/notifier/pushover.rb
204
+ - lib/boppers/notifier/sendgrid.rb
205
+ - lib/boppers/notifier/slack.rb
206
+ - lib/boppers/notifier/stdout.rb
207
+ - lib/boppers/notifier/telegram.rb
208
+ - lib/boppers/notifier/twitter.rb
209
+ - lib/boppers/runner.rb
210
+ - lib/boppers/testing.rb
211
+ - lib/boppers/testing/bopper_linter.rb
212
+ - lib/boppers/testing/notifier_linter.rb
213
+ - lib/boppers/utils.rb
78
214
  - lib/boppers/version.rb
215
+ - setup/telegram.rb
79
216
  homepage: https://rubygems.org/gems/boppers
80
217
  licenses:
81
218
  - MIT
@@ -99,5 +236,5 @@ rubyforge_project:
99
236
  rubygems_version: 2.6.13
100
237
  signing_key:
101
238
  specification_version: 4
102
- summary: Bots.
239
+ summary: A simple bot framework for individuals.
103
240
  test_files: []
@@ -1,24 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- boppers (0.0.0)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- minitest (4.7.5)
10
- minitest-test (1.1.0)
11
- minitest (~> 4.0)
12
- rake (12.2.1)
13
-
14
- PLATFORMS
15
- ruby
16
-
17
- DEPENDENCIES
18
- boppers!
19
- bundler
20
- minitest-test
21
- rake
22
-
23
- BUNDLED WITH
24
- 1.16.0