Class: ThatLanguage::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/that_language/client.rb,
lib/that_language/client/query.rb,
lib/that_language/client/config.rb,
lib/that_language/client/version.rb,
lib/that_language/client/detect_query.rb,
lib/that_language/client/details_query.rb,
lib/that_language/client/version_query.rb,
lib/that_language/client/language_query.rb,
lib/that_language/client/available_query.rb,
lib/that_language/client/language_code_query.rb

Defined Under Namespace

Classes: AvailableQuery, Config, DetailsQuery, DetectQuery, LanguageCodeQuery, LanguageQuery, Query, VersionQuery

Constant Summary collapse

VERSION =
"0.2.0"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host:) ⇒ Client

Returns a new instance of Client.



17
18
19
# File 'lib/that_language/client.rb', line 17

def initialize(host:)
  @host = host
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



15
16
17
# File 'lib/that_language/client.rb', line 15

def host
  @host
end

Class Method Details

.configObject



35
36
37
# File 'lib/that_language/client.rb', line 35

def self.config
  @config ||= Config.new
end

.configure {|config| ... } ⇒ Object

Yields:



39
40
41
# File 'lib/that_language/client.rb', line 39

def self.configure
  yield(config)
end

.currentObject



31
32
33
# File 'lib/that_language/client.rb', line 31

def self.current
  @current ||= Client.new(host: config.host)
end

Instance Method Details

#base_urlObject

host may be a bare "example.com", a "host:port", or a full base URL carrying a scheme. Anything without a scheme is assumed to be http, which is what this client always did; https is now expressible, and any real deployment will need it.



25
26
27
28
29
# File 'lib/that_language/client.rb', line 25

def base_url
  return host.sub(%r{/+\z}, "") if host.include?("://")

  "http://#{host}"
end