slack_msgr 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile.lock +1 -1
- data/lib/config/constants.rb +1 -1
- data/lib/config/initializer.rb +2 -0
- data/lib/slack_msgr.rb +5 -0
- data/lib/slack_msgr/configuration.rb +4 -0
- data/lib/slack_msgr/slack_method.rb +15 -4
- data/lib/slack_msgr/users.rb +67 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ba93be303c5728b994007644a45678eec7bec9aeefd338d97e09e7d68382a7f2
|
4
|
+
data.tar.gz: 0a40e7e180a44821106e2450e403afbc606361c46861a2a74663005b37984cc6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ac47b139f27763a56f9266f37af7e9e7ec67fdb5e958faddf5b4aeedc746e77abf49ca251bf4667aba765afd49e6c6ed12c26cd4840e7563ee4987aa2e84428
|
7
|
+
data.tar.gz: 914e94e373131ec0c5152eb602e73be370aa53c5019bc71c20bf0f313f31ec9ff636749f32aae0941440ee70b900fba7da7590ac3ef7032bd4b0c0f862f6b3b6
|
data/Gemfile.lock
CHANGED
data/lib/config/constants.rb
CHANGED
data/lib/config/initializer.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'json'
|
4
4
|
require 'faraday'
|
5
|
+
require 'uri'
|
5
6
|
require_relative './constants'
|
6
7
|
|
7
8
|
path = __dir__
|
@@ -9,4 +10,5 @@ path = __dir__
|
|
9
10
|
require "#{path}/../slack_msgr/slack_method"
|
10
11
|
require "#{path}/../slack_msgr/chat"
|
11
12
|
require "#{path}/../slack_msgr/configuration"
|
13
|
+
require "#{path}/../slack_msgr/users"
|
12
14
|
require "#{path}/../utils/error_handling"
|
data/lib/slack_msgr.rb
CHANGED
@@ -6,6 +6,7 @@ module SlackMsgr
|
|
6
6
|
attr_accessor :verification_token,
|
7
7
|
:client_secret,
|
8
8
|
:signing_secret,
|
9
|
+
:legacy_token,
|
9
10
|
:access_tokens,
|
10
11
|
:set_default_token
|
11
12
|
|
@@ -13,12 +14,14 @@ module SlackMsgr
|
|
13
14
|
verification_token: nil,
|
14
15
|
client_secret: nil,
|
15
16
|
signing_secret: nil,
|
17
|
+
legacy_token: nil,
|
16
18
|
access_tokens: {},
|
17
19
|
set_default_token: nil
|
18
20
|
)
|
19
21
|
@verification_token = verification_token
|
20
22
|
@client_secret = client_secret
|
21
23
|
@signing_secret = signing_secret
|
24
|
+
@legacy_token = legacy_token
|
22
25
|
@access_tokens = access_tokens
|
23
26
|
@set_default_token = set_default_token
|
24
27
|
end
|
@@ -27,6 +30,7 @@ module SlackMsgr
|
|
27
30
|
@verification_token = nil
|
28
31
|
@client_secret = nil
|
29
32
|
@signing_secret = nil
|
33
|
+
@legacy_token = nil
|
30
34
|
@access_tokens = {}
|
31
35
|
@set_default_token = nil
|
32
36
|
@default_token = nil
|
@@ -8,12 +8,11 @@ module SlackMsgr
|
|
8
8
|
|
9
9
|
attr_reader :conn
|
10
10
|
|
11
|
-
def establish_connection
|
11
|
+
def establish_connection
|
12
12
|
@conn ||= Faraday.new(url: SLACK_URL) do |config|
|
13
13
|
config.request :url_encoded # form-encode POST params
|
14
14
|
config.adapter Faraday.default_adapter # make requests with Net::HTTP
|
15
15
|
end
|
16
|
-
conn.authorization :Bearer, SlackMsgr.configuration.oauth_access_token(given_token)
|
17
16
|
end
|
18
17
|
|
19
18
|
def conceal(token)
|
@@ -25,8 +24,9 @@ module SlackMsgr
|
|
25
24
|
.merge!(auth_token: conceal(conn.headers['Authorization']))
|
26
25
|
end
|
27
26
|
|
28
|
-
def send_post_request_to_slack(obj)
|
29
|
-
establish_connection
|
27
|
+
def send_post_request_to_slack(obj, **request_opts)
|
28
|
+
establish_connection
|
29
|
+
conn.authorization :Bearer, SlackMsgr.configuration.oauth_access_token(obj.opts[:use_token])
|
30
30
|
response = conn.post do |req|
|
31
31
|
req.url "/api/#{obj.method}"
|
32
32
|
req.headers['Content-Type'] = 'application/json; charset=utf-8'
|
@@ -34,6 +34,17 @@ module SlackMsgr
|
|
34
34
|
end
|
35
35
|
add_metadata_to_response(response)
|
36
36
|
end
|
37
|
+
|
38
|
+
def send_legacy_request_to_slack(obj)
|
39
|
+
establish_connection
|
40
|
+
conn.authorization :Bearer, SlackMsgr.configuration.legacy_token
|
41
|
+
response = conn.post do |req|
|
42
|
+
req.url "/api/#{obj.method}"
|
43
|
+
req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
|
44
|
+
req.body = URI.encode_www_form(obj.body)
|
45
|
+
end
|
46
|
+
JSON.parse(response.body, symbolize_names: true)
|
47
|
+
end
|
37
48
|
end
|
38
49
|
end
|
39
50
|
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SlackMsgr
|
4
|
+
# Handles all users functionality and methods corresponding with Slack API
|
5
|
+
class Users < SlackMethod
|
6
|
+
USERS_METHODS = {
|
7
|
+
admin: 'admin',
|
8
|
+
invite: 'invite'
|
9
|
+
}.freeze
|
10
|
+
|
11
|
+
REQUIRED_ARGUMENTS = %i[email].freeze
|
12
|
+
|
13
|
+
PERMITTED_ARGUMENTS = %i[
|
14
|
+
token
|
15
|
+
email
|
16
|
+
channels
|
17
|
+
real_name
|
18
|
+
resend
|
19
|
+
restricted
|
20
|
+
ultra_restricted
|
21
|
+
expiration_ts
|
22
|
+
].freeze
|
23
|
+
|
24
|
+
class << self
|
25
|
+
def call(method, opts = {})
|
26
|
+
users = new(method, opts)
|
27
|
+
send_legacy_request_to_slack(users)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
attr_reader :method,
|
32
|
+
:opts,
|
33
|
+
:body
|
34
|
+
|
35
|
+
def initialize(methods, opts)
|
36
|
+
users_method = methods.map do |method|
|
37
|
+
ErrorHandling.raise(:unknown_method, method: method) unless USERS_METHODS[method]
|
38
|
+
|
39
|
+
USERS_METHODS[method]
|
40
|
+
end.join(".")
|
41
|
+
|
42
|
+
@method = "users.#{users_method}"
|
43
|
+
@opts = opts
|
44
|
+
@body = sanitize_body
|
45
|
+
puts body
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def sanitize_body
|
51
|
+
ErrorHandling.raise(:req_args_missing, req_args: REQUIRED_ARGUMENTS, method: method) if req_args_missing? # rubocop:disable LineLength
|
52
|
+
puts opts.merge(token)
|
53
|
+
opts.merge!(token).keys.each_with_object({}) do |key, body|
|
54
|
+
body[key] ||= opts[key] if PERMITTED_ARGUMENTS.include?(key)
|
55
|
+
body
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def req_args_missing?
|
60
|
+
!(REQUIRED_ARGUMENTS - opts.keys).empty?
|
61
|
+
end
|
62
|
+
|
63
|
+
def token
|
64
|
+
{token: SlackMsgr.configuration.legacy_token}
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slack_msgr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Workman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -148,6 +148,7 @@ files:
|
|
148
148
|
- lib/slack_msgr/chat.rb
|
149
149
|
- lib/slack_msgr/configuration.rb
|
150
150
|
- lib/slack_msgr/slack_method.rb
|
151
|
+
- lib/slack_msgr/users.rb
|
151
152
|
- lib/utils/error_handling.rb
|
152
153
|
- slack_msgr.gemspec
|
153
154
|
homepage: https://github.com/rdavid1099/slack-msgr
|
@@ -171,8 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
171
172
|
- !ruby/object:Gem::Version
|
172
173
|
version: '0'
|
173
174
|
requirements: []
|
174
|
-
|
175
|
-
rubygems_version: 2.6.14
|
175
|
+
rubygems_version: 3.0.3
|
176
176
|
signing_key:
|
177
177
|
specification_version: 4
|
178
178
|
summary: A Ruby gem to send and receive messages through Slack
|