komonjo 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +50 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/komonjo.gemspec +27 -0
- data/lib/komonjo.rb +16 -0
- data/lib/komonjo/client.rb +22 -0
- data/lib/komonjo/connections/slack_connection.rb +59 -0
- data/lib/komonjo/extensions/hash_extensions.rb +8 -0
- data/lib/komonjo/extensions/to_json.rb +16 -0
- data/lib/komonjo/gateways/channels_gateway.rb +15 -0
- data/lib/komonjo/gateways/messages_gateway.rb +36 -0
- data/lib/komonjo/mocks/slack_mock.rb +84 -0
- data/lib/komonjo/models/api/response_base.rb +25 -0
- data/lib/komonjo/models/channel.rb +16 -0
- data/lib/komonjo/models/message.rb +47 -0
- data/lib/komonjo/models/profile.rb +15 -0
- data/lib/komonjo/models/user.rb +19 -0
- data/lib/komonjo/services/channels_service.rb +17 -0
- data/lib/komonjo/services/login_service.rb +15 -0
- data/lib/komonjo/services/messages_service.rb +18 -0
- data/lib/komonjo/services/slack_service.rb +10 -0
- data/lib/komonjo/version.rb +3 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e3f1a6dd632f13cdf283ef1c850ebdea0659a607
|
4
|
+
data.tar.gz: 736f46282d66595aa22839ce3d90f68b539a88c6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9d896f691aa414e3a6f6a9d87ea77ccb230ef4d7ef222893340315fb9a7b4d9dc1e21687b07c9e4e8277a289e379ea79146346f8200e6dd54ac93c46ade12b91
|
7
|
+
data.tar.gz: 832a69b6ceb1b93d6afea95b33214702d8e9d67c0c0b266fb5317de5bf1c1383f6526df00f76a421ef3c236b5cd1cac115cba7f620733756c4baebddb6f0b961
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 hkdnet
|
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,50 @@
|
|
1
|
+
# Komonjo
|
2
|
+
|
3
|
+
A Slack client wrapper
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'komonjo'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install komonjo-ruby
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
client = Komonjo::Client.new(your_slack_token)
|
25
|
+
|
26
|
+
# checking connection
|
27
|
+
client.token_valid?
|
28
|
+
|
29
|
+
# get channels
|
30
|
+
client.channels
|
31
|
+
|
32
|
+
# get message at a channel
|
33
|
+
# Note: The argument is not channel_id but channel_name
|
34
|
+
client.messages(channel_name)
|
35
|
+
```
|
36
|
+
|
37
|
+
## Development
|
38
|
+
|
39
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
40
|
+
|
41
|
+
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).
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/hkdnet/komonjo-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
46
|
+
|
47
|
+
|
48
|
+
## License
|
49
|
+
|
50
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "komonjo"
|
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
data/komonjo.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'komonjo/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "komonjo"
|
8
|
+
spec.version = Komonjo::VERSION
|
9
|
+
spec.authors = ["hkdnet"]
|
10
|
+
spec.email = ["hkdnet@users.noreply.github.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A Slack client wrapper.}
|
13
|
+
spec.description = %q{A Slack client wrapper.}
|
14
|
+
spec.homepage = "https://github.com/hkdnet/komonjo-ruby"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "slack-api", "~> 1.1.6"
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
26
|
+
spec.add_development_dependency "minitest-power_assert", "~> 0.2.0"
|
27
|
+
end
|
data/lib/komonjo.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'komonjo/client'
|
2
|
+
require 'komonjo/version'
|
3
|
+
require 'komonjo/connections/slack_connection'
|
4
|
+
require 'komonjo/extensions/hash_extensions'
|
5
|
+
require 'komonjo/extensions/to_json'
|
6
|
+
require 'komonjo/gateways/channels_gateway'
|
7
|
+
require 'komonjo/gateways/messages_gateway'
|
8
|
+
require 'komonjo/models/api/response_base'
|
9
|
+
require 'komonjo/models/channel'
|
10
|
+
require 'komonjo/models/message'
|
11
|
+
require 'komonjo/models/profile'
|
12
|
+
require 'komonjo/models/user'
|
13
|
+
require 'komonjo/services/slack_service'
|
14
|
+
require 'komonjo/services/channels_service'
|
15
|
+
require 'komonjo/services/login_service'
|
16
|
+
require 'komonjo/services/messages_service'
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Komonjo
|
2
|
+
class Client
|
3
|
+
def initialize(api_token)
|
4
|
+
@api_token = api_token
|
5
|
+
end
|
6
|
+
|
7
|
+
def token_valid?
|
8
|
+
s = Komonjo::Service::LoginService.new(@api_token)
|
9
|
+
s.login
|
10
|
+
end
|
11
|
+
|
12
|
+
def channels
|
13
|
+
s = Komonjo::Service::ChannelsService.new(@api_token)
|
14
|
+
s.channels
|
15
|
+
end
|
16
|
+
|
17
|
+
def messages(channel_name)
|
18
|
+
s = Komonjo::Service::MessagesService.new(@api_token)
|
19
|
+
s.messages(channel_name)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'slack'
|
2
|
+
|
3
|
+
module Komonjo
|
4
|
+
module Connection
|
5
|
+
# Connection for slack
|
6
|
+
class SlackConnection
|
7
|
+
attr_reader :client
|
8
|
+
def initialize(api_token)
|
9
|
+
@client = Slack::Client.new(token: api_token)
|
10
|
+
end
|
11
|
+
|
12
|
+
def channels_history(channel_name)
|
13
|
+
channel_name[0] = '' if channel_name[0] == '#'
|
14
|
+
channel_id = channel_id channel_name
|
15
|
+
ret = client.channels_history(channel: channel_id)
|
16
|
+
fail 'error' unless ret['ok']
|
17
|
+
ret['messages']
|
18
|
+
end
|
19
|
+
|
20
|
+
def users_info(user_id)
|
21
|
+
ret = client.users_info(user: user_id)
|
22
|
+
fail 'error' unless ret['ok']
|
23
|
+
ret['user']
|
24
|
+
end
|
25
|
+
|
26
|
+
def users_list
|
27
|
+
ret = client.users_list
|
28
|
+
fail 'error' unless ret['ok']
|
29
|
+
ret['members']
|
30
|
+
end
|
31
|
+
|
32
|
+
def channels_list
|
33
|
+
ret = client.channels_list
|
34
|
+
fail 'error' unless ret['ok']
|
35
|
+
ret['channels']
|
36
|
+
end
|
37
|
+
|
38
|
+
def auth_test
|
39
|
+
ret = client.auth_test
|
40
|
+
ret['ok']
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def channel_id(channel_name)
|
46
|
+
channel_list = Slack.channels_list
|
47
|
+
fail 'error' unless channel_list['ok']
|
48
|
+
target_channel = channel_list['channels'].select do |e|
|
49
|
+
e['name'] == channel_name
|
50
|
+
end
|
51
|
+
if target_channel.empty?
|
52
|
+
fail "unknown channel name: #{channel_name}"
|
53
|
+
else
|
54
|
+
target_channel.first['id']
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Komonjo
|
2
|
+
module Extension
|
3
|
+
# generate to_json method
|
4
|
+
module ToJson
|
5
|
+
def to_json(*args)
|
6
|
+
ret = instance_variables.each_with_object({}) do |attr, hash|
|
7
|
+
# remove head @
|
8
|
+
key = attr.to_s
|
9
|
+
key[0] = ''
|
10
|
+
hash[key.to_sym] = instance_variable_get(attr)
|
11
|
+
end
|
12
|
+
ret.to_json(*args)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Komonjo
|
2
|
+
module Gateway
|
3
|
+
# Merge history and users
|
4
|
+
class ChannelsGateway
|
5
|
+
using HashExtensions
|
6
|
+
def initialize(channels)
|
7
|
+
@channels = channels.map { |e| Hash[e.symbolize_keys] }
|
8
|
+
end
|
9
|
+
|
10
|
+
def channels
|
11
|
+
@channels.map { |e| Komonjo::Model::Channel.create(e) }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
3
|
+
module Komonjo
|
4
|
+
module Gateway
|
5
|
+
# Merge history and users
|
6
|
+
class MessagesGateway
|
7
|
+
using HashExtensions
|
8
|
+
def initialize(history, users)
|
9
|
+
@history = history.map { |e| Hash[e.symbolize_keys] }
|
10
|
+
@users = users.map do |e|
|
11
|
+
ret = Hash[e.symbolize_keys]
|
12
|
+
ret[:profile] = Hash[ret[:profile].symbolize_keys]
|
13
|
+
ret
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def messages
|
18
|
+
@history.map do |e|
|
19
|
+
next e unless e[:user]
|
20
|
+
Komonjo::Model::Message.create(e).tap do |message|
|
21
|
+
message.user = find_user(e[:user])
|
22
|
+
message.text = CGI.unescapeHTML(message.text)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def find_user(user_id)
|
30
|
+
user = @users.find { |e| e[:id] == user_id }
|
31
|
+
fail "unknown user: #{user_id}" unless user
|
32
|
+
Komonjo::Model::User.create(user)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module Komonjo
|
2
|
+
module Mock
|
3
|
+
# Mock for SlackConnection
|
4
|
+
class SlackMock
|
5
|
+
class << self
|
6
|
+
def chat_logs
|
7
|
+
g = Komonjo::Gateway::MessagesGateway.new(channels_history('test'),
|
8
|
+
users_list)
|
9
|
+
g.messages
|
10
|
+
end
|
11
|
+
|
12
|
+
def users_list
|
13
|
+
[{ id: 'id001', name: 'name001', deleted: false,
|
14
|
+
profile: { image_48: '' } },
|
15
|
+
{ id: 'id002', name: 'name002', deleted: false,
|
16
|
+
profile: { image_48: '' } }]
|
17
|
+
end
|
18
|
+
|
19
|
+
def channels_history(channel_name)
|
20
|
+
[{ type: 'message', user: 'id001', channel: channel_name,
|
21
|
+
text: 'Hello, world' },
|
22
|
+
{ type: 'message', user: 'id002', channel: channel_name,
|
23
|
+
text: 'This is Komonjo' }]
|
24
|
+
end
|
25
|
+
|
26
|
+
def channels_list
|
27
|
+
[{
|
28
|
+
'id': 'C024BE91L',
|
29
|
+
'name': 'channel1',
|
30
|
+
'is_channel': 'true',
|
31
|
+
'created': 1_360_782_804,
|
32
|
+
'creator': 'U024BE7LH',
|
33
|
+
'is_archived': false,
|
34
|
+
'is_general': false,
|
35
|
+
'members': %w(U024BE7LH U024BE7LH),
|
36
|
+
'topic': {
|
37
|
+
'value': 'Fun times',
|
38
|
+
'creator': 'U024BE7LV',
|
39
|
+
'last_set': 1_369_677_212
|
40
|
+
},
|
41
|
+
'purpose': {
|
42
|
+
'value': 'This channel is for fun',
|
43
|
+
'creator': 'U024BE7LH',
|
44
|
+
'last_set': 1_360_782_804
|
45
|
+
},
|
46
|
+
'is_member': true,
|
47
|
+
'last_read': '1401383885.000061',
|
48
|
+
'latest': {
|
49
|
+
'hoge': 'fuga'
|
50
|
+
},
|
51
|
+
'unread_count': 0,
|
52
|
+
'unread_count_display': 0
|
53
|
+
}, {
|
54
|
+
'id': 'C024BE91L',
|
55
|
+
'name': 'channel1',
|
56
|
+
'is_channel': 'true',
|
57
|
+
'created': 1_360_782_804,
|
58
|
+
'creator': 'U024BE7LH',
|
59
|
+
'is_archived': false,
|
60
|
+
'is_general': false,
|
61
|
+
'members': %w(U024BE7LH U024BE7LH),
|
62
|
+
'topic': {
|
63
|
+
'value': 'Fun times',
|
64
|
+
'creator': 'U024BE7LV',
|
65
|
+
'last_set': 1_369_677_212
|
66
|
+
},
|
67
|
+
'purpose': {
|
68
|
+
'value': 'This channel is for fun',
|
69
|
+
'creator': 'U024BE7LH',
|
70
|
+
'last_set': 1_360_782_804
|
71
|
+
},
|
72
|
+
'is_member': true,
|
73
|
+
'last_read': '1401383885.000061',
|
74
|
+
'latest': {
|
75
|
+
'hoge': 'fuga'
|
76
|
+
},
|
77
|
+
'unread_count': 0,
|
78
|
+
'unread_count_display': 0
|
79
|
+
}]
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Komonjo
|
4
|
+
module Model
|
5
|
+
module API
|
6
|
+
# api response base class
|
7
|
+
class ResponseBase
|
8
|
+
attr_accessor :ok, :message, :data
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@ok = true
|
12
|
+
@message = ''
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_json
|
16
|
+
hash = {}
|
17
|
+
hash[:ok] = @ok
|
18
|
+
hash[:message] = @message
|
19
|
+
hash[:data] = @data
|
20
|
+
JSON[hash]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Komonjo
|
2
|
+
module Model
|
3
|
+
# slacke channel
|
4
|
+
class Channel
|
5
|
+
attr_accessor :id, :name, :is_channel, :created, :creator, :is_archived,
|
6
|
+
:is_general, :members, :topic, :purpose, :is_member,
|
7
|
+
:last_read, :latest, :unread_count, :unread_count_display
|
8
|
+
|
9
|
+
def self.create(hash)
|
10
|
+
new.tap do |e|
|
11
|
+
hash.each { |k, v| e.instance_variable_set("@#{k}", v) }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Komonjo
|
2
|
+
module Model
|
3
|
+
# slacke Message
|
4
|
+
class Message
|
5
|
+
include Komonjo::Extension::ToJson
|
6
|
+
attr_accessor :type, :channel, :user, :text, :ts, :edited, :subtype
|
7
|
+
# for jsonize
|
8
|
+
attr_reader :markdown
|
9
|
+
alias_method :to_json_org, :to_json
|
10
|
+
|
11
|
+
def self.create(hash)
|
12
|
+
new.tap do |e|
|
13
|
+
hash.each { |k, v| e.instance_variable_set("@#{k}", v) }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def timestamp
|
18
|
+
Time.at(@ts.to_f).strftime('%Y-%m-%d %H:%M:%S')
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_markdown
|
22
|
+
icon_markdown + name_markdown + ts_markdown + text_markdown
|
23
|
+
end
|
24
|
+
|
25
|
+
def icon_markdown
|
26
|
+
"* \n"
|
27
|
+
end
|
28
|
+
|
29
|
+
def name_markdown
|
30
|
+
"\t- #{@user.name}\n"
|
31
|
+
end
|
32
|
+
|
33
|
+
def ts_markdown
|
34
|
+
"\t- #{timestamp}\n"
|
35
|
+
end
|
36
|
+
|
37
|
+
def text_markdown
|
38
|
+
"\t- #{@text}\n"
|
39
|
+
end
|
40
|
+
|
41
|
+
def to_json(*args)
|
42
|
+
@markdown = to_markdown
|
43
|
+
to_json_org(args)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Komonjo
|
2
|
+
module Model
|
3
|
+
# slack User.profile
|
4
|
+
class Profile
|
5
|
+
include Komonjo::Extension::ToJson
|
6
|
+
|
7
|
+
attr_accessor :first_name, :last_name, :real_name, :email, :skype, :phone,
|
8
|
+
:image_24, :image_32, :image_48, :image_72, :image_192
|
9
|
+
|
10
|
+
def self.create(hash)
|
11
|
+
new.tap { |e| hash.each { |k, v| e.instance_variable_set("@#{k}", v) } }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Komonjo
|
2
|
+
module Model
|
3
|
+
# slack user
|
4
|
+
class User
|
5
|
+
include Komonjo::Extension::ToJson
|
6
|
+
|
7
|
+
attr_accessor :profile, :id, :name, :deleted, :color, :is_admin,
|
8
|
+
:is_owner, :is_primary_owner, :is_restricted,
|
9
|
+
:is_ultra_restricted, :has_2fa, :has_files
|
10
|
+
|
11
|
+
def self.create(hash)
|
12
|
+
new.tap do |e|
|
13
|
+
hash.each { |k, v| e.instance_variable_set("@#{k}", v) }
|
14
|
+
e.profile = Profile.create(hash[:profile]) if hash[:profile]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Komonjo
|
2
|
+
module Service
|
3
|
+
# A service for get channels_list as Komonjo::Model::Channel
|
4
|
+
class ChannelsService < Komonjo::Service::SlackService
|
5
|
+
def initialize(api_token)
|
6
|
+
@api_token = api_token
|
7
|
+
end
|
8
|
+
|
9
|
+
def channels
|
10
|
+
connection = connection(@api_token)
|
11
|
+
raw_channels = connection.channels_list
|
12
|
+
gateway = Komonjo::Gateway::ChannelsGateway.new raw_channels
|
13
|
+
gateway.channels
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Komonjo
|
2
|
+
module Service
|
3
|
+
# A service for get channels_list as Komonjo::Model::Channel
|
4
|
+
class LoginService < Komonjo::Service::SlackService
|
5
|
+
def initialize(api_token)
|
6
|
+
@api_token = api_token
|
7
|
+
end
|
8
|
+
|
9
|
+
def login
|
10
|
+
connection = connection(@api_token)
|
11
|
+
connection.auth_test
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Komonjo
|
2
|
+
module Service
|
3
|
+
# A service for merge channel log and user information
|
4
|
+
class MessagesService < Komonjo::Service::SlackService
|
5
|
+
def initialize(api_token)
|
6
|
+
@api_token = api_token
|
7
|
+
end
|
8
|
+
|
9
|
+
def messages(channel_name)
|
10
|
+
connection = connection(@api_token)
|
11
|
+
history = connection.channels_history channel_name
|
12
|
+
users = connection.users_list
|
13
|
+
gateway = Komonjo::Gateway::MessagesGateway.new history, users
|
14
|
+
gateway.messages
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: komonjo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- hkdnet
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: slack-api
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.1.6
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.1.6
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.11'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.11'
|
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: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest-power_assert
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.2.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.2.0
|
83
|
+
description: A Slack client wrapper.
|
84
|
+
email:
|
85
|
+
- hkdnet@users.noreply.github.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".travis.yml"
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- bin/console
|
97
|
+
- bin/setup
|
98
|
+
- komonjo.gemspec
|
99
|
+
- lib/komonjo.rb
|
100
|
+
- lib/komonjo/client.rb
|
101
|
+
- lib/komonjo/connections/slack_connection.rb
|
102
|
+
- lib/komonjo/extensions/hash_extensions.rb
|
103
|
+
- lib/komonjo/extensions/to_json.rb
|
104
|
+
- lib/komonjo/gateways/channels_gateway.rb
|
105
|
+
- lib/komonjo/gateways/messages_gateway.rb
|
106
|
+
- lib/komonjo/mocks/slack_mock.rb
|
107
|
+
- lib/komonjo/models/api/response_base.rb
|
108
|
+
- lib/komonjo/models/channel.rb
|
109
|
+
- lib/komonjo/models/message.rb
|
110
|
+
- lib/komonjo/models/profile.rb
|
111
|
+
- lib/komonjo/models/user.rb
|
112
|
+
- lib/komonjo/services/channels_service.rb
|
113
|
+
- lib/komonjo/services/login_service.rb
|
114
|
+
- lib/komonjo/services/messages_service.rb
|
115
|
+
- lib/komonjo/services/slack_service.rb
|
116
|
+
- lib/komonjo/version.rb
|
117
|
+
homepage: https://github.com/hkdnet/komonjo-ruby
|
118
|
+
licenses:
|
119
|
+
- MIT
|
120
|
+
metadata: {}
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
requirements: []
|
136
|
+
rubyforge_project:
|
137
|
+
rubygems_version: 2.4.5.1
|
138
|
+
signing_key:
|
139
|
+
specification_version: 4
|
140
|
+
summary: A Slack client wrapper.
|
141
|
+
test_files: []
|
142
|
+
has_rdoc:
|