Module: Miasma

Defined in:
lib/miasma.rb,
lib/miasma/error.rb,
lib/miasma/types.rb,
lib/miasma/utils.rb,
lib/miasma/models.rb,
lib/miasma/version.rb,
lib/miasma/types/api.rb,
lib/miasma/types/data.rb,
lib/miasma/utils/lazy.rb,
lib/miasma/types/model.rb,
lib/miasma/utils/smash.rb,
lib/miasma/models/compute.rb,
lib/miasma/models/storage.rb,
lib/miasma/utils/immutable.rb,
lib/miasma/types/collection.rb,
lib/miasma/types/thin_model.rb,
lib/miasma/models/auto_scale.rb,
lib/miasma/utils/memoization.rb,
lib/miasma/models/storage/file.rb,
lib/miasma/utils/api_methoding.rb,
lib/miasma/models/load_balancer.rb,
lib/miasma/models/orchestration.rb,
lib/miasma/models/storage/files.rb,
lib/miasma/utils/animal_strings.rb,
lib/miasma/models/compute/server.rb,
lib/miasma/models/storage/bucket.rb,
lib/miasma/models/compute/servers.rb,
lib/miasma/models/storage/buckets.rb,
lib/miasma/models/auto_scale/group.rb,
lib/miasma/models/auto_scale/groups.rb,
lib/miasma/models/orchestration/event.rb,
lib/miasma/models/orchestration/stack.rb,
lib/miasma/models/orchestration/events.rb,
lib/miasma/models/orchestration/stacks.rb,
lib/miasma/models/load_balancer/balancer.rb,
lib/miasma/models/orchestration/resource.rb,
lib/miasma/models/load_balancer/balancers.rb,
lib/miasma/models/orchestration/resources.rb

Defined Under Namespace

Modules: Models, Types, Utils Classes: Error

Constant Summary collapse

VERSION =

current library version

Gem::Version.new('0.3.2')

Class Method Summary collapse

Class Method Details

.api(args = {}) ⇒ Object

Generate and API connection

Parameters:

  • args (Hash) (defaults to: {})

Options Hash (args):

  • :type (String, Symbol)

    API type (:compute, :dns, etc)

  • :provider (String, Symbol)

    Service provider

  • :credentials (Hash)

    Service provider credentials



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/miasma.rb', line 23

def self.api(args={})
  args = Utils::Smash.new(args)
  [:type, :provider].each do |key|
    unless(args[key])
      raise ArgumentError.new "Missing required api argument `#{key.inspect}`!"
    end
  end
  args[:type] = Utils.camel(args[:type].to_s).to_sym
  args[:provider] = Utils.camel(args[:provider].to_s).to_sym
  args[:credentials] ||= {}
  begin
    require "miasma/contrib/#{Utils.snake(args[:provider])}"
  rescue LoadError
    # just ignore
  end
  begin
    base_klass = Models.const_get(args[:type])
    if(base_klass)
      api_klass = base_klass.const_get(args[:provider])
      if(api_klass)
        api_klass.new(args[:credentials].to_smash)
      else
        raise Error.new "Failed to locate #{args[:type]} API for #{args[:provider].inspect}"
      end
    else
      raise Error.new "Failed to locate requested API type #{args[:type].inspect} for #{args[:provider].inspect}"
    end
  rescue NameError => e
    raise Error.new "Failed to load requested API type #{args[:type].inspect} (Reason: #{e.class} - #{e})"
  end
end