slack_msgr 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fd274c89233b9e5903e49f7e4243a859f2e78c74
4
+ data.tar.gz: 7ba179fb4226cf6fafb36f6735c80b10daf28b3c
5
+ SHA512:
6
+ metadata.gz: 1998160597b692ff67d57b2c6c794c6f3b807037c0da3186d6a5c6b4b46eb7caf1c70220dd8d08938b537fbae9078a06f305093a5efb99733ec8ce284fdb86ff
7
+ data.tar.gz: 227e030f4de7db7f7c0ed5134217e6594d1efa5f2b71011dae41010bc2898754cbe76e952426d9b27cf107c5f2566df82707e5796a430fe808927000e4bc9f1b
data/.codeclimate.yml ADDED
@@ -0,0 +1,8 @@
1
+ ---
2
+ version: "2"
3
+ plugins:
4
+ rubocop:
5
+ enabled: true
6
+ channel: rubocop-0-71
7
+ reek:
8
+ enabled: true
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.reek.yml ADDED
@@ -0,0 +1,132 @@
1
+ ---
2
+ detectors:
3
+ Attribute:
4
+ enabled: true
5
+ exclude:
6
+ - Configuration
7
+ BooleanParameter:
8
+ enabled: true
9
+ exclude: []
10
+ ClassVariable:
11
+ enabled: true
12
+ exclude: []
13
+ ControlParameter:
14
+ enabled: true
15
+ exclude: []
16
+ DataClump:
17
+ enabled: true
18
+ exclude: []
19
+ max_copies: 2
20
+ min_clump_size: 2
21
+ DuplicateMethodCall:
22
+ enabled: true
23
+ exclude: []
24
+ max_calls: 1
25
+ allow_calls: []
26
+ FeatureEnvy:
27
+ enabled: true
28
+ exclude: []
29
+ InstanceVariableAssumption:
30
+ enabled: true
31
+ exclude: []
32
+ IrresponsibleModule:
33
+ enabled: true
34
+ exclude: []
35
+ LongParameterList:
36
+ enabled: true
37
+ exclude: []
38
+ max_params: 3
39
+ overrides:
40
+ initialize:
41
+ max_params: 5
42
+ LongYieldList:
43
+ enabled: true
44
+ exclude: []
45
+ max_params: 3
46
+ ManualDispatch:
47
+ enabled: true
48
+ exclude: []
49
+ MissingSafeMethod:
50
+ enabled: false
51
+ exclude:
52
+ - 'Configuration#clear!'
53
+ ModuleInitialize:
54
+ enabled: true
55
+ exclude: []
56
+ NestedIterators:
57
+ enabled: true
58
+ exclude: []
59
+ max_allowed_nesting: 1
60
+ ignore_iterators:
61
+ - tap
62
+ NilCheck:
63
+ enabled: true
64
+ exclude: []
65
+ RepeatedConditional:
66
+ enabled: true
67
+ exclude: []
68
+ max_ifs: 2
69
+ SubclassedFromCoreClass:
70
+ enabled: true
71
+ exclude: []
72
+ TooManyConstants:
73
+ enabled: true
74
+ exclude: []
75
+ max_constants: 5
76
+ TooManyInstanceVariables:
77
+ enabled: false
78
+ exclude: []
79
+ max_instance_variables: 4
80
+ TooManyMethods:
81
+ enabled: true
82
+ exclude: []
83
+ max_methods: 15
84
+ TooManyStatements:
85
+ enabled: true
86
+ exclude:
87
+ - initialize
88
+ - SlackMsgrHelpers
89
+ max_statements: 5
90
+ UncommunicativeMethodName:
91
+ enabled: true
92
+ exclude: []
93
+ reject:
94
+ - "/^[a-z]$/"
95
+ - "/[0-9]$/"
96
+ - "/[A-Z]/"
97
+ accept: []
98
+ UncommunicativeModuleName:
99
+ enabled: true
100
+ exclude: []
101
+ reject:
102
+ - "/^.$/"
103
+ - "/[0-9]$/"
104
+ accept: []
105
+ UncommunicativeParameterName:
106
+ enabled: true
107
+ exclude: []
108
+ reject:
109
+ - "/^.$/"
110
+ - "/[0-9]$/"
111
+ - "/[A-Z]/"
112
+ - "/^_/"
113
+ accept: []
114
+ UncommunicativeVariableName:
115
+ enabled: true
116
+ exclude: []
117
+ reject:
118
+ - "/^.$/"
119
+ - "/[0-9]$/"
120
+ - "/[A-Z]/"
121
+ accept:
122
+ - "/^_$/"
123
+ UnusedParameters:
124
+ enabled: true
125
+ exclude: []
126
+ UnusedPrivateMethod:
127
+ enabled: false
128
+ exclude: []
129
+ UtilityFunction:
130
+ enabled: true
131
+ exclude: []
132
+ public_methods_only: false
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,141 @@
1
+ AllCops:
2
+ # Include common Ruby source files.
3
+ Include:
4
+ - '**/*.rb'
5
+ - '**/*.arb'
6
+ - '**/*.axlsx'
7
+ - '**/*.builder'
8
+ - '**/*.fcgi'
9
+ - '**/*.gemfile'
10
+ - '**/*.god'
11
+ - '**/*.jb'
12
+ - '**/*.jbuilder'
13
+ - '**/*.mspec'
14
+ - '**/*.opal'
15
+ - '**/*.pluginspec'
16
+ - '**/*.podspec'
17
+ - '**/*.rabl'
18
+ - '**/*.rake'
19
+ - '**/*.rbuild'
20
+ - '**/*.rbw'
21
+ - '**/*.rbx'
22
+ - '**/*.ru'
23
+ - '**/*.ruby'
24
+ - '**/*.spec'
25
+ - '**/*.thor'
26
+ - '**/*.watchr'
27
+ - '**/.irbrc'
28
+ - '**/.pryrc'
29
+ - '**/buildfile'
30
+ - '**/Appraisals'
31
+ - '**/Berksfile'
32
+ - '**/Brewfile'
33
+ - '**/Buildfile'
34
+ - '**/Capfile'
35
+ - '**/Cheffile'
36
+ - '**/Dangerfile'
37
+ - '**/Deliverfile'
38
+ - '**/Fastfile'
39
+ - '**/*Fastfile'
40
+ - '**/Guardfile'
41
+ - '**/Jarfile'
42
+ - '**/Mavenfile'
43
+ - '**/Podfile'
44
+ - '**/Puppetfile'
45
+ - '**/Rakefile'
46
+ - '**/Snapfile'
47
+ - '**/Thorfile'
48
+ - '**/Vagabondfile'
49
+ - '**/Vagrantfile'
50
+ Exclude:
51
+ - 'node_modules/**/*'
52
+ - 'vendor/**/*'
53
+ - '.git/**/*'
54
+ - 'Gemfile'
55
+ - 'slack_msgr.gemspec'
56
+ - 'spec/**/*'
57
+ - Rakefile
58
+ - bin/**
59
+
60
+ Metrics/LineLength:
61
+ Description: 'Limit lines to 100 characters.'
62
+ StyleGuide: '#100-character-limits'
63
+ Enabled: true
64
+ Max: 100
65
+ # To make it possible to copy or click on URIs in the code, we allow lines
66
+ # containing a URI to be longer than Max.
67
+ AllowHeredoc: true
68
+ AllowURI: true
69
+ URISchemes:
70
+ - http
71
+ - https
72
+ # The IgnoreCopDirectives option causes the LineLength rule to ignore cop
73
+ # directives like '# rubocop: enable ...' when calculating a line's length.
74
+ IgnoreCopDirectives: false
75
+ # The IgnoredPatterns option is a list of !ruby/regexp and/or string
76
+ # elements. Strings will be converted to Regexp objects. A line that matches
77
+ # any regular expression listed in this option will be ignored by LineLength.
78
+ IgnoredPatterns: []
79
+
80
+ Naming/FileName:
81
+ Description: 'Use snake_case for source file names.'
82
+ StyleGuide: '#snake-case-files'
83
+ Enabled: true
84
+ # Camel case file names listed in `AllCops:Include` and all file names listed
85
+ # in `AllCops:Exclude` are excluded by default. Add extra excludes here.
86
+ Exclude: [slack_msgr.gemspec]
87
+ # When `true`, requires that each source file should define a class or module
88
+ # with a name which matches the file name (converted to ... case).
89
+ # It further expects it to be nested inside modules which match the names
90
+ # of subdirectories in its path.
91
+ ExpectMatchingDefinition: false
92
+ # If non-`nil`, expect all source file names to match the following regex.
93
+ # Only the file name itself is matched, not the entire file path.
94
+ # Use anchors as necessary if you want to match the entire name rather than
95
+ # just a part of it.
96
+ Regex: ~
97
+ # With `IgnoreExecutableScripts` set to `true`, this cop does not
98
+ # report offending filenames for executable scripts (i.e. source
99
+ # files with a shebang in the first line).
100
+ IgnoreExecutableScripts: true
101
+ AllowedAcronyms:
102
+ - CLI
103
+ - DSL
104
+ - ACL
105
+ - API
106
+ - ASCII
107
+ - CPU
108
+ - CSS
109
+ - DNS
110
+ - EOF
111
+ - GUID
112
+ - HTML
113
+ - HTTP
114
+ - HTTPS
115
+ - ID
116
+ - IP
117
+ - JSON
118
+ - LHS
119
+ - QPS
120
+ - RAM
121
+ - RHS
122
+ - RPC
123
+ - SLA
124
+ - SMTP
125
+ - SQL
126
+ - SSH
127
+ - TCP
128
+ - TLS
129
+ - TTL
130
+ - UDP
131
+ - UI
132
+ - UID
133
+ - UUID
134
+ - URI
135
+ - URL
136
+ - UTF8
137
+ - VM
138
+ - XML
139
+ - XMPP
140
+ - XSRF
141
+ - XSS
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at rdavid1099@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in slack_msgr.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,96 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ slack_msgr (0.0.1)
5
+ faraday (~> 0.15.4)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.0)
11
+ axiom-types (0.1.1)
12
+ descendants_tracker (~> 0.0.4)
13
+ ice_nine (~> 0.11.0)
14
+ thread_safe (~> 0.3, >= 0.3.1)
15
+ codeclimate-engine-rb (0.4.1)
16
+ virtus (~> 1.0)
17
+ coderay (1.1.2)
18
+ coercible (1.0.0)
19
+ descendants_tracker (~> 0.0.1)
20
+ descendants_tracker (0.0.4)
21
+ thread_safe (~> 0.3, >= 0.3.1)
22
+ diff-lcs (1.3)
23
+ docile (1.3.1)
24
+ equalizer (0.0.11)
25
+ faraday (0.15.4)
26
+ multipart-post (>= 1.2, < 3)
27
+ ice_nine (0.11.2)
28
+ jaro_winkler (1.5.2)
29
+ json (2.2.0)
30
+ kwalify (0.7.2)
31
+ method_source (0.9.2)
32
+ multipart-post (2.1.1)
33
+ parallel (1.17.0)
34
+ parser (2.6.3.0)
35
+ ast (~> 2.4.0)
36
+ pry (0.12.2)
37
+ coderay (~> 1.1.0)
38
+ method_source (~> 0.9.0)
39
+ psych (3.1.0)
40
+ rainbow (3.0.0)
41
+ rake (10.5.0)
42
+ reek (5.4.0)
43
+ codeclimate-engine-rb (~> 0.4.0)
44
+ kwalify (~> 0.7.0)
45
+ parser (>= 2.5.0.0, < 2.7, != 2.5.1.1)
46
+ psych (~> 3.1.0)
47
+ rainbow (>= 2.0, < 4.0)
48
+ rspec (3.8.0)
49
+ rspec-core (~> 3.8.0)
50
+ rspec-expectations (~> 3.8.0)
51
+ rspec-mocks (~> 3.8.0)
52
+ rspec-core (3.8.0)
53
+ rspec-support (~> 3.8.0)
54
+ rspec-expectations (3.8.3)
55
+ diff-lcs (>= 1.2.0, < 2.0)
56
+ rspec-support (~> 3.8.0)
57
+ rspec-mocks (3.8.0)
58
+ diff-lcs (>= 1.2.0, < 2.0)
59
+ rspec-support (~> 3.8.0)
60
+ rspec-support (3.8.0)
61
+ rubocop (0.71.0)
62
+ jaro_winkler (~> 1.5.1)
63
+ parallel (~> 1.10)
64
+ parser (>= 2.6)
65
+ rainbow (>= 2.2.2, < 4.0)
66
+ ruby-progressbar (~> 1.7)
67
+ unicode-display_width (>= 1.4.0, < 1.7)
68
+ ruby-progressbar (1.10.1)
69
+ simplecov (0.16.1)
70
+ docile (~> 1.1)
71
+ json (>= 1.8, < 3)
72
+ simplecov-html (~> 0.10.0)
73
+ simplecov-html (0.10.2)
74
+ thread_safe (0.3.6)
75
+ unicode-display_width (1.6.0)
76
+ virtus (1.0.5)
77
+ axiom-types (~> 0.1)
78
+ coercible (~> 1.0)
79
+ descendants_tracker (~> 0.0, >= 0.0.3)
80
+ equalizer (~> 0.0, >= 0.0.9)
81
+
82
+ PLATFORMS
83
+ ruby
84
+
85
+ DEPENDENCIES
86
+ bundler (~> 2.0)
87
+ pry
88
+ rake (~> 10.0)
89
+ reek (~> 5.4.0)
90
+ rspec (~> 3.0)
91
+ rubocop (~> 0.71.0)
92
+ simplecov
93
+ slack_msgr!
94
+
95
+ BUNDLED WITH
96
+ 2.0.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Ryan Workman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,77 @@
1
+ # SlackMsgr
2
+
3
+ [![Build Status](https://semaphoreci.com/api/v1/rworkman1099/slack-msgr/branches/master/badge.svg)](https://semaphoreci.com/rworkman1099/slack-msgr)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/b0b292347eea43d4c414/maintainability)](https://codeclimate.com/github/rdavid1099/slack-msgr/maintainability)
5
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/b0b292347eea43d4c414/test_coverage)](https://codeclimate.com/github/rdavid1099/slack-msgr/test_coverage)
6
+
7
+ Under construction 🚧 Release is still in very early development. Limited, basic functionality is available.
8
+
9
+ ## Requirements
10
+ * Ruby >= 2.3
11
+
12
+ SlackMsgr depends on these other gems for usage at runtime:
13
+ * [Faraday](https://github.com/lostisland/faraday) handles requests to and from [SlackAPI](https://api.slack.com/)
14
+
15
+ ## Installation
16
+ Add the following line to a Gemfile:
17
+
18
+ gem 'slack_msgr'
19
+
20
+ and run `bundle install` from your shell.
21
+
22
+ If you use Rubygems, run this command manually from your shell to install the latest poke-api-v2 version:
23
+
24
+ gem install slack_msgr
25
+
26
+ ## Configuration
27
+ This gem must be configured with credentials provided by Slack. _NOTE: These tokens are secret and given uniquely to you to access your workspace. It is strongly advised to store these in an environment variable and not directly in your configuration file._
28
+
29
+ ### Using Rails
30
+ If you are using this gem with a Rails project, create an initializer file.
31
+
32
+ ```ruby
33
+ # ./config/initializers/slack_msgr.rb
34
+
35
+ SlackMsgr.configure do |config|
36
+ config.verification_token = '1a2b3c4d5e'
37
+ config.client_secret = 'a1b2c3d4e5'
38
+ config.signing_secret = 'aa11bb22cc3'
39
+ config.oauth_access_token = 'xoxp-1234567-xxxxxxxxx'
40
+ config.bot_user_oauth_access_token = 'xoxb-1234567-xxxxxxxxx'
41
+ end
42
+ ```
43
+
44
+ If you are using this gem outside of a Rails project, follow the configuration pattern above, but be sure to run this code before using any functionality of the gem.
45
+
46
+ ## Usage
47
+ _SlackMsgr is still in the early stages of development and has limited functionality. Please refer to the [issues](https://github.com/rdavid1099/slack-msgr/issues) for future development and if you would like to help out._
48
+
49
+ SlackMsgr follows SlackAPI's patterns for methods and functionality. Posting a message in Slack using its API, for example, requires making a `POST` request to `https://slack.com/api/chat.postMessage`. You can execute this identical functionality in SlackMsgr by calling `SlackMsgr.chat(:post_message)`. A `POST` request to `https://slack.com/api/channels.info` would simply be `SlackMsgr.channels(:info)`. Please refer to the list of available functions below for a complete summary of what is built out in this early stage of development.
50
+
51
+ ### SlackMsgr#chat
52
+ All options passed to a chat function follow the patterns and arguments described by the [SlackAPI Documentation](https://api.slack.com/methods). SlackMsgr uses the `bot_user_oauth_access_token` passed in the configuration to send out the messages. At this moment, only one `bot_user_oauth_access_token` can be configured at a time and there is no way to send a message as one user and then send a consecutive message as a different user. This functionality will be built out in the future.
53
+
54
+ Available functions:
55
+ - `:post_message`: [chat.postMessage SlackAPI Docs](https://api.slack.com/methods/chat.postMessage)
56
+
57
+ ```ruby
58
+ SlackMsgr.chat(:post_message, channel: 'announcements', text: 'Hello world')
59
+ # Sends the text 'Hello world' to the announcements channel
60
+
61
+ SlackMsgr.chat(:post_message, {
62
+ channel: "C1H9RESGL",
63
+ text: "Here's a message for you",
64
+ as_user: false,
65
+ username: "testing",
66
+ attachments: [{
67
+ text: "This is an attachment",
68
+ id: 1,
69
+ fallback: "This is an attachment's fallback"
70
+ }]
71
+ })
72
+ # Sends a message with an attachment as a user with the username 'testing'
73
+ ```
74
+
75
+ ## License
76
+
77
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "slack_msgr"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+ require "pry"
9
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SlackMsgr
4
+ GITHUB_REPO = 'https://github.com/rdavid1099/slack-msgr'
5
+
6
+ SLACK_URL = 'https://slack.com'
7
+
8
+ VERSION = '0.0.1'
9
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'faraday'
5
+ require_relative './constants'
6
+
7
+ Dir[File.expand_path 'lib/{slack_msgr,utils}/**/*.rb'].each { |f| require f }
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SlackMsgr
4
+ # Handles all chat functionality and methods corresponding with Slack API
5
+ class Chat < SlackMethod
6
+ CHAT_METHODS = { post_message: 'postMessage' }.freeze
7
+
8
+ REQUIRED_ARGUMENTS = %i[channel text].freeze
9
+
10
+ PERMITTED_ARGUMENTS = %i[
11
+ token
12
+ channel
13
+ text
14
+ as_user
15
+ attachments
16
+ blocks
17
+ icon_emoji
18
+ icon_url
19
+ link_names
20
+ mrkdwn
21
+ parse
22
+ reply_broadcast
23
+ thread_ts
24
+ unfurl_links
25
+ unfurl_media
26
+ username
27
+ ].freeze
28
+
29
+ class << self
30
+ def call(method, opts = {})
31
+ chat = new(method, opts)
32
+
33
+ conn.post do |req|
34
+ req.url "/api/#{chat.method}"
35
+ req.headers['Content-Type'] = 'application/json; charset=utf-8'
36
+ req.body = chat.body
37
+ end
38
+ end
39
+ end
40
+
41
+ attr_reader :method,
42
+ :opts,
43
+ :body
44
+
45
+ def initialize(method, opts)
46
+ chat_method = CHAT_METHODS[method]
47
+ ErrorHandling.raise(:unknown_method, method: method) unless chat_method
48
+
49
+ @method = "chat.#{chat_method}"
50
+ @opts = opts
51
+ @body = sanitize_body
52
+ end
53
+
54
+ private
55
+
56
+ def sanitize_body
57
+ ErrorHandling.raise(:req_args_missing, req_args: REQUIRED_ARGUMENTS, method: method) if req_args_missing? # rubocop:disable LineLength
58
+ opts.keys.each_with_object({}) do |key, body|
59
+ body[key] ||= opts[key] if PERMITTED_ARGUMENTS.include?(key)
60
+ body
61
+ end.to_json
62
+ end
63
+
64
+ def req_args_missing?
65
+ !(REQUIRED_ARGUMENTS - opts.keys).empty?
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SlackMsgr
4
+ # Configuration class handling config variables set on launch
5
+ class Configuration
6
+ attr_accessor :verification_token,
7
+ :client_secret,
8
+ :signing_secret,
9
+ :oauth_access_token,
10
+ :bot_user_oauth_access_token
11
+
12
+ def initialize(
13
+ verification_token: nil,
14
+ client_secret: nil,
15
+ signing_secret: nil,
16
+ oauth_access_token: nil,
17
+ bot_user_oauth_access_token: nil
18
+ )
19
+ @verification_token = verification_token
20
+ @client_secret = client_secret
21
+ @signing_secret = signing_secret
22
+ @oauth_access_token = oauth_access_token
23
+ @bot_user_oauth_access_token = bot_user_oauth_access_token
24
+ end
25
+
26
+ def clear!
27
+ @verification_token = nil
28
+ @client_secret = nil
29
+ @signing_secret = nil
30
+ @oauth_access_token = nil
31
+ @bot_user_oauth_access_token = nil
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SlackMsgr
4
+ # Handles all requests with Slack API
5
+ class SlackMethod
6
+ class << self
7
+ private
8
+
9
+ def conn
10
+ oauth_access_token = SlackMsgr.configuration.oauth_access_token
11
+ ErrorHandling.raise(:configuration_error) unless oauth_access_token
12
+
13
+ faraday = Faraday.new(url: SLACK_URL) do |config|
14
+ config.request :url_encoded # form-encode POST params
15
+ config.adapter Faraday.default_adapter # make requests with Net::HTTP
16
+ end
17
+ faraday.authorization :Bearer, oauth_access_token
18
+ faraday
19
+ end
20
+ end
21
+ end
22
+ end
data/lib/slack_msgr.rb ADDED
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './config/initializer'
4
+
5
+ # Main module housing all classes, modules and methods for SlackMsgr
6
+ module SlackMsgr
7
+ class << self
8
+ def configuration
9
+ @configuration ||= Configuration.new
10
+ end
11
+
12
+ def configure
13
+ yield(configuration)
14
+ end
15
+
16
+ def chat(method, opts = {})
17
+ Chat.call(method, opts)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SlackMsgr
4
+ # Handles all chat functionality and methods corresponding with Slack API
5
+ module ErrorHandling
6
+ class << self
7
+ def raise(error_type, opts = {})
8
+ err = send(error_type, opts)
9
+
10
+ Kernel.raise err[:exception], err[:message]
11
+ end
12
+
13
+ def unknown_method(opts)
14
+ {
15
+ exception: NoMethodError,
16
+ message: "Method not found: #{opts[:method] || 'unknown_method'} does not exist\n" \
17
+ "If you would like this method added, please add an issue at #{GITHUB_REPO}"
18
+ }
19
+ end
20
+
21
+ def configuration_error(_opts)
22
+ {
23
+ exception: ConfigurationError,
24
+ message: "Error with configruation: oauth_access_token not found\n" \
25
+ 'Be sure to configure all tokens and secrets'
26
+ }
27
+ end
28
+
29
+ def req_args_missing(opts)
30
+ {
31
+ exception: ArgumentError,
32
+ message: "Required arguments missing: Method #{opts[:method]} requires arguments:\n" \
33
+ "[ #{opts[:req_args].join(', ')} ] Refer to https://api.slack.com/methods/"
34
+ }
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ # Define custom error class for more descriptive exceptions
41
+ class ConfigurationError < StandardError
42
+ end
@@ -0,0 +1,42 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require './lib/config/constants'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'slack_msgr'
7
+ spec.version = SlackMsgr::VERSION
8
+ spec.authors = ['Ryan Workman']
9
+ spec.email = ['rdavid1099@gmail.com']
10
+
11
+ spec.summary = %q{A Ruby gem to send and receive messages through Slack}
12
+ spec.description = %q{A Ruby gem to send and receive messages through Slack}
13
+ spec.homepage = 'https://github.com/rdavid1099/slack-msgr'
14
+ spec.license = 'MIT'
15
+
16
+ if spec.respond_to?(:metadata)
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = 'https://github.com/rdavid1099/slack_msgr'
19
+ else
20
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
21
+ 'public gem pushes.'
22
+ end
23
+
24
+ # Specify which files should be added to the gem when it is released.
25
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
26
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
27
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
28
+ end
29
+ spec.bindir = 'exe'
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ['lib']
32
+
33
+ spec.add_dependency 'faraday', '~>0.15.4'
34
+
35
+ spec.add_development_dependency 'bundler', '~> 2.0'
36
+ spec.add_development_dependency 'rake', '~> 10.0'
37
+ spec.add_development_dependency 'rspec', '~> 3.0'
38
+ spec.add_development_dependency 'rubocop', '~> 0.71.0'
39
+ spec.add_development_dependency 'reek', '~> 5.4.0'
40
+ spec.add_development_dependency 'simplecov'
41
+ spec.add_development_dependency 'pry'
42
+ end
metadata ADDED
@@ -0,0 +1,179 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: slack_msgr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Workman
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-07-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.15.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.15.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.71.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.71.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: reek
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 5.4.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 5.4.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: A Ruby gem to send and receive messages through Slack
126
+ email:
127
+ - rdavid1099@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".codeclimate.yml"
133
+ - ".gitignore"
134
+ - ".reek.yml"
135
+ - ".rspec"
136
+ - ".rubocop.yml"
137
+ - CODE_OF_CONDUCT.md
138
+ - Gemfile
139
+ - Gemfile.lock
140
+ - LICENSE.txt
141
+ - README.md
142
+ - Rakefile
143
+ - bin/console
144
+ - bin/setup
145
+ - lib/config/constants.rb
146
+ - lib/config/initializer.rb
147
+ - lib/slack_msgr.rb
148
+ - lib/slack_msgr/chat.rb
149
+ - lib/slack_msgr/configuration.rb
150
+ - lib/slack_msgr/fetcher.rb
151
+ - lib/utils/error_handling.rb
152
+ - slack_msgr.gemspec
153
+ homepage: https://github.com/rdavid1099/slack-msgr
154
+ licenses:
155
+ - MIT
156
+ metadata:
157
+ homepage_uri: https://github.com/rdavid1099/slack-msgr
158
+ source_code_uri: https://github.com/rdavid1099/slack_msgr
159
+ post_install_message:
160
+ rdoc_options: []
161
+ require_paths:
162
+ - lib
163
+ required_ruby_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ required_rubygems_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ requirements: []
174
+ rubyforge_project:
175
+ rubygems_version: 2.6.14
176
+ signing_key:
177
+ specification_version: 4
178
+ summary: A Ruby gem to send and receive messages through Slack
179
+ test_files: []