module ThreeScale::Core

Constants

Invalid
NotFound
VERSION

Attributes

password[RW]
url[W]
username[RW]

Public Instance Methods

faraday() click to toggle source
# File lib/3scale/core.rb, line 37
def faraday
  return @faraday if @faraday

  url = self.url
  @faraday = Faraday.new(url: url) do |f|
    f.adapter :net_http_persistent
  end
  @faraday.headers = {
    'User-Agent' => "pisoni v#{ThreeScale::Core::VERSION}",
    'Accept' => 'application/json',
    'Content-Type' => 'application/json'
  }

  if @username.nil? && @password.nil?
    # even though the url may contain the user info, turns out Faraday is
    # not really picking it up, so must fill it in if present in the URL and
    # no previous setting was done (ie. assigning username or password).
    uri = URI.parse url
    @username = uri.user
    @password = uri.password
  end

  @faraday.basic_auth(@username, @password) if @username || @password
  @faraday
end
url() click to toggle source
# File lib/3scale/core.rb, line 63
def url
  ENV['THREESCALE_CORE_INTERNAL_API'] || @url ||
    raise(UnknownAPIEndpoint)
end