Class: SlackBot::ApiResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/slack_bot/api_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ ApiResponse

Returns a new instance of ApiResponse.



6
7
8
9
# File 'lib/slack_bot/api_client.rb', line 6

def initialize(&block)
  @response = block.call
  SlackBot::DevConsole.log_output "#{self.class.name}: #{response.body}"
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



5
6
7
# File 'lib/slack_bot/api_client.rb', line 5

def response
  @response
end

Instance Method Details

#dataObject



19
20
21
# File 'lib/slack_bot/api_client.rb', line 19

def data
  JSON.parse(response.body)
end

#errorObject



15
16
17
# File 'lib/slack_bot/api_client.rb', line 15

def error
  data["error"]
end

#ok?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/slack_bot/api_client.rb', line 11

def ok?
  response.status == 200 && data["ok"]
end