Class: SlackMessage::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/slack_message/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_response, profile_handle) ⇒ Response

Returns a new instance of Response.



4
5
6
7
8
9
10
11
12
13
# File 'lib/slack_message/response.rb', line 4

def initialize(api_response, profile_handle)
  @original_response = JSON.parse(api_response.body)
  @ok = @original_response["ok"]
  @channel = @original_response["channel"]

  @timestamp = @original_response["ts"]
  @scheduled_message_id = @original_response["scheduled_message_id"]

  @profile_handle = profile_handle
end

Instance Attribute Details

#channelObject (readonly)

Returns the value of attribute channel.



2
3
4
# File 'lib/slack_message/response.rb', line 2

def channel
  @channel
end

#original_responseObject (readonly)

Returns the value of attribute original_response.



2
3
4
# File 'lib/slack_message/response.rb', line 2

def original_response
  @original_response
end

#profile_handleObject (readonly)

Returns the value of attribute profile_handle.



2
3
4
# File 'lib/slack_message/response.rb', line 2

def profile_handle
  @profile_handle
end

#scheduled_message_idObject (readonly)

Returns the value of attribute scheduled_message_id.



2
3
4
# File 'lib/slack_message/response.rb', line 2

def scheduled_message_id
  @scheduled_message_id
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



2
3
4
# File 'lib/slack_message/response.rb', line 2

def timestamp
  @timestamp
end

Instance Method Details

#inspectObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/slack_message/response.rb', line 31

def inspect
  identifier = if scheduled?
    "scheduled_message_id=#{scheduled_message_id}"
  else
    "timestamp=#{timestamp}"
  end

  ok_msg = @ok ? "ok" : "error"

  "<SlackMessage::Response #{ok_msg} profile_handle=:#{profile_handle} channel=#{channel} #{identifier}>"
end

#marshal_dumpObject



15
16
17
# File 'lib/slack_message/response.rb', line 15

def marshal_dump
  [ @profile_handle, @channel, @timestamp, @original_response, @ok, @original_response ]
end

#marshal_load(data) ⇒ Object



19
20
21
# File 'lib/slack_message/response.rb', line 19

def marshal_load(data)
  @profile_handle, @channel, @timestamp, @original_response, @ok, @original_response = data
end

#scheduled?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/slack_message/response.rb', line 27

def scheduled?
  !!scheduled_message_id
end

#sent_to_user?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/slack_message/response.rb', line 23

def sent_to_user?
  channel =~ /^D.*/ # users are D for DM, channels start w/ C
end