botterscotch 0.1.0 → 0.2.0
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 +4 -4
- data/botterscotch.gemspec +1 -0
- data/lib/botterscotch/app.rb +34 -0
- data/lib/botterscotch/version.rb +1 -1
- data/lib/botterscotch.rb +1 -0
- data/spec/botterscotch/app_spec.rb +132 -0
- metadata +17 -2
- data/spec/blickpunkte_spec.rb +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c393ec7fe3ae9afee4d96272dc43c4f52906194dc1111a60e9e9115c544206f5
|
|
4
|
+
data.tar.gz: 460389268bd5ad2d09ae7e5094f05c08e9f42a64f8d150e0c92bb52d736e33ef
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 10a8ffd26821d703ad1d164e32408508b7b883019c1d7ea8882f5a3e73c4a88b6c81739270bcd4fbcac4571c06e35e2ba4bd021f48286da321299c39ecd04b35
|
|
7
|
+
data.tar.gz: a4c8fb8096ebbafcd7df19127f176ec7515f92a1c186626bac0847ff6e6c3e49e3c07dcd780dc9928648b40399427211974dc341a992588971fa31b81ce129ad
|
data/botterscotch.gemspec
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require "rufus-scheduler"
|
|
2
|
+
|
|
3
|
+
module Botterscotch
|
|
4
|
+
class App
|
|
5
|
+
def client_class
|
|
6
|
+
case Botterscotch.configuration.server[:adapter]
|
|
7
|
+
when :mastodon
|
|
8
|
+
::Botterscotch::Clients::Mastodon
|
|
9
|
+
when :gotosocial
|
|
10
|
+
::Botterscotch::Clients::Gotosocial
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def client
|
|
15
|
+
@client ||= client_class.new
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def log
|
|
19
|
+
config.logger
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def config
|
|
23
|
+
::Botterscotch.configuration
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def scheduler
|
|
27
|
+
@scheduler ||= ::Rufus::Scheduler.new
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def report_monitoring
|
|
31
|
+
HTTP.get(config.monitoring_url) unless config.monitoring_url.nil? || config.monitoring_url.empty?
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
data/lib/botterscotch/version.rb
CHANGED
data/lib/botterscotch.rb
CHANGED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
RSpec.describe Botterscotch::App do
|
|
4
|
+
let(:app) { Botterscotch::App.new }
|
|
5
|
+
|
|
6
|
+
describe "#client_class" do
|
|
7
|
+
context "when server adapter is :mastodon" do
|
|
8
|
+
before do
|
|
9
|
+
allow(Botterscotch).to receive(:configuration) { double(server: {adapter: :mastodon}) }
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "returns the Mastodon client class" do
|
|
13
|
+
expect(app.send(:client_class)).to eq(::Botterscotch::Clients::Mastodon)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
context "when server adapter is :gotosocial" do
|
|
18
|
+
before do
|
|
19
|
+
allow(Botterscotch).to receive(:configuration) { double(server: {adapter: :gotosocial}) }
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "returns the Gotosocial client class" do
|
|
23
|
+
expect(app.send(:client_class)).to eq(::Botterscotch::Clients::Gotosocial)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
context "when server adapter is not set" do
|
|
28
|
+
before do
|
|
29
|
+
allow(Botterscotch).to receive(:configuration) { double(server: {}) }
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "returns nil" do
|
|
33
|
+
expect(app.send(:client_class)).to be_nil
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
describe "#client" do
|
|
39
|
+
let(:configuration) { double(server: {adapter: :mastodon}) }
|
|
40
|
+
|
|
41
|
+
before do
|
|
42
|
+
allow(Botterscotch).to receive(:configuration) { configuration }
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "returns an instance of the client_class" do
|
|
46
|
+
expect(app.client).to be_an_instance_of(::Botterscotch::Clients::Mastodon)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "memoizes the instance" do
|
|
50
|
+
first = app.client
|
|
51
|
+
second = app.client
|
|
52
|
+
expect(first).to eq(second)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
describe "#logger" do
|
|
57
|
+
let(:configuration) { double(logger: "test_logger") }
|
|
58
|
+
|
|
59
|
+
before do
|
|
60
|
+
allow(Botterscotch).to receive(:configuration) { configuration }
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "returns the logger" do
|
|
64
|
+
expect(app.log).to eq("test_logger")
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
describe "#config" do
|
|
69
|
+
let(:configuration) { double }
|
|
70
|
+
|
|
71
|
+
before do
|
|
72
|
+
allow(Botterscotch).to receive(:configuration) { configuration }
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "returns the configuration" do
|
|
76
|
+
expect(app.config).to eq(configuration)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it "returns the same object on multiple calls" do
|
|
80
|
+
first = app.config
|
|
81
|
+
second = app.config
|
|
82
|
+
expect(first).to eq(second)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
describe "#scheduler" do
|
|
87
|
+
it "returns a new Rufus::Scheduler on first call" do
|
|
88
|
+
expect(app.scheduler).to be_an_instance_of(Rufus::Scheduler)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it "returns the same instance on subsequent calls" do
|
|
92
|
+
first = app.scheduler
|
|
93
|
+
second = app.scheduler
|
|
94
|
+
expect(first).to eq(second)
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
describe "#report_monitoring" do
|
|
99
|
+
before do
|
|
100
|
+
Botterscotch.configure do |config|
|
|
101
|
+
config.monitoring_url = url
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
context "when monitoring_url is present" do
|
|
106
|
+
let(:url) { "http://example.com" }
|
|
107
|
+
|
|
108
|
+
it "calls HTTP.get with the monitoring url" do
|
|
109
|
+
expect(HTTP).to receive(:get).with("http://example.com")
|
|
110
|
+
app.report_monitoring
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
context "when monitoring_url is nil" do
|
|
115
|
+
let(:url) { nil }
|
|
116
|
+
|
|
117
|
+
it "does not call HTTP.get" do
|
|
118
|
+
expect(HTTP).not_to receive(:get)
|
|
119
|
+
app.report_monitoring
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
context "when monitoring_url is empty string" do
|
|
124
|
+
let(:url) { "" }
|
|
125
|
+
|
|
126
|
+
it "does not call HTTP.get" do
|
|
127
|
+
expect(HTTP).not_to receive(:get)
|
|
128
|
+
app.report_monitoring
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: botterscotch
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daniel Senff
|
|
@@ -23,6 +23,20 @@ dependencies:
|
|
|
23
23
|
- - ">="
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
25
|
version: '0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: rufus-scheduler
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
26
40
|
description: Shared utilities for building Mastodon bots
|
|
27
41
|
email:
|
|
28
42
|
- mail@danielsenff.de
|
|
@@ -37,11 +51,12 @@ files:
|
|
|
37
51
|
- Rakefile
|
|
38
52
|
- botterscotch.gemspec
|
|
39
53
|
- lib/botterscotch.rb
|
|
54
|
+
- lib/botterscotch/app.rb
|
|
40
55
|
- lib/botterscotch/clients/gotosocial.rb
|
|
41
56
|
- lib/botterscotch/clients/mastodon.rb
|
|
42
57
|
- lib/botterscotch/configuration.rb
|
|
43
58
|
- lib/botterscotch/version.rb
|
|
44
|
-
- spec/
|
|
59
|
+
- spec/botterscotch/app_spec.rb
|
|
45
60
|
- spec/botterscotch/clients/gotosocial_spec.rb
|
|
46
61
|
- spec/botterscotch/clients/mastodon_spec.rb
|
|
47
62
|
- spec/spec_helper.rb
|
data/spec/blickpunkte_spec.rb
DELETED
|
File without changes
|