slack-api-wrapper 0.0.6 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +2 -0
- data/.coveralls.yml +1 -0
- data/{spec/slack/oauth2/flow_base_spec.rb → .simplecov} +0 -0
- data/.travis.yml +18 -1
- data/.yardopts +9 -0
- data/CHANGELOG.md +10 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/{LICENSE.txt → MIT-LICENSE} +0 -0
- data/README.md +50 -11
- data/Rakefile +3 -4
- data/lib/slack-api-wrapper.rb +15 -92
- data/lib/slack/client.rb +5 -6
- data/lib/slack/error.rb +1 -9
- data/lib/slack/request.rb +56 -0
- data/lib/slack/session.rb +20 -55
- data/lib/slack/version.rb +1 -1
- data/lib/slack/web/api.rb +4 -5
- data/lib/slack/web/auth.rb +4 -4
- data/lib/slack/web/channels.rb +60 -61
- data/lib/slack/web/chat.rb +17 -18
- data/lib/slack/web/emoji.rb +4 -4
- data/lib/slack/web/files.rb +16 -16
- data/lib/slack/web/groups.rb +81 -68
- data/lib/slack/web/im.rb +21 -22
- data/lib/slack/web/pins.rb +65 -0
- data/lib/slack/web/reactions.rb +97 -0
- data/lib/slack/web/search.rb +17 -18
- data/lib/slack/web/stars.rb +4 -5
- data/lib/slack/web/team.rb +12 -4
- data/lib/slack/web/users.rb +22 -23
- data/slack-api-wrapper.gemspec +13 -11
- data/spec/slack/client_spec.rb +2 -3
- data/spec/slack/session_spec.rb +21 -0
- data/spec/slack_spec.rb +0 -19
- data/spec/spec_helper.rb +81 -1
- metadata +52 -16
- data/lib/slack/oauth2.rb +0 -10
- data/lib/slack/oauth2/flow.rb +0 -165
- data/lib/slack/oauth2/flow_base.rb +0 -81
- data/spec/slack/oauth2/flow_spec.rb +0 -0
- data/spec/slack/oauth2_spec.rb +0 -7
@@ -1,81 +0,0 @@
|
|
1
|
-
# Copyright (c) 2015 Gustavo Bazan
|
2
|
-
# MIT License
|
3
|
-
|
4
|
-
require 'uri'
|
5
|
-
|
6
|
-
module Slack
|
7
|
-
module Oauth2
|
8
|
-
# Base class for the OAuth 2 authorization helpers.
|
9
|
-
class FlowBase
|
10
|
-
def initialize(consumer_key, consumer_secret, scope, team)
|
11
|
-
unless consumer_key.is_a?(String)
|
12
|
-
raise ArgumentError, "consumer_key must be a String, got #{consumer_key.inspect}"
|
13
|
-
end
|
14
|
-
unless consumer_secret.is_a?(String)
|
15
|
-
raise ArgumentError, "consumer_secret must be a String, got #{consumer_secret.inspect}"
|
16
|
-
end
|
17
|
-
unless scope.is_a?(String)
|
18
|
-
raise ArgumentError, "scope must be a String, got #{scope.inspect}"
|
19
|
-
end
|
20
|
-
|
21
|
-
@consumer_key = consumer_key
|
22
|
-
@consumer_secret = consumer_secret
|
23
|
-
@scope = scope
|
24
|
-
@team = team
|
25
|
-
end
|
26
|
-
|
27
|
-
protected
|
28
|
-
|
29
|
-
def _get_authorize_url(redirect_uri, state)
|
30
|
-
params = {
|
31
|
-
"client_id" => @consumer_key,
|
32
|
-
"redirect_uri" => redirect_uri,
|
33
|
-
"scope" => @scope,
|
34
|
-
"state" => state,
|
35
|
-
"team" => @team
|
36
|
-
}
|
37
|
-
|
38
|
-
host = Slack::WEB_SERVER
|
39
|
-
path = "/oauth/authorize"
|
40
|
-
|
41
|
-
target = URI::Generic.new("https", nil, host, nil, nil, path, nil, nil, nil)
|
42
|
-
target.query = Slack::make_query_string(params)
|
43
|
-
|
44
|
-
target.to_s
|
45
|
-
end
|
46
|
-
|
47
|
-
# Finish the OAuth 2 authorization process. If you used a redirect_uri, pass that in.
|
48
|
-
# Will return an access token string that you can use with SlackClient.
|
49
|
-
def _finish(code, original_redirect_uri)
|
50
|
-
|
51
|
-
raise ArgumentError, "code must be a String" unless code.is_a?(String)
|
52
|
-
|
53
|
-
uri = URI.parse("https://#{Slack::API_SERVER}/oauth.access")
|
54
|
-
request = Net::HTTP::Post.new(uri.request_uri)
|
55
|
-
|
56
|
-
params = {
|
57
|
-
"client_id" => @consumer_key,
|
58
|
-
"client_secret" => @consumer_secret,
|
59
|
-
"code" => code,
|
60
|
-
"redirect_uri" => original_redirect_uri
|
61
|
-
}
|
62
|
-
|
63
|
-
request.set_form_data(Slack::clean_params(params))
|
64
|
-
|
65
|
-
response = Slack::do_http(uri, request)
|
66
|
-
|
67
|
-
j = Slack::parse_response(response)
|
68
|
-
["access_token", "scope"].each do |k|
|
69
|
-
unless j.has_key?(k)
|
70
|
-
raise Slack::Error.new("Bad response from /token: missing \"#{k}\".")
|
71
|
-
end
|
72
|
-
unless j[k].is_a?(String)
|
73
|
-
raise Slack::Error.new("Bad response from /token: field \"#{k}\" is not a string.")
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
return j['access_token'], j['scope']
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
File without changes
|