Class: StandupMD::Post::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/standup_md/post/result.rb

Overview

Result returned by posting adapters.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(success:, adapter:, channel:, response: {}, error: nil) ⇒ Result

Builds a posting result.

Parameters:

  • success (Boolean)
  • adapter (String, Symbol)
  • channel (String, nil)
  • response (Hash) (defaults to: {})
  • error (String, nil) (defaults to: nil)


40
41
42
43
44
45
46
# File 'lib/standup_md/post/result.rb', line 40

def initialize(success:, adapter:, channel:, response: {}, error: nil)
  @success = success
  @adapter = adapter.to_sym
  @channel = channel
  @response = response
  @error = error
end

Instance Attribute Details

#adapterSymbol (readonly)

The adapter that handled the post.

Returns:

  • (Symbol)


12
13
14
# File 'lib/standup_md/post/result.rb', line 12

def adapter
  @adapter
end

#channelString? (readonly)

The destination channel, room, or conversation identifier.

Returns:

  • (String, nil)


18
19
20
# File 'lib/standup_md/post/result.rb', line 18

def channel
  @channel
end

#errorString? (readonly)

Human-readable error message for failed posts.

Returns:

  • (String, nil)


30
31
32
# File 'lib/standup_md/post/result.rb', line 30

def error
  @error
end

#responseHash (readonly)

Adapter-specific response metadata.

Returns:

  • (Hash)


24
25
26
# File 'lib/standup_md/post/result.rb', line 24

def response
  @response
end

Class Method Details

.failure(adapter:, channel:, error:, response: {}) ⇒ StandupMD::Post::Result

Builds a failed result.



60
61
62
63
64
65
66
67
68
# File 'lib/standup_md/post/result.rb', line 60

def self.failure(adapter:, channel:, error:, response: {})
  new(
    success: false,
    adapter: adapter,
    channel: channel,
    response: response,
    error: error
  )
end

.success(adapter:, channel:, response: {}) ⇒ StandupMD::Post::Result

Builds a successful result.



52
53
54
# File 'lib/standup_md/post/result.rb', line 52

def self.success(adapter:, channel:, response: {})
  new(success: true, adapter: adapter, channel: channel, response: response)
end

Instance Method Details

#failure?Boolean

Did the post fail?

Returns:

  • (Boolean)


82
83
84
# File 'lib/standup_md/post/result.rb', line 82

def failure?
  !success?
end

#success?Boolean

Was the post successful?

Returns:

  • (Boolean)


74
75
76
# File 'lib/standup_md/post/result.rb', line 74

def success?
  @success
end