Class: DistributedPress::V1::Social::Inbox
- Inherits:
-
Object
- Object
- DistributedPress::V1::Social::Inbox
- Defined in:
- lib/distributed_press/v1/social/inbox.rb
Overview
Manages the actor’s inbox on the Social Inbox
Instance Attribute Summary collapse
- #actor ⇒ String readonly
- #client ⇒ DistributedPress::V1::Social::Client readonly
Instance Method Summary collapse
-
#accept(id:) ⇒ HTTParty::Response
Accept an activity queued on the inbox.
-
#create(actor_url, announce: false, manually_approves_followers: false) ⇒ HTTParty::Response
Creates a Social Inbox by uploading the keypair to it.
-
#endpoint ⇒ String
Inbox.
-
#get ⇒ HTTParty::Response
Get the actor’s inbox.
-
#initialize(client:, actor:) ⇒ Inbox
constructor
A new instance of Inbox.
-
#post(activity:) ⇒ HTTParty::Response
Send an activity to the actor’s inbox.
-
#reject(id:) ⇒ HTTParty::Response
Reject an activity queued on the inbox.
Constructor Details
#initialize(client:, actor:) ⇒ Inbox
Returns a new instance of Inbox.
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
#actor ⇒ String (readonly)
15 16 17 |
# File 'lib/distributed_press/v1/social/inbox.rb', line 15 def actor @actor end |
#client ⇒ DistributedPress::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
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.
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 |
#endpoint ⇒ String
Inbox
81 82 83 |
# File 'lib/distributed_press/v1/social/inbox.rb', line 81 def endpoint @endpoint ||= "/v1/#{actor}/inbox" end |
#get ⇒ HTTParty::Response
Get the actor’s inbox
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.
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
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 |