Skip to content
This repository has been archived by the owner on Jan 3, 2018. It is now read-only.

Commit

Permalink
More improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustavo Bazan committed Sep 27, 2015
1 parent fb26929 commit 8a1902e
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 34 deletions.
1 change: 1 addition & 0 deletions lib/slack-api-wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
37 changes: 24 additions & 13 deletions lib/slack/request.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
13 changes: 0 additions & 13 deletions lib/slack/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
1 change: 1 addition & 0 deletions slack-api-wrapper.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 0 additions & 8 deletions spec/slack/session_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
require 'slack-api-wrapper'

require 'bundler/setup'
require 'webmock/rspec'
Bundler.require

RSpec.configure do |config|
Expand Down

0 comments on commit 8a1902e

Please sign in to comment.