slack-ruby 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/lib/slack/rpc/client.rb +44 -0
- data/lib/slack/rpc/command.rb +46 -0
- data/lib/slack/rpc/invoker.rb +51 -0
- data/lib/slack/version.rb +3 -0
- data/lib/slack.rb +2 -0
- data/slack.gemspec +26 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 68b48f7b87ba4acbd769054835ea8d6c78749c0d
|
4
|
+
data.tar.gz: 5535f467ccc763483eb4e0ce767b1f7e1d0266f2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4a13d0d3e2bdabe5868d1163bbaa1d15af6f9603247bf05e37b6a7bc3f36dacf1e4521cee36075a62dc428d93340159a93a07c8ba38f8cc702048c03334e2dca
|
7
|
+
data.tar.gz: 41bf15183a6849b13a47a619e2fd91ca3f63f41f8397575093be35139b29c7aa51cb8dc91def48e8a71b001748c94171863511dc9c6b2c48f5193f12a115b52f
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 morou
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Slack::Ruby
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'slack-ruby'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install slack-ruby
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/slack-ruby/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require "slack/rpc/invoker"
|
2
|
+
require "slack/rpc/command"
|
3
|
+
|
4
|
+
module Slack
|
5
|
+
module RPC
|
6
|
+
|
7
|
+
# ## Slack::RPC::Client
|
8
|
+
# A class for Slack RPC-Style API client
|
9
|
+
#
|
10
|
+
class Client
|
11
|
+
|
12
|
+
# ### Slack::RPC::Client.new(token)
|
13
|
+
# Creates a new instance of `Slack::RPC::Client` class
|
14
|
+
#
|
15
|
+
def initialize(token)
|
16
|
+
invoker = Invoker.new(token)
|
17
|
+
define_command(invoker, "api", %w{test})
|
18
|
+
define_command(invoker, "auth", %w{test})
|
19
|
+
define_command(invoker, "channels", %w{archive create history info invite join kick leave list mark rename setPurpose setTopic unarchive})
|
20
|
+
define_command(invoker, "chat", %w{delete postMessage update})
|
21
|
+
define_command(invoker, "emoji", %w{list})
|
22
|
+
define_command(invoker, "files", %w{info list upload})
|
23
|
+
define_command(invoker, "groups", %w{archive close create createChild history invite kick leave list mark open rename setPurpose setTopic unarchive})
|
24
|
+
define_command(invoker, "im", %w{close history list mark open})
|
25
|
+
define_command(invoker, "oauth", %w{access})
|
26
|
+
define_command(invoker, "rtm", %w{start})
|
27
|
+
define_command(invoker, "search", %w{all files messages})
|
28
|
+
define_command(invoker, "stars", %w{list})
|
29
|
+
define_command(invoker, "users", %w{getPresence info list setActive setPresence})
|
30
|
+
end
|
31
|
+
|
32
|
+
# ### Slack::RPC::Client::define_command(invoker, name, sub_commands)
|
33
|
+
# Create `Slack::RPC::Command` object and store it as instance variable and expose it
|
34
|
+
#
|
35
|
+
def define_command(invoker, name, sub_commands)
|
36
|
+
command = Command.new(invoker, name, sub_commands)
|
37
|
+
instance_variable_set(:"@#{name}", command)
|
38
|
+
self.class.class_eval('attr_reader :"#{name}"')
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Slack
|
2
|
+
module RPC
|
3
|
+
|
4
|
+
# ## Slack::RPC::Command
|
5
|
+
# A class that represents Slack-RPC style command
|
6
|
+
#
|
7
|
+
class Command
|
8
|
+
|
9
|
+
# ### Slack::RPC::Commnad.new(invoker, command, sub_commands)
|
10
|
+
# Creates a new instance of `Slack::RPC::Command` class
|
11
|
+
#
|
12
|
+
def initialize(invoker, command, sub_commands)
|
13
|
+
@invoker = invoker
|
14
|
+
@command = command
|
15
|
+
@sub_commands = sub_commands
|
16
|
+
end
|
17
|
+
|
18
|
+
# ### Slack::RPC::Command.invoke_command
|
19
|
+
# Invokes Slack RPC-Style command
|
20
|
+
#
|
21
|
+
def invoke_command(sub_command, args, &block)
|
22
|
+
@invoker.invoke(@command, sub_command, args, &block)
|
23
|
+
end
|
24
|
+
|
25
|
+
# ### Slack::RPC::Command.respond_to?(name)
|
26
|
+
# Returns true if obj responds to the given method.
|
27
|
+
#
|
28
|
+
def respond_to?(name)
|
29
|
+
@sub_commands.include?(name) || super
|
30
|
+
end
|
31
|
+
|
32
|
+
# ### Slack::RPC::Command.method_missing(name, *args, &block)
|
33
|
+
# Invoked by Ruby when obj is sent a message it cannot handle.
|
34
|
+
#
|
35
|
+
def method_missing(name, *args, &block)
|
36
|
+
if @sub_commands.include?(name.to_s) && args.length == 1 && args[0].class == Hash then
|
37
|
+
invoke_command(name.to_s, args[0], &block)
|
38
|
+
else
|
39
|
+
super
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require "faraday"
|
2
|
+
require "faraday_middleware"
|
3
|
+
|
4
|
+
module Slack
|
5
|
+
module RPC
|
6
|
+
|
7
|
+
# ## Slack::RPC::Invoker
|
8
|
+
# A class for invoke Slack RPC-Style command
|
9
|
+
#
|
10
|
+
class Invoker
|
11
|
+
|
12
|
+
# ### Slack::RPC::Invoker.BASE_URL
|
13
|
+
# A base url to invoke Slack RPC-Style command
|
14
|
+
#
|
15
|
+
BASE_URL = "https://slack.com/api"
|
16
|
+
|
17
|
+
# ### Slack::RPC::Invoker.new(token)
|
18
|
+
# Creates a new instance of `Slack::RPC::Invoker` class
|
19
|
+
#
|
20
|
+
def initialize(token)
|
21
|
+
@token = token
|
22
|
+
end
|
23
|
+
|
24
|
+
# ### Slack::RPC::Invoker.invoke(command, sub_commnad, args, &block)
|
25
|
+
# Invokes Slack RPC-Style command
|
26
|
+
#
|
27
|
+
def invoke(command, sub_command, args, &block)
|
28
|
+
responce = connection.get("#{command}.#{sub_command}", args.clone.merge({:token => @token}))
|
29
|
+
if block then
|
30
|
+
yield responce.body
|
31
|
+
else
|
32
|
+
responce.body
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# ### Slack::RPC::Invoker.connection
|
37
|
+
# retrieve Faraday Connection object
|
38
|
+
#
|
39
|
+
def connection
|
40
|
+
Faraday.new(:url => BASE_URL) { |faraday|
|
41
|
+
faraday.request :url_encoded
|
42
|
+
faraday.response :logger
|
43
|
+
faraday.response :json
|
44
|
+
faraday.adapter Faraday.default_adapter
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
data/lib/slack.rb
ADDED
data/slack.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'slack/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "slack-ruby"
|
8
|
+
spec.version = Slack::VERSION
|
9
|
+
spec.authors = ["morou"]
|
10
|
+
spec.email = ["kazuhiro.nakae@gmail.com"]
|
11
|
+
spec.summary = %q{A Ruby interface to Slack API}
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = "https://github.com/morou/slack-ruby-gem"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "faraday", "~> 0.9"
|
22
|
+
spec.add_dependency "faraday_middleware"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: slack-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- morou
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-23 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.9'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday_middleware
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description: A Ruby interface to Slack API
|
70
|
+
email:
|
71
|
+
- kazuhiro.nakae@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- lib/slack.rb
|
82
|
+
- lib/slack/rpc/client.rb
|
83
|
+
- lib/slack/rpc/command.rb
|
84
|
+
- lib/slack/rpc/invoker.rb
|
85
|
+
- lib/slack/version.rb
|
86
|
+
- slack.gemspec
|
87
|
+
homepage: https://github.com/morou/slack-ruby-gem
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.2.2
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: A Ruby interface to Slack API
|
111
|
+
test_files: []
|