Class: DistributedPress::V1::Social::Inbox

Inherits:
Object
  • Object
show all
Defined in:
lib/distributed_press/v1/social/inbox.rb

Overview

Manages the actor’s inbox on the Social Inbox

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:, actor:) ⇒ Inbox

Returns a new instance of Inbox.

Parameters:



19
20
21
22
# File 'lib/distributed_press/v1/social/inbox.rb', line 19

def initialize(client:, actor:)
  @client = client
  @actor = actor
end

Instance Attribute Details

#actorString (readonly)

Returns:

  • (String)


15
16
17
# File 'lib/distributed_press/v1/social/inbox.rb', line 15

def actor
  @actor
end

#clientDistributedPress::V1::Social::Client (readonly)



12
13
14
# File 'lib/distributed_press/v1/social/inbox.rb', line 12

def client
  @client
end

Instance Method Details

#accept(id:) ⇒ HTTParty::Response

Accept an activity queued on the inbox

Parameters:

  • :id (String)

    Activity ID

Returns:

  • (HTTParty::Response)


74
75
76
# File 'lib/distributed_press/v1/social/inbox.rb', line 74

def accept(id:)
  client.post(endpoint: "#{endpoint}/#{Base64.encode64(id).delete("\n")}", body: {})
end

#create(actor_url, announce: false, manually_approves_followers: false) ⇒ HTTParty::Response

Creates a Social Inbox by uploading the keypair to it.

Parameters:

  • actor_url (String)

    The URL where the Actor profile is hosted

  • announce (Boolean) (defaults to: false)

    Automatically announce new accounts

  • manually_approves_followers (Boolean) (defaults to: false)

    Automatically accept follow requests

Returns:

  • (HTTParty::Response)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/distributed_press/v1/social/inbox.rb', line 30

def create(actor_url, announce: false, manually_approves_followers: false)
  inbox_body = {
    'actorUrl' => actor_url,
    'publicKeyId' => "#{actor_url}#main-key",
    'announce' => announce,
    'manuallyApprovesFollowers' => manually_approves_followers,
    'keypair' => {
      'publicKeyPem' => client.public_key.public_to_pem,
      'privateKeyPem' => client.private_key.export
    }
  }

  client.post(endpoint: "/v1/#{actor}", body: inbox_body)
end

#endpointString

Inbox

Returns:

  • (String)


81
82
83
# File 'lib/distributed_press/v1/social/inbox.rb', line 81

def endpoint
  @endpoint ||= "/v1/#{actor}/inbox"
end

#getHTTParty::Response

Get the actor’s inbox

Returns:

  • (HTTParty::Response)


48
49
50
# File 'lib/distributed_press/v1/social/inbox.rb', line 48

def get
  client.get(endpoint: endpoint)
end

#post(activity:) ⇒ HTTParty::Response

Send an activity to the actor’s inbox. This is typically done by other actors though, not ourselves, so it could be used to send directly to another Actor’s Social Inbox.

Parameters:

  • :activity (Hash)

Returns:

  • (HTTParty::Response)


58
59
60
# File 'lib/distributed_press/v1/social/inbox.rb', line 58

def post(activity:)
  client.post(endpoint: endpoint, body: activity)
end

#reject(id:) ⇒ HTTParty::Response

Reject an activity queued on the inbox

Parameters:

  • :id (String)

    Activity ID

Returns:

  • (HTTParty::Response)


66
67
68
# File 'lib/distributed_press/v1/social/inbox.rb', line 66

def reject(id:)
  client.delete(endpoint: "#{endpoint}/#{Base64.encode64(id).delete("\n")}")
end