Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions lib/arroba/app/bsky/actor.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require_relative '../../validations'

module Arroba
class App
class BSky
Expand Down
2 changes: 0 additions & 2 deletions lib/arroba/app/bsky/feed.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require_relative '../../validations'

module Arroba
class App
class BSky
Expand Down
2 changes: 0 additions & 2 deletions lib/arroba/app/bsky/graph.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require_relative '../../validations'

module Arroba
class App
class BSky
Expand Down
2 changes: 2 additions & 0 deletions lib/arroba/base_resource.rb
Original file line number Diff line number Diff line change
@@ -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.
#
Expand Down
2 changes: 0 additions & 2 deletions lib/arroba/chat/bsky/convo.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require_relative '../../validations'

module Arroba
class Chat
class BSky
Expand Down
17 changes: 16 additions & 1 deletion lib/arroba/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
13 changes: 13 additions & 0 deletions lib/arroba/com.rb
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions lib/arroba/com/atproto.rb
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions lib/arroba/com/atproto/admin.rb
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions lib/arroba/com/atproto/identity.rb
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions lib/arroba/com/atproto/label.rb
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions lib/arroba/com/atproto/moderation.rb
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions lib/arroba/com/atproto/repo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

module Arroba
class Com
class ATProto
class Repo < BaseResource
end
end
end
end
10 changes: 10 additions & 0 deletions lib/arroba/com/atproto/server.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

module Arroba
class Com
class ATProto
class Server < BaseResource
end
end
end
end
10 changes: 10 additions & 0 deletions lib/arroba/com/atproto/sync.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

module Arroba
class Com
class ATProto
class Sync < BaseResource
end
end
end
end
6 changes: 6 additions & 0 deletions lib/arroba/http_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions lib/arroba/validations/limitable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
Expand Down