simple_slack 0.1.0

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: 750780880ecea4a4e8f43651a71584cba4eb28f6
4
+ data.tar.gz: d4083cf5ece114fe7b6cfbcfd9b686a1dc2ce749
5
+ SHA512:
6
+ metadata.gz: 43ca832aad72ca76bc48fc7160ca621b428847bf33c11996513c9685246e160799d3996c3f87e8c523f6c455825c5eb9e8cb3249c32c430d8b6147dc89b3bee6
7
+ data.tar.gz: c54fd91383db15f2ad49da2012f53891e486e53a38f99245f5246f1265497a1d1606604f8c13167a2f3f89cf0c03c4d6d89b3f56a4f8d79a15af03666522bc51
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in simple_slack.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 toririn
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,73 @@
1
+ # SimpleSlack
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/simple_slack`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'simple_slack'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install simple_slack
22
+
23
+ ## Usage
24
+
25
+ ```
26
+ client = SimpleSlack::Client.new("your Slack API TOKEN")
27
+ ```
28
+
29
+ ### Get
30
+
31
+ ```
32
+ client.get.channels
33
+ client.get.users
34
+ ```
35
+
36
+ ```
37
+ client.get.channel("channel_id") => { id: "channel_id", name: "channel_name" }
38
+ ```
39
+
40
+ or
41
+
42
+
43
+ ```
44
+ client.get.channel("channel_name") => { id: "channel_id", name: "channel_name" }
45
+ ```
46
+
47
+ and
48
+
49
+ ```
50
+ client.get.user("user_id" or "user_name") => { id: "user_id", name: "user_name"}
51
+ ```
52
+
53
+ ### Post
54
+
55
+ ```
56
+ client.post.channel(to: "general", text: "hello world", name: "myname")
57
+ ```
58
+
59
+ ## Development
60
+
61
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
62
+
63
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
64
+
65
+ ## Contributing
66
+
67
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/simple_slack. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
68
+
69
+
70
+ ## License
71
+
72
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
73
+
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,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "simple_slack"
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
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,19 @@
1
+ require 'slack'
2
+ require 'omniauth-slack'
3
+ require 'simple_slack/getter'
4
+ require 'simple_slack/poster'
5
+
6
+ class SimpleSlack::Client
7
+ def initialize(token)
8
+ Slack.configure { |config| config.token = token }
9
+ @slack = Slack.client
10
+ end
11
+
12
+ def get
13
+ @getter ||= SimpleSlack::Getter.new(@slack)
14
+ end
15
+
16
+ def post
17
+ @poster ||= SimpleSlack::Poster.new(@slack)
18
+ end
19
+ end
@@ -0,0 +1,62 @@
1
+ class SimpleSlack::Getter
2
+ def initialize(slack)
3
+ @slack = slack
4
+ end
5
+
6
+ def channels
7
+ channels = @slack.channels_list
8
+ channels["channels"].map do |channel|
9
+ { id: channel["id"], name: channel["name"] }
10
+ end.sort_by {|ch| ch[:name] }
11
+ end
12
+
13
+ def channel(key)
14
+ key.to_s =~ /\AC0.{7}\Z/ ? key_id = key : key_name = key
15
+ @channel_list ||= channels
16
+ if key_id
17
+ @channel_list.find{|ch| ch[:id] == key_id }
18
+ elsif key_name
19
+ @channel_list.find{|ch| ch[:name] == key_name }
20
+ else
21
+ "not found"
22
+ end
23
+ end
24
+
25
+ def users
26
+ users = @slack.users_list
27
+ users["members"].map do |user|
28
+ { id: user["id"], name: user["name"] }
29
+ end.sort_by {|ch| ch[:name] }
30
+ end
31
+
32
+ def user(key)
33
+ key.to_s =~ /\AU0.{7}\Z/ ? key_id = key : key_name = key
34
+ @user_list ||= users
35
+ if key_id
36
+ @user_list.find{|user| user[:id] == key_id }
37
+ elsif key_name
38
+ @user_list.find{|user| user[:name] == key_name }
39
+ else
40
+ "not found"
41
+ end
42
+ end
43
+
44
+ def images
45
+ image_list = users["members"].map do |user|
46
+ { id: user["id"], image: user["profile"]["image_24"] }
47
+ end
48
+ end
49
+
50
+ def image(id)
51
+ @image_list ||= images
52
+ @image_list.find{|user| user[:id] == id }
53
+ end
54
+
55
+ def chats
56
+ "yet"
57
+ end
58
+
59
+ def chat
60
+ "yet"
61
+ end
62
+ end
@@ -0,0 +1,31 @@
1
+ class SimpleSlack::Poster
2
+ def initialize(slack)
3
+ @slack = slack
4
+ end
5
+
6
+ def channel(to: , text: , name: "slacker")
7
+ to.to_s =~ /\AC0.{7}\Z/ ? id = to : id = convert(to)
8
+ result = @slack.chat_postMessage(username: name, channel: id, text: text)
9
+ result["ok"]
10
+ end
11
+
12
+ def user(to: , text: , name: "slacker")
13
+ "yet"
14
+ end
15
+
16
+ def chat(channel: nil, user: nil, text: , name: "slacker")
17
+ if channel
18
+ self.channel(to: to, text: text, name: name)
19
+ elsif user
20
+ "yet"
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def convert(name)
27
+ getter = SimpleSlack::Getter.new(@slack)
28
+ channel = getter.channel(name)
29
+ channel[:id]
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module SimpleSlack
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,5 @@
1
+ require "simple_slack/version"
2
+ require "simple_slack/client"
3
+
4
+ module SimpleSlack
5
+ end
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'simple_slack/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "simple_slack"
8
+ spec.version = SimpleSlack::VERSION
9
+ spec.authors = ["toririn"]
10
+ spec.email = ["toririn.paftako@gmail.com"]
11
+
12
+ spec.summary = %q{simple use slack}
13
+ spec.description = %q{simple use slack}
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.10"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rspec"
33
+
34
+ spec.add_dependency "slack-api", '~>1.2.1'
35
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_slack
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - toririn
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: slack-api
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.2.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.2.1
69
+ description: simple use slack
70
+ email:
71
+ - toririn.paftako@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - lib/simple_slack.rb
87
+ - lib/simple_slack/client.rb
88
+ - lib/simple_slack/getter.rb
89
+ - lib/simple_slack/poster.rb
90
+ - lib/simple_slack/version.rb
91
+ - simple_slack.gemspec
92
+ homepage: ''
93
+ licenses:
94
+ - MIT
95
+ metadata:
96
+ allowed_push_host: https://rubygems.org
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.4.5
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: simple use slack
117
+ test_files: []