Class: SlackPomodoroTimer::HTTP
- Inherits:
-
Object
- Object
- SlackPomodoroTimer::HTTP
- 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
-
#data ⇒ Object
Returns the value of attribute data.
-
#integration_type ⇒ Object
readonly
Returns the value of attribute integration_type.
-
#response ⇒ Object
Returns the value of attribute response.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
-
.valid_url?(url) ⇒ Boolean
Validates that the URL fits the expected Slackbot or Webhook URL format.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ HTTP
constructor
Accepts options for url and data.
-
#post ⇒ Object
Posts the data to the given URL.
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(={}) @url = [:url] @data = [:data] set_integration_type end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
13 14 15 |
# File 'lib/slack_pomodoro_timer/http.rb', line 13 def data @data end |
#integration_type ⇒ Object (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 |
#response ⇒ Object
Returns the value of attribute response.
13 14 15 |
# File 'lib/slack_pomodoro_timer/http.rb', line 13 def response @response end |
#url ⇒ Object
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
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
#post ⇒ Object
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 |