Class: SlackPomodoroTimer::HTTP

Inherits:
Object
  • Object
show all
Defined in:
lib/slack_pomodoro_timer/http.rb

Constant Summary collapse

REGEXES =
{
  :slackbot => /\.slack.com\/services\/hooks\/slackbot/,
  :webhook => /hooks\.slack\.com\/services/
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ HTTP

Accepts options for url and data



21
22
23
24
25
# File 'lib/slack_pomodoro_timer/http.rb', line 21

def initialize(options={})
  @url = options[:url]
  @data = options[:data]
  set_integration_type
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



13
14
15
# File 'lib/slack_pomodoro_timer/http.rb', line 13

def data
  @data
end

#integration_typeObject (readonly)

Returns the value of attribute integration_type.



17
18
19
# File 'lib/slack_pomodoro_timer/http.rb', line 17

def integration_type
  @integration_type
end

#responseObject

Returns the value of attribute response.



13
14
15
# File 'lib/slack_pomodoro_timer/http.rb', line 13

def response
  @response
end

#urlObject

Returns the value of attribute url.



13
14
15
# File 'lib/slack_pomodoro_timer/http.rb', line 13

def url
  @url
end

Class Method Details

.valid_url?(url) ⇒ Boolean

Validates that the URL fits the expected Slackbot or Webhook URL format

Returns:

  • (Boolean)


116
117
118
# File 'lib/slack_pomodoro_timer/http.rb', line 116

def self.valid_url?(url)
  REGEXES.any? { |key, regex| regex.match(url) }
end

Instance Method Details

#postObject

Posts the data to the given URL



40
41
42
43
44
# File 'lib/slack_pomodoro_timer/http.rb', line 40

def post
  data = serialized_data
  url = url_for_integration_type
  @response = Net::HTTP.post_form(URI.parse(url), data)
end