Module: Slack
- Defined in:
- lib/slack/error.rb,
lib/slack/web.rb,
lib/slack/client.rb,
lib/slack/oauth2.rb,
lib/slack/web/im.rb,
lib/slack/session.rb,
lib/slack/version.rb,
lib/slack/web/auth.rb,
lib/slack/web/chat.rb,
lib/slack/web/emoji.rb,
lib/slack/web/files.rb,
lib/slack/web/stars.rb,
lib/slack/web/users.rb,
lib/slack/web/groups.rb,
lib/slack/web/search.rb,
lib/slack-api-wrapper.rb,
lib/slack/oauth2/flow.rb,
lib/slack/web/channels.rb,
lib/slack/oauth2/flow_base.rb
Overview
:nodoc:
Defined Under Namespace
Modules: OAuth2, Oauth2, Web Classes: AuthError, Client, Error, OAuth2Session
Constant Summary collapse
- VERSION =
"0.0.2"- WEB_SERVER =
'slack.com'- API_SERVER =
"#{WEB_SERVER}/api"
Class Method Summary collapse
- .clean_params(params) ⇒ Object
-
.do_http(uri, request) ⇒ Object
:nodoc:.
- .make_query_string(params) ⇒ Object
-
.parse_response(response, raw = false) ⇒ Object
Parse response.
-
.safe_string_equals(a, b) ⇒ Object
A string comparison function that is resistant to timing attacks.
Class Method Details
.clean_params(params) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/slack-api-wrapper.rb', line 16 def self.clean_params(params) r = {} params.each do |k,v| r[k] = v.to_s unless v.nil? end r end |
.do_http(uri, request) ⇒ Object
:nodoc:
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/slack-api-wrapper.rb', line 32 def self.do_http(uri, request) # :nodoc: http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true # Let then know about us request['User-Agent'] = "SlackRubyAPIWrapper" begin http.request(request) rescue OpenSSL::SSL::SSLError => e raise SlackError.new("SSL error connecting to Slack.") end end |
.make_query_string(params) ⇒ Object
25 26 27 28 29 |
# File 'lib/slack-api-wrapper.rb', line 25 def self.make_query_string(params) clean_params(params).collect {|k,v| CGI.escape(k) + "=" + CGI.escape(v) }.join("&") end |
.parse_response(response, raw = false) ⇒ Object
Parse response. You probably shouldn’t be calling this directly. This takes responses from the server and parses them. It also checks for errors and raises exceptions with the appropriate messages.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/slack-api-wrapper.rb', line 50 def self.parse_response(response, raw=false) # :nodoc: if response.kind_of?(Net::HTTPServerError) raise Slack.new("Slack Server Error: #{response} - #{response.body}", response) elsif response.kind_of?(Net::) raise SlackAuthError.new("User is not authenticated.", response) elsif !response.kind_of?(Net::HTTPSuccess) begin d = JSON.parse(response.body) rescue raise SlackError.new("Slack Server Error: body=#{response.body}", response) end if d['error'] raise SlackError.new(d['error'], response) else raise SlackError.new(response.body, response) end end return response.body if raw begin return JSON.parse(response.body) rescue JSON::ParserError raise SlackError.new("Unable to parse JSON response: #{response.body}", response) end end |
.safe_string_equals(a, b) ⇒ Object
A string comparison function that is resistant to timing attacks. If you’re comparing a string you got from the outside world with a string that is supposed to be a secret, use this function to check equality.
80 81 82 83 84 85 86 |
# File 'lib/slack-api-wrapper.rb', line 80 def self.safe_string_equals(a, b) if a.length != b.length false else a.chars.zip(b.chars).map {|ac,bc| ac == bc}.all? end end |