diff --git a/lib/slack-api-wrapper.rb b/lib/slack-api-wrapper.rb index 1aa0b26..46e7b25 100644 --- a/lib/slack-api-wrapper.rb +++ b/lib/slack-api-wrapper.rb @@ -22,6 +22,7 @@ module Slack # Parse response. You probably shouldn't be calling this directly. # This takes responses from the server and parses them. # It also checks for errors and raises exceptions with the appropriate messages. + # # @param [Net::HTTPResponse] response # @param [Boolean] raw if return raw data # @raise [SlackError] diff --git a/lib/slack/request.rb b/lib/slack/request.rb index 7543281..e887f6b 100644 --- a/lib/slack/request.rb +++ b/lib/slack/request.rb @@ -1,18 +1,6 @@ module Slack + # Methods to do http requests module Request - # Removes nil params - # - # @param [Hash] params - # API call arguments - # @return [Hash] - def clean_params(params) - r = {} - params.each do |k, v| - r[k] = v.to_s unless v.nil? - end - r - end - # Convert params to query string # # @param [Hash] params @@ -41,5 +29,28 @@ def do_http(uri, request) raise Slack::Error, 'SSL error connecting to Slack.' end end + + def do_http_with_body(uri, request, body) # :nodoc: + unless body.nil? + if body.is_a?(Hash) + request.set_form_data clean_params(body) + else + s = body.to_s + request['Content-Length'] = s.length + request.body = s + end + end + do_http(uri, request) + end + + private + + def clean_params(params) # :nodoc: + r = {} + params.each do |k, v| + r[k] = v.to_s unless v.nil? + end + r + end end end diff --git a/lib/slack/session.rb b/lib/slack/session.rb index 7ed4358..97e8f18 100644 --- a/lib/slack/session.rb +++ b/lib/slack/session.rb @@ -21,19 +21,6 @@ def do_get(path, params = nil) # :nodoc: do_http(uri, Net::HTTP::Get.new(uri.request_uri)) end - def do_http_with_body(uri, request, body) # :nodoc: - unless body.nil? - if body.is_a?(Hash) - request.set_form_data clean_params(body) - else - s = body.to_s - request['Content-Length'] = s.length - request.body = s - end - end - do_http(uri, request) - end - def do_post(path, params = nil, headers = nil) # :nodoc: headers ||= {} headers['Authorization'] = "Bearer #{@access_token}" diff --git a/slack-api-wrapper.gemspec b/slack-api-wrapper.gemspec index 7b69609..42a294b 100644 --- a/slack-api-wrapper.gemspec +++ b/slack-api-wrapper.gemspec @@ -24,6 +24,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'bundler', '~> 1.7' spec.add_development_dependency 'rake', '~> 10.0' spec.add_development_dependency 'rspec', '~> 3.2', '>= 3.2.0' + spec.add_development_dependency 'webmock', '~> 1.21', '>= 1.21.0' spec.add_development_dependency 'coveralls', '~>0.8.0' spec.add_development_dependency 'yard', '~> 0.8.7', '>= 0.8.0' end diff --git a/spec/slack/session_spec.rb b/spec/slack/session_spec.rb index 85367e2..d9195d8 100644 --- a/spec/slack/session_spec.rb +++ b/spec/slack/session_spec.rb @@ -11,14 +11,6 @@ describe "instance methods" do subject(:session) { Slack::Session.new('') } - - describe '#clean_params' do - let(:params) { { 'test_1' => 'test', 'test_2' => nil } } - it 'removes nil params' do - expect(session.clean_params(params)).to eq('test_1' => 'test') - end - end - describe '#make_query_string' do let(:params) { { 'test_1' => 'test', 'test_2' => 'test' } } it 'transform params to query string' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7bd47bc..c3b16d0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -9,6 +9,7 @@ require 'slack-api-wrapper' require 'bundler/setup' +require 'webmock/rspec' Bundler.require RSpec.configure do |config|