Class: DistributedPress::V1::Social::Blocklist

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

Overview

Manages Social Inbox blocklist

Examples:

DistributedPress::V1::Social::Blocklist.new(client: client)
DistributedPress::V1::Social::Blocklist.new(client: client, actor: '@[email protected]')

Direct Known Subclasses

Allowlist

Constant Summary collapse

ACCEPT =
%w[text/plain].freeze
CONTENT_TYPE =
'text/plain'
ENDPOINT =
'/blocklist'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:, actor: nil) ⇒ Blocklist

Returns a new instance of Blocklist.

Parameters:



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/distributed_press/v1/social/blocklist.rb', line 26

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

  @serializer = proc do |body|
    body.join("\n")
  end

  # @param :body [String,nil]
  # @return [Array<String>]
  @parser =
    proc do |body, _|
      next [] if body.nil?

      body.split("\n").map(&:strip).reject(&:empty?)
    end
end

Instance Attribute Details

#actorString? (readonly)

Returns:

  • (String, nil)


22
23
24
# File 'lib/distributed_press/v1/social/blocklist.rb', line 22

def actor
  @actor
end

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



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

def client
  @client
end

Instance Method Details

#delete(list:) ⇒ HTTParty::Response

Removes instances and accounts from the blocklist

Parameters:

  • :list (Array<String>)

Returns:

  • (HTTParty::Response)


64
65
66
67
# File 'lib/distributed_press/v1/social/blocklist.rb', line 64

def delete(list:)
  client.delete(endpoint: endpoint, body: list, serializer: @serializer, parser: @parser,
                content_type: CONTENT_TYPE, accept: ACCEPT)
end

#endpointObject



69
70
71
# File 'lib/distributed_press/v1/social/blocklist.rb', line 69

def endpoint
  @endpoint ||= "/v1/#{actor}#{self.class::ENDPOINT}".squeeze('/')
end

#getArray<String>

Obtains the current blocklist

Returns:

  • (Array<String>)


47
48
49
# File 'lib/distributed_press/v1/social/blocklist.rb', line 47

def get
  client.get(endpoint: endpoint, parser: @parser, content_type: CONTENT_TYPE, accept: ACCEPT)
end

#post(list:) ⇒ HTTParty::Response

Sends an array of instances and accounts to be blocked

Parameters:

  • :list (Array<String>)

Returns:

  • (HTTParty::Response)


55
56
57
58
# File 'lib/distributed_press/v1/social/blocklist.rb', line 55

def post(list:)
  client.post(endpoint: endpoint, body: list, serializer: @serializer, parser: @parser,
              content_type: CONTENT_TYPE, accept: ACCEPT)
end