Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ spec/reports
test/tmp
test/version_tmp
tmp
.idea
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source 'https://rubygems.org'

gemspec
4 changes: 2 additions & 2 deletions kickbox.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ Gem::Specification.new do |gem|

gem.files = Dir["lib/**/*"]

gem.add_dependency "faraday", "~> 1.0"
gem.add_dependency "json", ">= 1.8"
gem.add_dependency "faraday", "~> 2.0"
gem.add_dependency "json", "~> 2.0"
end
2 changes: 1 addition & 1 deletion lib/kickbox/api/kickbox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def initialize(client)
#
# email - Email address to verify
def verify(email, options = {})
body = options.fetch("query", {})
body = options.fetch("query", {})
timeout = options.fetch("timeout", 6000)

email = CGI::escape(email)
Expand Down
2 changes: 1 addition & 1 deletion lib/kickbox/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(auth = {}, options = {})
end

#
def kickbox()
def kickbox
Kickbox::Api::Kickbox.new(@http_client)
end

Expand Down
33 changes: 11 additions & 22 deletions lib/kickbox/http_client/auth_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,29 @@ def initialize(app, auth = {}, options = {})
end

def call(env)
if [email protected]?
auth = get_auth_type
flag = false

if auth == HTTP_HEADER
env = http_header(env)
flag = true
end

if !flag
raise StandardError.new "Unable to calculate authorization method. Please check"
end
else
raise StandardError.new "Server requires authentication to proceed further. Please check"
raise StandardError.new("Server requires authentication to proceed further. Please check") if @auth.empty?

if get_auth_type == HTTP_HEADER
env = http_header(env)
end

@app.call(env)
end

# Calculating the Authentication Type
def get_auth_type()

def get_auth_type
if @auth.has_key?(:http_header)
return HTTP_HEADER
HTTP_HEADER
else
raise StandardError.new("Unable to calculate authorization method. Please check")
end

return -1
end

# Authorization with HTTP header
def http_header(env)
env[:request_headers]["Authorization"] = "token #{@auth[:http_header]}"

return env
env
end

def query_params(url)
Expand All @@ -60,11 +49,11 @@ def query_params(url)
end

def merge_query(env, query)
query = query.update query_params(env[:url])
query = query.update(query_params(env[:url]))

env[:url].query = Faraday::Utils.build_query(query)

return env
env
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/kickbox/http_client/error_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Kickbox

module HttpClient

# ErrorHanlder takes care of selecting the error message from response body
# ErrorHandler takes care of selecting the error message from response body
class ErrorHandler < Faraday::Middleware

def initialize(app)
Expand Down
8 changes: 3 additions & 5 deletions lib/kickbox/http_client/response_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ class ResponseHandler

def self.get_body(env)
type = env.response_headers["content-type"] || ''
body = env.body

# Response body is in JSON
if type.include?("json")
body = JSON.parse body
end
type.include?("json") ?
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Syntax error here!!!

return JSON.parse(body) :
return env.body

return body
end

end
Expand Down