lib/ecoportal/api/common/graphql/http_client.rb in ecoportal-api-graphql-0.4.2 vs lib/ecoportal/api/common/graphql/http_client.rb in ecoportal-api-graphql-0.4.3
- old
+ new
@@ -7,20 +7,20 @@
def base_url(host)
"#{protocol(host)}://#{host}"
end
def protocol(host)
- host.match(/^localhost|^127\.0\.0\.1/)? "http" : "https"
+ host.match(/^localhost|^127\.0\.0\.1/)? 'http' : 'https'
end
end
attr_reader :host, :version
def initialize(
api_key: nil,
- version: "v1",
- host: "live.ecoportal.com",
+ version: nil,
+ host: 'live.ecoportal.com',
logger: ::Logger.new(IO::NULL),
deep_logging: false
)
super(
api_key: api_key,
@@ -41,16 +41,16 @@
def base_request
@base_request ||=
case @version
when NilClass
HTTP.accept(:json)
- when "v2"
- HTTP.headers("X-ECOPORTAL-API-KEY" => key_token).accept(:json)
- when "graphql"
- HTTP.headers("Authorization" => "Bearer #{key_token}").accept(:json)
+ when 'v2'
+ HTTP.headers('X-ECOPORTAL-API-KEY' => key_token).accept(:json)
+ when 'graphql'
+ HTTP.headers('Authorization' => "Bearer #{key_token}").accept(:json)
else
- HTTP.headers("X-ApiKey" => key_token).accept(:json)
+ HTTP.headers('X-ApiKey' => key_token).accept(:json)
end
end
# Full URl builder of the request
# @param path [String] the tail that completes the url of the request.
@@ -77,13 +77,13 @@
@base_url_api ||= "#{base_url}/api/#{version}"
end
def key_token
if @api_key.nil? || @api_key.match(/\A\W*\z/)
- if (version == "v0") && (key = ENV['ORG_INT_KEY'])
+ if (version == 'v0') && (key = ENV['ORG_INT_KEY'])
key
- else
- puts "Api-key missing!"
+ elsif !version.nil?
+ puts 'Api-key missing!'
end
else
@api_key
end
end