From d261a815e9e82f06f4e6c6a9a5945d87e2f638bf Mon Sep 17 00:00:00 2001 From: Eli <9064062+snood1205@users.noreply.github.com> Date: Wed, 16 Apr 2025 12:35:29 -0400 Subject: [PATCH 1/4] Scaffold com.atproto.* --- lib/arroba/com.rb | 13 +++++++++++++ lib/arroba/com/atproto.rb | 21 +++++++++++++++++++++ lib/arroba/com/atproto/admin.rb | 10 ++++++++++ lib/arroba/com/atproto/identity.rb | 10 ++++++++++ lib/arroba/com/atproto/label.rb | 10 ++++++++++ lib/arroba/com/atproto/moderation.rb | 10 ++++++++++ lib/arroba/com/atproto/repo.rb | 10 ++++++++++ lib/arroba/com/atproto/server.rb | 10 ++++++++++ lib/arroba/com/atproto/sync.rb | 10 ++++++++++ 9 files changed, 104 insertions(+) create mode 100644 lib/arroba/com.rb create mode 100644 lib/arroba/com/atproto.rb create mode 100644 lib/arroba/com/atproto/admin.rb create mode 100644 lib/arroba/com/atproto/identity.rb create mode 100644 lib/arroba/com/atproto/label.rb create mode 100644 lib/arroba/com/atproto/moderation.rb create mode 100644 lib/arroba/com/atproto/repo.rb create mode 100644 lib/arroba/com/atproto/server.rb create mode 100644 lib/arroba/com/atproto/sync.rb diff --git a/lib/arroba/com.rb b/lib/arroba/com.rb new file mode 100644 index 0000000..57542ed --- /dev/null +++ b/lib/arroba/com.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require_relative 'com/atproto' + +module Arroba + class Com + attr_reader :atproto + + def initialize(client) + @atproto = ATProto.new(client) + end + end +end diff --git a/lib/arroba/com/atproto.rb b/lib/arroba/com/atproto.rb new file mode 100644 index 0000000..ad87505 --- /dev/null +++ b/lib/arroba/com/atproto.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require_relative 'atproto/admin' +require_relative 'atproto/identity' +require_relative 'atproto/label' +require_relative 'atproto/moderation' +require_relative 'atproto/repo' +require_relative 'atproto/server' +require_relative 'atproto/sync' + +module Arroba + class Com + class ATProto + def initialize(client) + @client = client + end + + def admin = @admin ||= Admin.new(@client) + end + end +end diff --git a/lib/arroba/com/atproto/admin.rb b/lib/arroba/com/atproto/admin.rb new file mode 100644 index 0000000..5ae7de8 --- /dev/null +++ b/lib/arroba/com/atproto/admin.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module Arroba + class Com + class ATProto + class Admin < BaseResource + end + end + end +end diff --git a/lib/arroba/com/atproto/identity.rb b/lib/arroba/com/atproto/identity.rb new file mode 100644 index 0000000..f809744 --- /dev/null +++ b/lib/arroba/com/atproto/identity.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module Arroba + class Com + class ATProto + class Identity < BaseResource + end + end + end +end diff --git a/lib/arroba/com/atproto/label.rb b/lib/arroba/com/atproto/label.rb new file mode 100644 index 0000000..5c711e2 --- /dev/null +++ b/lib/arroba/com/atproto/label.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module Arroba + class Com + class ATProto + class Label < BaseResource + end + end + end +end diff --git a/lib/arroba/com/atproto/moderation.rb b/lib/arroba/com/atproto/moderation.rb new file mode 100644 index 0000000..7be5d28 --- /dev/null +++ b/lib/arroba/com/atproto/moderation.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module Arroba + class Com + class ATProto + class Moderation < BaseResource + end + end + end +end diff --git a/lib/arroba/com/atproto/repo.rb b/lib/arroba/com/atproto/repo.rb new file mode 100644 index 0000000..6f80122 --- /dev/null +++ b/lib/arroba/com/atproto/repo.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module Arroba + class Com + class ATProto + class Repo < BaseResource + end + end + end +end diff --git a/lib/arroba/com/atproto/server.rb b/lib/arroba/com/atproto/server.rb new file mode 100644 index 0000000..0e05c13 --- /dev/null +++ b/lib/arroba/com/atproto/server.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module Arroba + class Com + class ATProto + class Server < BaseResource + end + end + end +end diff --git a/lib/arroba/com/atproto/sync.rb b/lib/arroba/com/atproto/sync.rb new file mode 100644 index 0000000..c1b27c0 --- /dev/null +++ b/lib/arroba/com/atproto/sync.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module Arroba + class Com + class ATProto + class Sync < BaseResource + end + end + end +end From 7bb798394100a7847397f132e5b097d58d9efbec Mon Sep 17 00:00:00 2001 From: Eli <9064062+snood1205@users.noreply.github.com> Date: Mon, 21 Apr 2025 12:28:58 -0400 Subject: [PATCH 2/4] comt.atproto.admin.* is done --- lib/arroba/app/bsky/actor.rb | 2 -- lib/arroba/app/bsky/feed.rb | 2 -- lib/arroba/app/bsky/graph.rb | 2 -- lib/arroba/base_resource.rb | 2 ++ lib/arroba/chat/bsky/convo.rb | 2 -- lib/arroba/client.rb | 17 ++++++++++++++++- lib/arroba/com/atproto.rb | 1 + lib/arroba/com/atproto/admin.rb | 15 +++++++++++++++ lib/arroba/com/atproto/identity.rb | 1 + lib/arroba/http_client.rb | 6 ++++++ lib/arroba/validations/limitable.rb | 6 +++--- 11 files changed, 44 insertions(+), 12 deletions(-) diff --git a/lib/arroba/app/bsky/actor.rb b/lib/arroba/app/bsky/actor.rb index ad07ad2..dffaf68 100644 --- a/lib/arroba/app/bsky/actor.rb +++ b/lib/arroba/app/bsky/actor.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require_relative '../../validations' - module Arroba class App class BSky diff --git a/lib/arroba/app/bsky/feed.rb b/lib/arroba/app/bsky/feed.rb index 7f4ad04..ac162ba 100644 --- a/lib/arroba/app/bsky/feed.rb +++ b/lib/arroba/app/bsky/feed.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require_relative '../../validations' - module Arroba class App class BSky diff --git a/lib/arroba/app/bsky/graph.rb b/lib/arroba/app/bsky/graph.rb index f1d5da8..de92a16 100644 --- a/lib/arroba/app/bsky/graph.rb +++ b/lib/arroba/app/bsky/graph.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require_relative '../../validations' - module Arroba class App class BSky diff --git a/lib/arroba/base_resource.rb b/lib/arroba/base_resource.rb index 717a766..162066e 100644 --- a/lib/arroba/base_resource.rb +++ b/lib/arroba/base_resource.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require_relative 'validations' + module Arroba # Serves as a base class for all resources in the Arroba gem. # diff --git a/lib/arroba/chat/bsky/convo.rb b/lib/arroba/chat/bsky/convo.rb index 7ca33c6..778b1ef 100644 --- a/lib/arroba/chat/bsky/convo.rb +++ b/lib/arroba/chat/bsky/convo.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require_relative '../../validations' - module Arroba class Chat class BSky diff --git a/lib/arroba/client.rb b/lib/arroba/client.rb index 31467cc..9334edb 100644 --- a/lib/arroba/client.rb +++ b/lib/arroba/client.rb @@ -3,19 +3,23 @@ require_relative 'base_resource' require_relative 'app' require_relative 'chat' +require_relative 'com' require_relative 'http_client' module Arroba # This class is the main entry point for the Arroba gem. # It provides a simple interface to interact with the Bluesky API. + # pds_url is optional and if provided is only used for com.atproto.* and not app.bsky.* or chat.bsky.* requests, + # this could change in future versions. # # @example # app = Arroba::Client.new(identifier: 'your_identifier', password: 'your_password') # app.bsky.actor.get_profile(actor: 'example_handle') class Client - def initialize(identifier: nil, password: nil, auth_url: 'https://bsky.social') + def initialize(identifier: nil, password: nil, auth_url: 'https://bsky.social', pds_url: nil) raise ArgumentError, 'Both identifier and password are required' if identifier.nil? || password.nil? + @pds_url = pds_url @client = HTTPClient.new(identifier:, password:, auth_url:) end @@ -27,5 +31,16 @@ def chat @client.proxy_for_chat! @chat = Chat.new(@client) end + + def com = @com ||= Com.new(pds_client) + + private + + def pds_client + return @client if @pds_url.nil? + return @pds_client if @pds_client + + @pds_client ||= @client.pds_client_with_url @pds_url + end end end diff --git a/lib/arroba/com/atproto.rb b/lib/arroba/com/atproto.rb index ad87505..f227cf8 100644 --- a/lib/arroba/com/atproto.rb +++ b/lib/arroba/com/atproto.rb @@ -16,6 +16,7 @@ def initialize(client) end def admin = @admin ||= Admin.new(@client) + def identity = @identity ||= Identity.new(@client) end end end diff --git a/lib/arroba/com/atproto/admin.rb b/lib/arroba/com/atproto/admin.rb index 5ae7de8..96556a1 100644 --- a/lib/arroba/com/atproto/admin.rb +++ b/lib/arroba/com/atproto/admin.rb @@ -4,6 +4,21 @@ module Arroba class Com class ATProto class Admin < BaseResource + include Validations::Limitable + basic_post :delete_account, :did + basic_post :disable_account_invites, :account, note: nil + basic_post :disable_invite_codes, codes: nil, accounts: nil + basic_post :enable_account_invites, :account, note: nil + basic_get :get_account_info, :did + basic_get :get_account_infos, :dids + get_with_enforced_limit :get_invite_codes, sort: nil, max: 500 + basic_get :get_subject_status, did: nil, uri: nil, blob: nil + get_with_enforced_limit :search_accounts, email: nil + basic_post :send_email, :recipient_did, :content, :sended_did, subject: nil, comment: nil + basic_post :update_account_email, :account, :email + basic_post :update_account_handle, :account, :handle + basic_post :update_account_password, :account, :password + basic_post :update_subject_status, :subject, takedown: nil, deactivated: nil end end end diff --git a/lib/arroba/com/atproto/identity.rb b/lib/arroba/com/atproto/identity.rb index f809744..0d54dd8 100644 --- a/lib/arroba/com/atproto/identity.rb +++ b/lib/arroba/com/atproto/identity.rb @@ -4,6 +4,7 @@ module Arroba class Com class ATProto class Identity < BaseResource + basic_get :get_recommended_did_credentials end end end diff --git a/lib/arroba/http_client.rb b/lib/arroba/http_client.rb index fe1f175..cb1f630 100644 --- a/lib/arroba/http_client.rb +++ b/lib/arroba/http_client.rb @@ -50,6 +50,12 @@ def proxy_for_chat! @proxy_check = 'chat' end + def pds_client_with_url(pds_url) + dup_client = dup + dup_client.instance_variable_set(:@base_url, pds_url) + dup_client + end + private def authenticate!(auth_url, identifier, password) diff --git a/lib/arroba/validations/limitable.rb b/lib/arroba/validations/limitable.rb index 461638a..98e04f3 100644 --- a/lib/arroba/validations/limitable.rb +++ b/lib/arroba/validations/limitable.rb @@ -4,7 +4,7 @@ module Arroba module Validations # Limitable is a module that provides functionality to enforce limits on query parameters. module Limitable - DEFAULT_LIMIT = ->(limit: nil, **) { enforce_limit! limit, min: 1, max: 100 }.freeze + DEFAULT_LIMIT = ->(limit: nil, min: 1, max: 100, **) { enforce_limit! limit, min:, max: }.freeze def self.enforce_limit!(limit, min:, max:, name: 'Limit') return if limit.nil? || (limit.is_a?(Integer) && limit.between?(min, max)) @@ -17,9 +17,9 @@ def self.included(base) end module ClassMethods - def get_with_enforced_limit(method_name, *, limit: nil, cursor: nil, **) + def get_with_enforced_limit(method_name, *, limit: nil, cursor: nil, min: 1, max: 100, **) basic_get method_name, *, limit:, cursor:, ** do |**query_params| - DEFAULT_LIMIT.call(limit:, **query_params) + DEFAULT_LIMIT.call(limit:, min:, max:, **query_params) yield if block_given? end From 2bb37e4267f5d15a9d86efd820b72f0a3de1dc10 Mon Sep 17 00:00:00 2001 From: Eli <9064062+snood1205@users.noreply.github.com> Date: Mon, 21 Apr 2025 15:28:43 -0400 Subject: [PATCH 3/4] Add method to identity --- lib/arroba/com/atproto/identity.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/arroba/com/atproto/identity.rb b/lib/arroba/com/atproto/identity.rb index 0d54dd8..998e76e 100644 --- a/lib/arroba/com/atproto/identity.rb +++ b/lib/arroba/com/atproto/identity.rb @@ -5,6 +5,7 @@ class Com class ATProto class Identity < BaseResource basic_get :get_recommended_did_credentials + basic_post :refresh_identity, :identifier end end end From 399ed0feea74b1913d0eb1ab9308aae0d3e8532f Mon Sep 17 00:00:00 2001 From: Eli <9064062+snood1205@users.noreply.github.com> Date: Thu, 24 Apr 2025 13:08:37 -0400 Subject: [PATCH 4/4] More endpoints --- lib/arroba/com/atproto.rb | 2 ++ lib/arroba/com/atproto/identity.rb | 8 ++++++++ lib/arroba/com/atproto/label.rb | 2 ++ lib/arroba/com/atproto/moderation.rb | 1 + 4 files changed, 13 insertions(+) diff --git a/lib/arroba/com/atproto.rb b/lib/arroba/com/atproto.rb index f227cf8..fea567c 100644 --- a/lib/arroba/com/atproto.rb +++ b/lib/arroba/com/atproto.rb @@ -17,6 +17,8 @@ def initialize(client) def admin = @admin ||= Admin.new(@client) def identity = @identity ||= Identity.new(@client) + def label = @label ||= Label.new(@client) + def moderation = @moderation ||= Moderation.new(@client) end end end diff --git a/lib/arroba/com/atproto/identity.rb b/lib/arroba/com/atproto/identity.rb index 998e76e..cba6e15 100644 --- a/lib/arroba/com/atproto/identity.rb +++ b/lib/arroba/com/atproto/identity.rb @@ -6,6 +6,14 @@ class ATProto class Identity < BaseResource basic_get :get_recommended_did_credentials basic_post :refresh_identity, :identifier + basic_post :request_plc_operation_signature + basic_get :resolve_did, :did + basic_get :resolve_handle, :handle + basic_get :resolve_identity, :identifier + basic_post :sign_plc_operation, token: nil, rotation_keys: nil, also_known_as: nil, verification_methods: nil, + services: nil + basic_post :submit_plc_operation, :operation + basic_post :update_handle, :handle end end end diff --git a/lib/arroba/com/atproto/label.rb b/lib/arroba/com/atproto/label.rb index 5c711e2..8c74275 100644 --- a/lib/arroba/com/atproto/label.rb +++ b/lib/arroba/com/atproto/label.rb @@ -4,6 +4,8 @@ module Arroba class Com class ATProto class Label < BaseResource + include Validations::Limitable + get_with_enforced_limit :query_labels, :uri_patterns, sources: nil, max: 250 end end end diff --git a/lib/arroba/com/atproto/moderation.rb b/lib/arroba/com/atproto/moderation.rb index 7be5d28..215c4e4 100644 --- a/lib/arroba/com/atproto/moderation.rb +++ b/lib/arroba/com/atproto/moderation.rb @@ -4,6 +4,7 @@ module Arroba class Com class ATProto class Moderation < BaseResource + basic_post :create_report, :reason_type, :subject, reason: nil end end end