botterscotch 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3e51821e158ad2d89876eb8d527b6ffb0f00c4338d706bd2955ab84764fd4457
4
+ data.tar.gz: 18abdd4e66c473084aa5988d58ce38fcd16448b82d056e1a2d5f5ca5b8e4b0f2
5
+ SHA512:
6
+ metadata.gz: 1c34f95d8e1f4fb33e3f356cd20a61bf44d0433443d8c75ff37dcb583037256620a8843570b3914ddc2d9fdcd601dcaeb214475e04de9538346b8a62c7e51d53
7
+ data.tar.gz: ca49a4ea33cc8fbdc845adc0f01fd8cf8e4772935dac298961e6d132dd95e0d1926d7f72579f313089871c4e575f943f1d8718973b65fcb532f5f69d938cf7bf
data/.editorconfig ADDED
File without changes
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ coverage
8
+ doc/
9
+ pkg
10
+ rdoc
11
+ spec/reports
12
+ test/tmp
13
+ test/version_tmp
14
+ tmp
15
+ *.bundle
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://gem.coop"
4
+
5
+ # Specify your gem's dependencies in testgem.gemspec
6
+ gemspec
7
+
8
+ gem "bundler", "~> 2.7"
9
+ gem "rake"
10
+ gem "rspec"
11
+ gem "standard"
12
+ gem "ruby-lsp"
data/README ADDED
@@ -0,0 +1,7 @@
1
+ # botterscotch
2
+
3
+ Shared utilities for writing mastodon bots
4
+
5
+ ## Copyright
6
+
7
+ Copyright (c) 2025 Daniel Senff. See LICENSE.md for further details.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rspec/core/rake_task"
4
+ require "bundler/gem_tasks"
5
+
6
+ # Default directory to look in is `/specs`
7
+ # Run with `rake spec`
8
+ RSpec::Core::RakeTask.new(:spec) do |task|
9
+ task.rspec_opts = ["--color", "--format", "documentation"]
10
+ end
11
+
12
+ task default: :spec
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "botterscotch/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "botterscotch"
9
+ spec.version = Botterscotch::VERSION
10
+ spec.license = "MIT"
11
+ spec.authors = ["Daniel Senff"]
12
+ spec.email = ["mail@danielsenff.de"]
13
+ spec.homepage = "http://codeberg.org/Dahie/botterscotch"
14
+ spec.summary = "Shared utilities for building Mastodon bots"
15
+ spec.description = "Shared utilities for building Mastodon bots"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+ spec.required_ruby_version = ">= 3"
21
+
22
+ spec.add_dependency("http")
23
+
24
+ spec.metadata["rubygems_mfa_required"] = "true"
25
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "http"
4
+
5
+ module Botterscotch
6
+ module Clients
7
+ class Gotosocial
8
+ def post_message(message, options = {})
9
+ form = {
10
+ status: message,
11
+ visibility: "unlisted",
12
+ language: "de"
13
+ }.merge(options)
14
+
15
+ yield(form) if block_given?
16
+
17
+ HTTP.headers(headers).post("#{config.server[:url]}/api/v1/statuses", form:)
18
+ end
19
+
20
+ private
21
+
22
+ def headers
23
+ {Authorization: "Bearer #{config.server[:access_token]}"}
24
+ end
25
+
26
+ def config
27
+ ::Botterscotch.configuration
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "http"
4
+
5
+ module Botterscotch
6
+ module Clients
7
+ class Mastodon
8
+ def post_message(message, options = {})
9
+ form = {
10
+ content: message,
11
+ visibility: "unlisted",
12
+ language: "de",
13
+ password: config.server[:access_token]
14
+ }.merge(options)
15
+
16
+ yield(form) if block_given?
17
+
18
+ HTTP.headers(accept: "application/json").post("#{config.server[:url]}/action/send", form:)
19
+ end
20
+
21
+ private
22
+
23
+ def config
24
+ ::Botterscotch.configuration
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,20 @@
1
+ # inspired by https://thoughtbot.com/blog/mygem-configure-block
2
+ require "logger"
3
+
4
+ module Botterscotch
5
+ class Configuration
6
+ attr_accessor :daily_fetch_at, :logger, :server, :monitoring_url
7
+
8
+ def initialize
9
+ @server = {
10
+ adapter: ENV.fetch("SERVER_ADAPTER", :mastodon).to_sym,
11
+ access_token: ENV.fetch("ACCESS_TOKEN", nil),
12
+ url: ENV.fetch("SERVER_URL", "https://example.com")
13
+ }
14
+ @monitoring_url = nil
15
+ @daily_fetch_at = "5 2 * * *"
16
+
17
+ @logger = Logger.new($stdout)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Botterscotch
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "botterscotch/configuration"
4
+ require_relative "botterscotch/clients/mastodon"
5
+ require_relative "botterscotch/clients/gotosocial"
6
+
7
+ module Botterscotch
8
+ def self.configuration
9
+ @@configuration ||= ::Botterscotch::Configuration.new
10
+ end
11
+
12
+ def self.configure
13
+ yield(configuration)
14
+ end
15
+ end
File without changes
@@ -0,0 +1,44 @@
1
+ require "spec_helper"
2
+ require "http"
3
+
4
+ describe Botterscotch::Clients::Gotosocial do
5
+ let(:config) { double(:configuration, server: {url: "https://example.com", access_token: "secret"}) }
6
+ let(:message) { "Hello, World!" }
7
+
8
+ before do
9
+ allow(::Botterscotch).to receive(:configuration).and_return(config)
10
+ allow(HTTP).to receive(:headers).and_return(HTTP)
11
+ end
12
+
13
+ it "posts a message with default visibility and language" do
14
+ expect(HTTP).to receive(:headers).with({Authorization: "Bearer secret"})
15
+ expect(HTTP).to receive(:post).with(
16
+ "#{config.server[:url]}/api/v1/statuses",
17
+ form: {
18
+ status: message,
19
+ visibility: "unlisted",
20
+ language: "de"
21
+ }
22
+ )
23
+ subject.post_message(message)
24
+ end
25
+
26
+ it "posts a message with custom options" do
27
+ options = {visibility: "public", language: "en"}
28
+ expect(HTTP).to receive(:headers).with({Authorization: "Bearer secret"})
29
+ expect(HTTP).to receive(:post).with(
30
+ "#{config.server[:url]}/api/v1/statuses",
31
+ form: {
32
+ status: message,
33
+ visibility: "public",
34
+ language: "en"
35
+ }
36
+ )
37
+ subject.post_message(message, options)
38
+ end
39
+
40
+ it "raises an error if the server returns a non-2xx response" do
41
+ allow(HTTP).to receive(:post).and_raise(HTTP::Error.new(401))
42
+ expect { subject.post_message(message) }.to raise_error HTTP::Error
43
+ end
44
+ end
@@ -0,0 +1,63 @@
1
+ require "spec_helper"
2
+
3
+ describe Botterscotch::Clients::Mastodon do
4
+ let(:config) { double(server: {url: "https://example.com", access_token: "123456"}) }
5
+ let(:mastodon_client) { described_class.new }
6
+
7
+ before do
8
+ allow(::Botterscotch).to receive(:configuration).and_return(config)
9
+ allow(HTTP).to receive(:headers).and_return(HTTP)
10
+ end
11
+
12
+ describe "#post_message" do
13
+ it "posts a message to Mastodon with default options" do
14
+ post_response = double(status: 200, body: "{\"message\":\"ok\"}")
15
+ expect(HTTP).to receive(:headers).with({accept: "application/json"})
16
+ expect(HTTP).to receive(:post).with(
17
+ "https://example.com/action/send",
18
+ form: hash_including(
19
+ content: "Hello, world!",
20
+ visibility: "unlisted",
21
+ language: "de",
22
+ password: config.server[:access_token]
23
+ )
24
+ ).and_return(post_response)
25
+ mastodon_client.post_message("Hello, world!")
26
+ end
27
+
28
+ it "posts a message to Mastodon with custom options" do
29
+ post_response = double(status: 200, body: "{\"message\":\"ok\"}")
30
+ allow(HTTP).to receive(:post).and_return(post_response)
31
+
32
+ mastodon_client.post_message("Hello, world!", visibility: "public", language: "en")
33
+
34
+ expect(HTTP).to have_received(:post).with(
35
+ "https://example.com/action/send",
36
+ form: hash_including(
37
+ content: "Hello, world!",
38
+ visibility: "public",
39
+ language: "en",
40
+ password: config.server[:access_token]
41
+ )
42
+ )
43
+ end
44
+
45
+ it "yields the form and tempfile to a block" do
46
+ post_response = double(status: 200, body: "{\"message\":\"ok\"}")
47
+ allow(HTTP).to receive(:post).and_return(post_response)
48
+
49
+ yielded_form = []
50
+
51
+ mastodon_client.post_message("Hello, world!", visibility: "public", language: "en") do |form|
52
+ yielded_form << form
53
+ end
54
+
55
+ expect(yielded_form).to eq([{
56
+ content: "Hello, world!",
57
+ visibility: "public",
58
+ language: "en",
59
+ password: config.server[:access_token]
60
+ }])
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,13 @@
1
+ require "bundler/setup"
2
+ Bundler.setup
3
+
4
+ require "botterscotch"
5
+
6
+ RSpec.configure do |config|
7
+ Botterscotch.configure do |config|
8
+ config.server = {
9
+ url: "https://example.com",
10
+ access_token: "helloworld"
11
+ }
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: botterscotch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Senff
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: http
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ description: Shared utilities for building Mastodon bots
27
+ email:
28
+ - mail@danielsenff.de
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - ".editorconfig"
34
+ - ".gitignore"
35
+ - Gemfile
36
+ - README
37
+ - Rakefile
38
+ - botterscotch.gemspec
39
+ - lib/botterscotch.rb
40
+ - lib/botterscotch/clients/gotosocial.rb
41
+ - lib/botterscotch/clients/mastodon.rb
42
+ - lib/botterscotch/configuration.rb
43
+ - lib/botterscotch/version.rb
44
+ - spec/blickpunkte_spec.rb
45
+ - spec/botterscotch/clients/gotosocial_spec.rb
46
+ - spec/botterscotch/clients/mastodon_spec.rb
47
+ - spec/spec_helper.rb
48
+ homepage: http://codeberg.org/Dahie/botterscotch
49
+ licenses:
50
+ - MIT
51
+ metadata:
52
+ rubygems_mfa_required: 'true'
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '3'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubygems_version: 3.6.9
68
+ specification_version: 4
69
+ summary: Shared utilities for building Mastodon bots
70
+ test_files: []