Skip to content

Commit

Permalink
Merge pull request #2 from jujulisan/development
Browse files Browse the repository at this point in the history
Refactor api response
  • Loading branch information
jujulisan authored Aug 30, 2017
2 parents c64ad03 + bb90bdc commit 24ba88a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
6 changes: 3 additions & 3 deletions klickmail_api.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ Gem::Specification.new do |spec|
spec.name = "klickmail_api"
spec.version = KlickmailApi::VERSION
spec.authors = ["Juliane Lima", "Rafael Simão"]
spec.email = ["juliane.lima@klicksite.com.br", "rafael.costa@klicksite.com.br"]
spec.email = ["juliane.lima@klickpages.com.br", "rafael.costa@klickpages.com.br"]

spec.summary = %q{Wrapper for integration with Klickmail.}
spec.description = %q{See https://github.com/jujulisan/klickmail_api for more information.}
spec.description = %q{See https://github.com/ignicaodigitalbr/klickmail_api for more information.}
spec.homepage = "https://github.com/ignicaodigitalbr/klickmail_api"
spec.license = "MIT"

Expand All @@ -23,7 +23,7 @@ Gem::Specification.new do |spec|

spec.add_development_dependency 'bundler', '~> 1.15'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'webmock'
spec.add_development_dependency 'webmock'
spec.add_development_dependency 'rspec'
spec.add_runtime_dependency 'httparty', '~> 0.15'
spec.required_ruby_version = '>=2.0.0'
Expand Down
7 changes: 1 addition & 6 deletions lib/klickmail_api/connector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,8 @@ def login(username, password)
data = { username: username, password: password }

response = http_request('account/login', 'POST', data)

if valid_login?(response)
set_session(response['result'])
return true
end

return false
return response['result']
end

private
Expand Down
18 changes: 10 additions & 8 deletions spec/klickmail_api/connector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,35 @@
.to_return(status: status, body: response, headers: header)
end

context 'when the request is valid' do
let(:response) do
context 'when the request is valid' do
let(:response) do
"<?xml version='1.0' encoding='utf-8'?>
<result>
<sessid>sessid</sessid>
<session_name>sessionname</session_name>
</result>"
end
let(:status) { 200 }

let(:result) { {"sessid"=>"sessid", "session_name"=>"sessionname"} }

subject { connector.login('username', 'password') }

it { is_expected.to be(true) }
it { is_expected.to eq(result) }
end

context 'when the request is invalid' do
let(:response) do
context 'when the request is invalid' do
let(:response) do
"<?xml version='1.0' encoding='utf-8'?>
<result>O nome de usuário ou a senha são inválidos.</result>"
end
let(:status) { 401 }
let(:result) { 'O nome de usuário ou a senha são inválidos.' }

subject { connector.login('wrong_username', 'wrong_password') }

it { is_expected.to be(false) }
it { is_expected.to eq(result) }
end
end
end


0 comments on commit 24ba88a

Please sign in to comment.