causeway 0.0.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
+ SHA256:
3
+ metadata.gz: a0c1a608aa0ccb33e5a87613f8b579ccc7f267241f63a3be0b2ba003f886f495
4
+ data.tar.gz: 7eca831aa60c63e743e031e7a9b428d73627c67210d9c9862498d0106a3df5ca
5
+ SHA512:
6
+ metadata.gz: ee4af941f3a3b55171b47bab9c0643d02a4a78d7ba4f307a63ff9b493c1915973c908f44b4b94c87b2c5525f8062555bddd14e32b03f3dea1824a28f2fd404a2
7
+ data.tar.gz: d31cf7ac701b0653e268108aac6e6a01d0775912379c8b7952326eb72398bff4ccc69a45460b596211358f66f26d019114b78a4dd86c983d1bf9f5f8a24db70b
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2026-08-24
4
+
5
+ - Initial release
@@ -0,0 +1,10 @@
1
+ # Code of Conduct
2
+
3
+ "causeway" follows [The Ruby Community Conduct Guideline](https://www.ruby-lang.org/en/conduct) in all "collaborative space", which is defined as community communications channels (such as mailing lists, submitted patches, commit comments, etc.):
4
+
5
+ * Participants will be tolerant of opposing views.
6
+ * Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
7
+ * When interpreting the words and actions of others, participants should always assume good intentions.
8
+ * Behaviour which can be reasonably considered harassment will not be tolerated.
9
+
10
+ If you have any concerns about behaviour within this project, please contact us at ["marc@fascination.works"](mailto:"marc@fascination.works").
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Marc Heiligers
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,37 @@
1
+ # Causeway
2
+
3
+ ## Installation
4
+
5
+ Install the gem and add to the application's Gemfile by executing:
6
+
7
+ ```bash
8
+ bundle add causeway
9
+ ```
10
+
11
+ If bundler is not being used to manage dependencies, install the gem by executing:
12
+
13
+ ```bash
14
+ gem install causeway
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ TODO: Write usage instructions here
20
+
21
+ ## Development
22
+
23
+ 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.
24
+
25
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
26
+
27
+ ## Contributing
28
+
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/FASCINATION-works/causeway/. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/FASCINATION-works/causeway/blob/main/CODE_OF_CONDUCT.md).
30
+
31
+ ## License
32
+
33
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
34
+
35
+ ## Code of Conduct
36
+
37
+ Everyone interacting in the Causeway project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/FASCINATION-works/causeway/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Causeway
4
+ class Configuration
5
+ attr_writer :bluesky_handle, :bluesky_app_password, :mastodon_token, :mastodon_instance
6
+
7
+ def initialize
8
+ @mastodon_instance = "https://mastodon.social"
9
+ end
10
+
11
+ def bluesky_handle = resolve(@bluesky_handle)
12
+ def bluesky_app_password = resolve(@bluesky_app_password)
13
+ def mastodon_token = resolve(@mastodon_token)
14
+ def mastodon_instance = resolve(@mastodon_instance)
15
+
16
+ private
17
+
18
+ def resolve(value)
19
+ value.respond_to?(:call) ? value.call : value
20
+ end
21
+ end
22
+
23
+ class << self
24
+ def configuration
25
+ @configuration ||= Configuration.new
26
+ end
27
+
28
+ def configure
29
+ yield(configuration)
30
+ end
31
+
32
+ def reset!
33
+ @configuration = Configuration.new
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Causeway
4
+ module Publishers
5
+ class Base
6
+ def name
7
+ raise NotImplementedError
8
+ end
9
+
10
+ # Returns { id:, url: } on success, { error: } on failure
11
+ def post(text)
12
+ raise NotImplementedError
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,110 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+ require "json"
5
+ require "uri"
6
+
7
+ module Causeway
8
+ module Publishers
9
+ class Bluesky < Base
10
+ API = "https://bsky.social"
11
+
12
+ def name
13
+ "Bluesky"
14
+ end
15
+
16
+ def post(text)
17
+ handle = Causeway.configuration.bluesky_handle
18
+ app_password = Causeway.configuration.bluesky_app_password
19
+
20
+ return { error: "Bluesky handle not configured." } unless handle && !handle.empty?
21
+ return { error: "Bluesky app password not configured." } unless app_password && !app_password.empty?
22
+
23
+ session = create_session(handle, app_password)
24
+ return session if session[:error]
25
+
26
+ facets = detect_facets(text)
27
+
28
+ record = {
29
+ "$type" => "app.bsky.feed.post",
30
+ "text" => text,
31
+ "createdAt" => Time.now.utc.strftime("%Y-%m-%dT%H:%M:%S.%3NZ")
32
+ }
33
+ record["facets"] = facets unless facets.empty?
34
+
35
+ body = {
36
+ "repo" => session[:did],
37
+ "collection" => "app.bsky.feed.post",
38
+ "record" => record
39
+ }
40
+
41
+ uri = URI("#{API}/xrpc/com.atproto.repo.createRecord")
42
+ response = https_post_json(uri, body, auth: session[:access_jwt])
43
+
44
+ unless response.is_a?(Net::HTTPSuccess)
45
+ return { error: "Bluesky API error: #{response.code} #{response.body}" }
46
+ end
47
+
48
+ data = JSON.parse(response.body)
49
+ rkey = data["uri"].split("/").last
50
+ { id: data["uri"], url: "https://bsky.app/profile/#{handle}/post/#{rkey}" }
51
+ end
52
+
53
+ private
54
+
55
+ def create_session(handle, app_password)
56
+ uri = URI("#{API}/xrpc/com.atproto.server.createSession")
57
+ body = { "identifier" => handle, "password" => app_password }
58
+ response = https_post_json(uri, body)
59
+
60
+ unless response.is_a?(Net::HTTPSuccess)
61
+ return { error: "Bluesky auth failed: #{response.code} #{response.body}" }
62
+ end
63
+
64
+ data = JSON.parse(response.body)
65
+ { did: data["did"], access_jwt: data["accessJwt"] }
66
+ end
67
+
68
+ def detect_facets(text)
69
+ facets = []
70
+
71
+ # URLs
72
+ text.scan(/(https?:\/\/[^\s)]+)/) do
73
+ match = Regexp.last_match
74
+ byte_start = text[0...match.begin(0)].bytesize
75
+ byte_end = byte_start + match[0].bytesize
76
+ facets << {
77
+ "index" => { "byteStart" => byte_start, "byteEnd" => byte_end },
78
+ "features" => [{ "$type" => "app.bsky.richtext.facet#link", "uri" => match[0] }]
79
+ }
80
+ end
81
+
82
+ # Hashtags
83
+ text.scan(/(?<=\s|^)#(\w+)/) do
84
+ match = Regexp.last_match
85
+ tag_with_hash = "##{match[1]}"
86
+ byte_start = text[0...match.begin(0)].bytesize
87
+ byte_end = byte_start + tag_with_hash.bytesize
88
+ facets << {
89
+ "index" => { "byteStart" => byte_start, "byteEnd" => byte_end },
90
+ "features" => [{ "$type" => "app.bsky.richtext.facet#tag", "tag" => match[1] }]
91
+ }
92
+ end
93
+
94
+ facets
95
+ end
96
+
97
+ def https_post_json(uri, body, auth: nil)
98
+ http = Net::HTTP.new(uri.host, uri.port)
99
+ http.use_ssl = true
100
+
101
+ request = Net::HTTP::Post.new(uri)
102
+ request["Content-Type"] = "application/json"
103
+ request["Authorization"] = "Bearer #{auth}" if auth
104
+ request.body = JSON.generate(body)
105
+
106
+ http.request(request)
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+ require "json"
5
+ require "uri"
6
+
7
+ module Causeway
8
+ module Publishers
9
+ class Mastodon < Base
10
+ def name
11
+ "Mastodon"
12
+ end
13
+
14
+ def post(text)
15
+ token = Causeway.configuration.mastodon_token
16
+ instance = Causeway.configuration.mastodon_instance || "https://mastodon.social"
17
+
18
+ return { error: "Mastodon token not configured." } unless token && !token.empty?
19
+
20
+ uri = URI("#{instance}/api/v1/statuses")
21
+ http = Net::HTTP.new(uri.host, uri.port)
22
+ http.use_ssl = uri.scheme == "https"
23
+
24
+ request = Net::HTTP::Post.new(uri)
25
+ request["Authorization"] = "Bearer #{token}"
26
+ request.set_form_data("status" => text)
27
+
28
+ response = http.request(request)
29
+ unless response.is_a?(Net::HTTPSuccess)
30
+ return { error: "Mastodon API error: #{response.code} #{response.body}" }
31
+ end
32
+
33
+ data = JSON.parse(response.body)
34
+ { id: data["id"], url: data["url"] }
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Causeway
4
+ VERSION = "0.0.1"
5
+ end
data/lib/causeway.rb ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "causeway/version"
4
+ require_relative "causeway/configuration"
5
+ require_relative "causeway/publishers/base"
6
+ require_relative "causeway/publishers/bluesky"
7
+ require_relative "causeway/publishers/mastodon"
8
+
9
+ module Causeway
10
+ class Error < StandardError; end
11
+ end
data/sig/causeway.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Causeway
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: causeway
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Marc Heiligers
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: Rubygem for publishing posts to social media.
13
+ email:
14
+ - rubygems@heiligers.us
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - CHANGELOG.md
20
+ - CODE_OF_CONDUCT.md
21
+ - LICENSE.txt
22
+ - README.md
23
+ - Rakefile
24
+ - lib/causeway.rb
25
+ - lib/causeway/configuration.rb
26
+ - lib/causeway/publishers/base.rb
27
+ - lib/causeway/publishers/bluesky.rb
28
+ - lib/causeway/publishers/mastodon.rb
29
+ - lib/causeway/version.rb
30
+ - sig/causeway.rbs
31
+ homepage: https://github.com/FASCINATION-works/causeway.
32
+ licenses:
33
+ - MIT
34
+ metadata:
35
+ allowed_push_host: https://rubygems.org
36
+ homepage_uri: https://github.com/FASCINATION-works/causeway.
37
+ source_code_uri: https://github.com/FASCINATION-works/causeway.
38
+ changelog_uri: https://github.com/FASCINATION-works/causeway/blob/main/CHANGELOG.md
39
+ rubygems_mfa_required: 'true'
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 3.2.0
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubygems_version: 4.0.16
55
+ specification_version: 4
56
+ summary: Publish posts to social media.
57
+ test_files: []