Class: Noticed::BulkDeliveryMethods::Bluesky

Inherits:
Noticed::BulkDeliveryMethod show all
Defined in:
lib/noticed/bulk_delivery_methods/bluesky.rb

Instance Attribute Summary

Attributes inherited from Noticed::BulkDeliveryMethod

#config, #event

Instance Method Summary collapse

Methods inherited from Noticed::BulkDeliveryMethod

#evaluate_option, #fetch_constant, #perform

Methods included from ApiClient

#post_request

Instance Method Details

#deliverObject

bulk_deliver_by :bluesky do |config|

config.identifier = ENV["BLUESKY_ID"]
config.password = ENV["BLUESKY_PASSWORD"]
config.json = {text: "...", createdAt: "..."}

end



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/noticed/bulk_delivery_methods/bluesky.rb', line 12

def deliver
  Rails.logger.debug(evaluate_option(:json))
  post_request(
    "https://#{host}/xrpc/com.atproto.repo.createRecord",
    headers: {"Authorization" => "Bearer #{token}"},
    json: {
      repo: identifier,
      collection: "app.bsky.feed.post",
      record: evaluate_option(:json)
    }
  )
end

#hostObject



40
41
42
# File 'lib/noticed/bulk_delivery_methods/bluesky.rb', line 40

def host
  @host ||= evaluate_option(:host) || "bsky.social"
end

#identifierObject



44
45
46
# File 'lib/noticed/bulk_delivery_methods/bluesky.rb', line 44

def identifier
  @identifier ||= evaluate_option(:identifier)
end

#start_sessionObject



29
30
31
32
33
34
35
36
37
38
# File 'lib/noticed/bulk_delivery_methods/bluesky.rb', line 29

def start_session
  response = post_request(
    "https://#{host}/xrpc/com.atproto.server.createSession",
    json: {
      identifier: identifier,
      password: evaluate_option(:password)
    }
  )
  JSON.parse(response.body)
end

#tokenObject



25
26
27
# File 'lib/noticed/bulk_delivery_methods/bluesky.rb', line 25

def token
  start_session.dig("accessJwt")
end