slack-api-wrapper 0.0.6 → 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.
@@ -4,25 +4,27 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'slack/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "slack-api-wrapper"
7
+ spec.name = 'slack-api-wrapper'
8
8
  spec.version = Slack::VERSION
9
- spec.authors = ["Gustavo Bazan"]
10
- spec.email = ["contacto@gustavobazan.com"]
11
- spec.summary = "Slack API Wrapper"
9
+ spec.authors = ['Gustavo Bazan']
10
+ spec.email = ['contacto@gustavobazan.com']
11
+ spec.summary = 'Slack API Wrapper'
12
12
  spec.description = <<-EOF
13
13
  A library that provides a plain function-call interface to the
14
14
  Slack API web endpoints.
15
15
  EOF
16
- spec.homepage = "https://github.com/gssbzn/slack-api-wrapper"
17
- spec.license = "MIT"
16
+ spec.homepage = 'https://github.com/gssbzn/slack-api-wrapper'
17
+ spec.license = 'MIT'
18
18
 
19
19
  spec.files = `git ls-files -z`.split("\x0")
20
20
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
21
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
22
- spec.require_paths = ["lib"]
22
+ spec.require_paths = ['lib']
23
23
 
24
- spec.add_development_dependency "bundler", "~> 1.6"
25
- spec.add_development_dependency "rake", '~> 0'
26
- spec.add_development_dependency "rspec", '~> 3.2', '>= 3.2.0'
27
- spec.add_development_dependency "yard", '~> 0.8.7', '>= 0.8.0'
24
+ spec.add_development_dependency 'bundler', '~> 1.7'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rspec', '~> 3.2', '>= 3.2.0'
27
+ spec.add_development_dependency 'webmock', '~> 1.21', '>= 1.21.0'
28
+ spec.add_development_dependency 'coveralls', '~>0.8.0'
29
+ spec.add_development_dependency 'yard', '~> 0.8.7', '>= 0.8.0'
28
30
  end
@@ -2,11 +2,10 @@ require 'spec_helper'
2
2
 
3
3
  describe Slack::Client do
4
4
  it 'Initialize' do
5
- client = Slack::Client.new("")
5
+ client = Slack::Client.new('')
6
6
  expect(client).not_to be nil
7
7
  end
8
8
  it 'Validates token is string' do
9
- expect{Slack::Client.new(1)}.to raise_error(ArgumentError)
9
+ expect { Slack::Client.new(1) }.to raise_error(ArgumentError)
10
10
  end
11
-
12
11
  end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Slack::Session do
4
+ it 'Initialize' do
5
+ session = Slack::Session.new('')
6
+ expect(session).not_to be nil
7
+ end
8
+ it 'Validates token is string' do
9
+ expect { Slack::Session.new(1) }.to raise_error(ArgumentError)
10
+ end
11
+
12
+ describe "instance methods" do
13
+ subject(:session) { Slack::Session.new('') }
14
+ describe '#make_query_string' do
15
+ let(:params) { { 'test_1' => 'test', 'test_2' => 'test' } }
16
+ it 'transform params to query string' do
17
+ expect(session.make_query_string(params)).to eq('test_1=test&test_2=test')
18
+ end
19
+ end
20
+ end
21
+ end
data/spec/slack_spec.rb CHANGED
@@ -8,23 +8,4 @@ describe Slack do
8
8
  it 'has web server domain' do
9
9
  expect(Slack::WEB_SERVER).to eq('slack.com')
10
10
  end
11
-
12
- it 'has api uri' do
13
- expect(Slack::API_SERVER).to eq('slack.com/api')
14
- end
15
-
16
- describe '::clean_params' do
17
- let(:params){ {"test_1"=>"test", "test_2" => nil} }
18
- it 'removes nil params' do
19
- expect(Slack::clean_params(params)).to eq({"test_1"=>"test"})
20
- end
21
- end
22
-
23
- describe '::make_query_string' do
24
- let(:params){ {"test_1"=>"test", "test_2" => "test"} }
25
- it 'transform params to query string' do
26
- expect(Slack::make_query_string(params)).to eq("test_1=test&test_2=test")
27
- end
28
- end
29
-
30
11
  end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,83 @@
1
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
1
+ require 'simplecov'
2
+ require 'coveralls'
3
+
4
+ SimpleCov.formatter = Coveralls::SimpleCov::Formatter
5
+ SimpleCov.start do
6
+ add_filter 'spec/support'
7
+ end
2
8
 
3
9
  require 'slack-api-wrapper'
10
+
11
+ require 'bundler/setup'
12
+ require 'webmock/rspec'
13
+ Bundler.require
14
+
15
+ RSpec.configure do |config|
16
+ # rspec-expectations config goes here. You can use an alternate
17
+ # assertion/expectation library such as wrong or the stdlib/minitest
18
+ # assertions if you prefer.
19
+ config.expect_with :rspec do |expectations|
20
+ # This option will default to `true` in RSpec 4. It makes the `description`
21
+ # and `failure_message` of custom matchers include text for helper methods
22
+ # defined using `chain`, e.g.:
23
+ # be_bigger_than(2).and_smaller_than(4).description
24
+ # # => "be bigger than 2 and smaller than 4"
25
+ # ...rather than:
26
+ # # => "be bigger than 2"
27
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
28
+ end
29
+
30
+ # rspec-mocks config goes here. You can use an alternate test double
31
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
32
+ config.mock_with :rspec do |mocks|
33
+ # Prevents you from mocking or stubbing a method that does not exist on
34
+ # a real object. This is generally recommended, and will default to
35
+ # `true` in RSpec 4.
36
+ mocks.verify_partial_doubles = true
37
+ end
38
+
39
+ # These two settings work together to allow you to limit a spec run
40
+ # to individual examples or groups you care about by tagging them with
41
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
42
+ # get run.
43
+ # config.filter_run :focus
44
+ # config.run_all_when_everything_filtered = true
45
+
46
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
47
+ # For more details, see:
48
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
49
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
50
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
51
+ # config.disable_monkey_patching!
52
+
53
+ # This setting enables warnings. It's recommended, but in some cases may
54
+ # be too noisy due to issues in dependencies.
55
+ config.warnings = true
56
+
57
+ # Many RSpec users commonly either run the entire suite or an individual
58
+ # file, and it's useful to allow more verbose output when running an
59
+ # individual spec file.
60
+ # if config.files_to_run.one?
61
+ # Use the documentation formatter for detailed output,
62
+ # unless a formatter has already been configured
63
+ # (e.g. via a command-line flag).
64
+ # config.default_formatter = 'doc'
65
+ # end
66
+
67
+ # Print the 10 slowest examples and example groups at the
68
+ # end of the spec run, to help surface which specs are running
69
+ # particularly slow.
70
+ # config.profile_examples = 10
71
+
72
+ # Run specs in random order to surface order dependencies. If you find an
73
+ # order dependency and want to debug it, you can fix the order by providing
74
+ # the seed, which is printed after each run.
75
+ # --seed 1234
76
+ config.order = :random
77
+
78
+ # Seed global randomization in this process using the `--seed` CLI option.
79
+ # Setting this allows you to use `--seed` to deterministically reproduce
80
+ # test failures related to randomization by passing the same `--seed` value
81
+ # as the one that triggered the failure.
82
+ Kernel.srand config.seed
83
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack-api-wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gustavo Bazan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-16 00:00:00.000000000 Z
11
+ date: 2015-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.6'
19
+ version: '1.7'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.6'
26
+ version: '1.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '10.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -58,6 +58,40 @@ dependencies:
58
58
  - - ">="
59
59
  - !ruby/object:Gem::Version
60
60
  version: 3.2.0
61
+ - !ruby/object:Gem::Dependency
62
+ name: webmock
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.21'
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: 1.21.0
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '1.21'
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 1.21.0
81
+ - !ruby/object:Gem::Dependency
82
+ name: coveralls
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: 0.8.0
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: 0.8.0
61
95
  - !ruby/object:Gem::Dependency
62
96
  name: yard
63
97
  requirement: !ruby/object:Gem::Requirement
@@ -87,19 +121,23 @@ executables: []
87
121
  extensions: []
88
122
  extra_rdoc_files: []
89
123
  files:
124
+ - ".codeclimate.yml"
125
+ - ".coveralls.yml"
90
126
  - ".gitignore"
91
127
  - ".rspec"
128
+ - ".simplecov"
92
129
  - ".travis.yml"
130
+ - ".yardopts"
131
+ - CHANGELOG.md
132
+ - CODE_OF_CONDUCT.md
93
133
  - Gemfile
94
- - LICENSE.txt
134
+ - MIT-LICENSE
95
135
  - README.md
96
136
  - Rakefile
97
137
  - lib/slack-api-wrapper.rb
98
138
  - lib/slack/client.rb
99
139
  - lib/slack/error.rb
100
- - lib/slack/oauth2.rb
101
- - lib/slack/oauth2/flow.rb
102
- - lib/slack/oauth2/flow_base.rb
140
+ - lib/slack/request.rb
103
141
  - lib/slack/session.rb
104
142
  - lib/slack/version.rb
105
143
  - lib/slack/web.rb
@@ -111,15 +149,15 @@ files:
111
149
  - lib/slack/web/files.rb
112
150
  - lib/slack/web/groups.rb
113
151
  - lib/slack/web/im.rb
152
+ - lib/slack/web/pins.rb
153
+ - lib/slack/web/reactions.rb
114
154
  - lib/slack/web/search.rb
115
155
  - lib/slack/web/stars.rb
116
156
  - lib/slack/web/team.rb
117
157
  - lib/slack/web/users.rb
118
158
  - slack-api-wrapper.gemspec
119
159
  - spec/slack/client_spec.rb
120
- - spec/slack/oauth2/flow_base_spec.rb
121
- - spec/slack/oauth2/flow_spec.rb
122
- - spec/slack/oauth2_spec.rb
160
+ - spec/slack/session_spec.rb
123
161
  - spec/slack_spec.rb
124
162
  - spec/spec_helper.rb
125
163
  homepage: https://github.com/gssbzn/slack-api-wrapper
@@ -148,9 +186,7 @@ specification_version: 4
148
186
  summary: Slack API Wrapper
149
187
  test_files:
150
188
  - spec/slack/client_spec.rb
151
- - spec/slack/oauth2/flow_base_spec.rb
152
- - spec/slack/oauth2/flow_spec.rb
153
- - spec/slack/oauth2_spec.rb
189
+ - spec/slack/session_spec.rb
154
190
  - spec/slack_spec.rb
155
191
  - spec/spec_helper.rb
156
192
  has_rdoc:
data/lib/slack/oauth2.rb DELETED
@@ -1,10 +0,0 @@
1
- # Copyright (c) 2015 Gustavo Bazan
2
- # MIT License
3
-
4
- require_relative 'oauth2/flow_base'
5
- require_relative 'oauth2/flow'
6
- module Slack
7
- # Oauth2 authentication
8
- module Oauth2
9
- end
10
- end
@@ -1,165 +0,0 @@
1
- # Copyright (c) 2015 Gustavo Bazan
2
- # MIT License
3
-
4
- require 'securerandom'
5
-
6
- require_relative 'flow_base'
7
-
8
- module Slack
9
- module Oauth2
10
- # The standard OAuth 2 authorization helper.
11
- class Flow < FlowBase
12
-
13
- # @param [String] consumer_key
14
- # Your Slack API app's "app key"
15
- # @param [String] consumer_secret
16
- # Your Slack API app's "app secret"
17
- # @param [String] redirect_uri
18
- # The URI that the Slack server will redirect the user to after the user
19
- # finishes authorizing your app. This URI must be HTTPs-based and pre-registered with
20
- # the Slack servers.
21
- # @param [Hash] session
22
- # represents the current web app session (will be used to save the CSRF token)
23
- # @param [Object] csrf_token_key
24
- # The key to use when storing the CSRF token in the session (for example,
25
- # :slack_auth_csrf_token)
26
- def initialize(consumer_key, consumer_secret, redirect_uri, scope, team, session, csrf_token_session_key)
27
- super(consumer_key, consumer_secret, scope, team)
28
- unless redirect_uri.is_a?(String)
29
- raise ArgumentError, "redirect_uri must be a String, got #{consumer_secret.inspect}"
30
- end
31
- @redirect_uri = redirect_uri
32
- @session = session
33
- @csrf_token_session_key = csrf_token_session_key
34
- end
35
-
36
- # Starts the OAuth 2 authorizaton process, which involves redirecting the user to
37
- # the returned "authorization URL" (a URL on the Slack website). When the user then
38
- # either approves or denies your app access, Slack will redirect them to the
39
- # redirect_uri you provided to the constructor, at which point you should call finish()
40
- # to complete the process.
41
- #
42
- # This function will also save a CSRF token to the session and csrf_token_session_key
43
- # you provided to the constructor. This CSRF token will be checked on finish() to prevent
44
- # request forgery.
45
- #
46
- # @param [String] url_state
47
- # Any data you would like to keep in the URL through the authorization
48
- # process. This exact value will be returned to you by finish().
49
- #
50
- # @return Returns the URL to redirect the user to.
51
- def start(url_state=nil)
52
- unless url_state.nil? or url_state.is_a?(String)
53
- raise ArgumentError, "url_state must be a String"
54
- end
55
-
56
- csrf_token = SecureRandom.base64(16)
57
- state = csrf_token
58
- unless url_state.nil?
59
- state += "|" + url_state
60
- end
61
- @session[@csrf_token_session_key] = csrf_token
62
- _get_authorize_url(@redirect_uri, state)
63
- end
64
-
65
- # Call this after the user has visited the authorize URL (see: start()), approved your app,
66
- # and was redirected to your redirect URI.
67
- #
68
- # @param [Hash] query_params
69
- # The query params on the GET request to your redirect URI.
70
- #
71
- # @return Returns a tuple of (access_token, scope, url_state). access_token can be used to
72
- # construct a SlackClient. scpe is the Slack scope the user that jsut approved
73
- # your app. url_state is the value you originally passed in to start().
74
- #
75
- # @raise [BadRequestError]
76
- # @raise [BadStateError]
77
- # @raise [CsrfError]
78
- # @raise [NotApprovedError]
79
- # @raise [ProviderError]
80
- def finish(query_params)
81
- csrf_token_from_session = @session[@csrf_token_session_key]
82
-
83
- # Check well-formedness of request.
84
-
85
- state = query_params['state']
86
- if state.nil?
87
- raise BadRequestError.new("Missing query parameter 'state'.")
88
- end
89
- code = query_params['code']
90
-
91
- error = query_params['error']
92
-
93
- unless error.nil? || code.nil?
94
- raise BadRequestError.new("Query parameters 'code' and 'error' are both set;" +
95
- " only one must be set.")
96
- end
97
- if error.nil? && code.nil?
98
- raise BadRequestError.new("Neither query parameter 'code' or 'error' is set.")
99
- end
100
-
101
- # Check CSRF token
102
-
103
- if csrf_token_from_session.nil?
104
- raise BadStateError.new("Missing CSRF token in session.");
105
- end
106
- unless csrf_token_from_session.length > 20
107
- raise RuntimeError.new("CSRF token unexpectedly short: #{csrf_token_from_session.inspect}")
108
- end
109
-
110
- split_pos = state.index('|')
111
- if split_pos.nil?
112
- given_csrf_token = state
113
- url_state = nil
114
- else
115
- given_csrf_token, url_state = state.split('|', 2)
116
- end
117
- unless Slack::safe_string_equals(csrf_token_from_session, given_csrf_token)
118
- raise CsrfError.new("Expected #{csrf_token_from_session.inspect}, " +
119
- "got #{given_csrf_token.inspect}.")
120
- end
121
- @session.delete(@csrf_token_session_key)
122
-
123
- # Check for error identifier
124
-
125
- unless error.nil?
126
- if error == 'access_denied'
127
- # The user clicked "Deny"
128
- raise NotApprovedError.new("No additional description from Slack.")
129
- else
130
- raise ProviderError.new(error)
131
- end
132
- end
133
-
134
- # If everything went ok, make the network call to get an access token.
135
-
136
- access_token, scope = _finish(code, @redirect_uri)
137
- return access_token, scope, url_state
138
- end
139
-
140
- # Thrown if the redirect URL was missing parameters or if the given parameters were not valid.
141
- #
142
- # The recommended action is to show an HTTP 400 error page.
143
- class BadRequestError < Exception; end
144
-
145
- # Thrown if all the parameters are correct, but there's no CSRF token in the session. This
146
- # probably means that the session expired.
147
- #
148
- # The recommended action is to redirect the user's browser to try the approval process again.
149
- class BadStateError < Exception; end
150
-
151
- # The user chose not to approve your app.
152
- class NotApprovedError < Exception; end
153
-
154
- # Thrown if the given 'state' parameter doesn't contain the CSRF token from the user's session.
155
- # This is blocked to prevent CSRF attacks.
156
- #
157
- # The recommended action is to respond with an HTTP 403 error page.
158
- class CsrfError < Exception; end
159
-
160
- # Slack redirected to your redirect URI with some unexpected error identifier and error
161
- # message.
162
- class ProviderError < Exception; end
163
- end
164
- end
165
- end