slack-ruby 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 68b48f7b87ba4acbd769054835ea8d6c78749c0d
4
- data.tar.gz: 5535f467ccc763483eb4e0ce767b1f7e1d0266f2
3
+ metadata.gz: e5a0fb441d7414a2a0da1a58f4e6931b57b421b8
4
+ data.tar.gz: 859b4e78624453ea375dc41887bbe60b72b83b87
5
5
  SHA512:
6
- metadata.gz: 4a13d0d3e2bdabe5868d1163bbaa1d15af6f9603247bf05e37b6a7bc3f36dacf1e4521cee36075a62dc428d93340159a93a07c8ba38f8cc702048c03334e2dca
7
- data.tar.gz: 41bf15183a6849b13a47a619e2fd91ca3f63f41f8397575093be35139b29c7aa51cb8dc91def48e8a71b001748c94171863511dc9c6b2c48f5193f12a115b52f
6
+ metadata.gz: 3ca8aa7091c3c760b4b787aad9ab659131f55f8aaccd18465f431cbf56bc5028750f850b393fb27d7e1537e816ff30b13f12d043ab5de227a22f9628b2f364ec
7
+ data.tar.gz: 2a8870d09739ed85b71f22a26faead18883b08fe252864a8953680a1059aff8b8722eb3323b15ea643a45009b138320d88553e65a4e0229d9dbe9d0a6fd7655e
@@ -1,4 +1,4 @@
1
- require "slack/rpc/invoker"
1
+ require "slack/rpc/connection"
2
2
  require "slack/rpc/command"
3
3
 
4
4
  module Slack
@@ -13,27 +13,27 @@ module Slack
13
13
  # Creates a new instance of `Slack::RPC::Client` class
14
14
  #
15
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})
16
+ conn = Connection.new(token)
17
+ define_command(conn, "api", %w{test})
18
+ define_command(conn, "auth", %w{test})
19
+ define_command(conn, "channels", %w{archive create history info invite join kick leave list mark rename setPurpose setTopic unarchive})
20
+ define_command(conn, "chat", %w{delete postMessage update})
21
+ define_command(conn, "emoji", %w{list})
22
+ define_command(conn, "files", %w{info list upload})
23
+ define_command(conn, "groups", %w{archive close create createChild history invite kick leave list mark open rename setPurpose setTopic unarchive})
24
+ define_command(conn, "im", %w{close history list mark open})
25
+ define_command(conn, "oauth", %w{access})
26
+ define_command(conn, "rtm", %w{start})
27
+ define_command(conn, "search", %w{all files messages})
28
+ define_command(conn, "stars", %w{list})
29
+ define_command(conn, "users", %w{getPresence info list setActive setPresence})
30
30
  end
31
31
 
32
- # ### Slack::RPC::Client::define_command(invoker, name, sub_commands)
32
+ # ### Slack::RPC::Client::define_command(conn, name, sub_commands)
33
33
  # Create `Slack::RPC::Command` object and store it as instance variable and expose it
34
34
  #
35
- def define_command(invoker, name, sub_commands)
36
- command = Command.new(invoker, name, sub_commands)
35
+ def define_command(conn, name, sub_commands)
36
+ command = Command.new(conn, name, sub_commands)
37
37
  instance_variable_set(:"@#{name}", command)
38
38
  self.class.class_eval('attr_reader :"#{name}"')
39
39
  end
@@ -6,11 +6,11 @@ module Slack
6
6
  #
7
7
  class Command
8
8
 
9
- # ### Slack::RPC::Commnad.new(invoker, command, sub_commands)
9
+ # ### Slack::RPC::Commnad.new(conn, command, sub_commands)
10
10
  # Creates a new instance of `Slack::RPC::Command` class
11
11
  #
12
- def initialize(invoker, command, sub_commands)
13
- @invoker = invoker
12
+ def initialize(connection, command, sub_commands)
13
+ @connection = connection
14
14
  @command = command
15
15
  @sub_commands = sub_commands
16
16
  end
@@ -18,8 +18,8 @@ module Slack
18
18
  # ### Slack::RPC::Command.invoke_command
19
19
  # Invokes Slack RPC-Style command
20
20
  #
21
- def invoke_command(sub_command, args, &block)
22
- @invoker.invoke(@command, sub_command, args, &block)
21
+ def call(sub_command, args, &block)
22
+ @connection.call(@command, sub_command, args, &block)
23
23
  end
24
24
 
25
25
  # ### Slack::RPC::Command.respond_to?(name)
@@ -34,7 +34,7 @@ module Slack
34
34
  #
35
35
  def method_missing(name, *args, &block)
36
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)
37
+ call(name.to_s, args[0], &block)
38
38
  else
39
39
  super
40
40
  end
@@ -0,0 +1,60 @@
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+ require "slack/rpc/response"
4
+
5
+ module Slack
6
+ module RPC
7
+
8
+ # ## Slack::RPC::Connection
9
+ # A class for invoke Slack RPC-Style command
10
+ #
11
+ class Connection
12
+
13
+ # ### Slack::RPC::Connection.BASE_URL
14
+ # A base url to invoke Slack RPC-Style command
15
+ #
16
+ BASE_URL = "https://slack.com/api"
17
+
18
+ # ### Slack::RPC::Connection.HEADERS
19
+ # HTTP request headers as Hash object
20
+ #
21
+ HEADERS = {
22
+ "Accept" => "application/json",
23
+ "User-Agent" => "Slack Ruby Gem #{Slack::VERSION}"
24
+ }
25
+
26
+ # ### Slack::RPC::Connection.new(token)
27
+ # Creates a new instance of `Slack::RPC::Connection` class
28
+ #
29
+ def initialize(token)
30
+ @token = token
31
+ end
32
+
33
+ # ### Slack::RPC::Connection.call(command, sub_commnad, args, &block)
34
+ # Call Slack RPC-Style command
35
+ #
36
+ def call(command, sub_command, args, &block)
37
+ faraday_response = connection.get("#{command}.#{sub_command}", args.clone.merge({:token => @token}))
38
+ response = Response.new(faraday_response)
39
+ if block then
40
+ yield response
41
+ else
42
+ response
43
+ end
44
+ end
45
+
46
+ # ### Slack::RPC::Connection.connection
47
+ # retrieve Faraday Connection object
48
+ #
49
+ def connection
50
+ @connection ||= Faraday.new(:headers => HEADERS, :url => BASE_URL) { |faraday|
51
+ faraday.request :url_encoded
52
+ faraday.response :json
53
+ faraday.adapter Faraday.default_adapter
54
+ }
55
+ end
56
+
57
+ end
58
+ end
59
+ end
60
+
@@ -0,0 +1,22 @@
1
+ module Slack
2
+ module RPC
3
+
4
+ # ## Slack::RPC::Response
5
+ # A class that represents Slack-RPC style command response
6
+ #
7
+ class Response
8
+ attr_reader :status, :headers, :body
9
+
10
+ # ### Slack::RPC::Response.new(faraday_response)
11
+ # Creates a new instance of `Slack::RPC::Response` class
12
+ #
13
+ def initialize(faraday_response)
14
+ @status = faraday_response.status
15
+ @headers = faraday_response.headers
16
+ @body = faraday_response.body
17
+ end
18
+
19
+ end
20
+
21
+ end
22
+ end
data/lib/slack/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Slack
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - morou
@@ -81,7 +81,8 @@ files:
81
81
  - lib/slack.rb
82
82
  - lib/slack/rpc/client.rb
83
83
  - lib/slack/rpc/command.rb
84
- - lib/slack/rpc/invoker.rb
84
+ - lib/slack/rpc/connection.rb
85
+ - lib/slack/rpc/response.rb
85
86
  - lib/slack/version.rb
86
87
  - slack.gemspec
87
88
  homepage: https://github.com/morou/slack-ruby-gem
@@ -1,51 +0,0 @@
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
-