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.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..fea567c --- /dev/null +++ b/lib/arroba/com/atproto.rb @@ -0,0 +1,24 @@ +# 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) + 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/admin.rb b/lib/arroba/com/atproto/admin.rb new file mode 100644 index 0000000..96556a1 --- /dev/null +++ b/lib/arroba/com/atproto/admin.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +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 +end diff --git a/lib/arroba/com/atproto/identity.rb b/lib/arroba/com/atproto/identity.rb new file mode 100644 index 0000000..cba6e15 --- /dev/null +++ b/lib/arroba/com/atproto/identity.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Arroba + class Com + 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 +end diff --git a/lib/arroba/com/atproto/label.rb b/lib/arroba/com/atproto/label.rb new file mode 100644 index 0000000..8c74275 --- /dev/null +++ b/lib/arroba/com/atproto/label.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +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 +end diff --git a/lib/arroba/com/atproto/moderation.rb b/lib/arroba/com/atproto/moderation.rb new file mode 100644 index 0000000..215c4e4 --- /dev/null +++ b/lib/arroba/com/atproto/moderation.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module Arroba + class Com + class ATProto + class Moderation < BaseResource + basic_post :create_report, :reason_type, :subject, reason: nil + 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 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