Module: Ey::Core::Client::Shared
Instance Attribute Summary collapse
-
#authentication ⇒ Object
readonly
Returns the value of attribute authentication.
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#metadata ⇒ Object
deprecated
Deprecated.
will be removed in 3.x
- #require_argument(_params, *_requirements) ⇒ Object
- #require_argument!(_params, *_requirements) ⇒ Object
- #require_arguments(_params, *_requirements) ⇒ Object
-
#require_parameters(_params, *_requirements) ⇒ Object
strong parameter emulation.
- #setup(options) ⇒ Object
- #url_for(*args) ⇒ Object
Instance Attribute Details
#authentication ⇒ Object (readonly)
Returns the value of attribute authentication.
314 315 316 |
# File 'lib/ey-core/client.rb', line 314 def authentication @authentication end |
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
314 315 316 |
# File 'lib/ey-core/client.rb', line 314 def cache @cache end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
314 315 316 |
# File 'lib/ey-core/client.rb', line 314 def url @url end |
Instance Method Details
#metadata ⇒ Object
Deprecated.
will be removed in 3.x
417 418 419 |
# File 'lib/ey-core/client.rb', line 417 def services.get("core") end |
#require_argument(_params, *_requirements) ⇒ Object
392 393 394 395 396 397 398 399 |
# File 'lib/ey-core/client.rb', line 392 def require_argument(_params, *_requirements) params = Cistern::Hash.stringify_keys(_params) requirements = _requirements.map(&:to_s) values = params.values_at(*requirements) values.all?(&:nil?) && raise(ArgumentError.new("argument is missing or the value is empty: #{requirement}")) values.size == 1 ? values.first : values end |
#require_argument!(_params, *_requirements) ⇒ Object
401 402 403 404 405 406 407 408 409 |
# File 'lib/ey-core/client.rb', line 401 def require_argument!(_params, *_requirements) params = Cistern::Hash.stringify_keys(_params) requirements = _requirements.map(&:to_s) values = params.values_at(*requirements) values.all?(&:nil?) && raise(ArgumentError.new("argument is missing or the value is empty: #{requirement}")) requirements.each { |r| params.delete(r) } values.size == 1 ? values.first : values end |
#require_arguments(_params, *_requirements) ⇒ Object
379 380 381 382 383 384 385 386 387 388 389 390 |
# File 'lib/ey-core/client.rb', line 379 def require_arguments(_params, *_requirements) params = Cistern::Hash.stringify_keys(_params) requirements = _requirements.map(&:to_s) values = requirements.map do |requirement| if params[requirement].nil? raise ArgumentError, "argument is missing or the value is empty: #{requirement}" end params[requirement] end [params, *values] end |
#require_parameters(_params, *_requirements) ⇒ Object
strong parameter emulation
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
# File 'lib/ey-core/client.rb', line 360 def require_parameters(_params, *_requirements) params = Cistern::Hash.stringify_keys(_params) requirements = _requirements.map(&:to_s) requirements.each do |requirement| unless !params[requirement].nil? if self.class == Ey::Core::Client::Real raise ArgumentError, "param is missing or the value is empty: #{requirement}" else response( :status => 400, :body => "param is missing or the value is empty: #{requirement}") end end end values = params.values_at(*requirements) values.size == 1 ? values.first : values end |
#setup(options) ⇒ Object
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
# File 'lib/ey-core/client.rb', line 316 def setup() token_dotfile = begin if [:config_file] YAML.load_file([:config_file]) || {} # if the file is empty, yaml returns false else YAML.load_file(File.("~/.ey-core")) end rescue Errno::ENOENT {} end resolved_url = [:url] || ENV["CORE_URL"] || "https://api.engineyard.com/" @url = File.join(resolved_url, "/") # trailing slash # consistency # hash tag you're welcome @cache = if [:cache] == true Ey::Core::MemoryCache else [:cache] end @authentication = nil @token = if .has_key?(:token) && [:token].nil? @authentication = :none else [:token] || token_dotfile[@url] || token_dotfile[@url.gsub(/\/$/, "")] # matching with or without trailing slash end # For HMAC @auth_id = [:auth_id] @auth_key = [:auth_key] unless @authentication == :none if !@auth_id && !@auth_key && !@token raise "Missing token. Use Ey::Core::Client.new(token: mytoken) or add \"'#{@url}': mytoken\" to your ~/.ey-core file (see: https://cloud.engineyard.com/cli)" unless @token elsif [:token] || (@token && !@auth_id) # token was explicitly provided @authentication = :token else @authentication = :hmac @token = nil end end @logger = [:logger] || Logger.new(nil) end |
#url_for(*args) ⇒ Object
411 412 413 |
# File 'lib/ey-core/client.rb', line 411 def url_for(*args) File.join(@url.to_s, *args.map(&:to_s)) end |