Sha256: 9b22edf6ba55a49477d53c66bc45de194e715f507fa450ce5e03faffebffbc2a

Contents?: true

Size: 1.95 KB

Versions: 79

Compression:

Stored size: 1.95 KB

Contents

module Fog
  module Compute
    class Linode
      class Real

        # Get available plans
        #
        # ==== Parameters
        # * linodeplanId<~Integer>: id to limit results to
        #
        # ==== Returns
        # * response<~Excon::Response>:
        #   * body<~Array>:
        # TODO: docs
        def avail_linodeplans(linodeplan_id = nil)
          options = {}
          if linodeplan_id
            options.merge!(:planId => linodeplan_id)
          end
          result = request(
            :expects  => 200,
            :method   => 'GET',
            :query    => { :api_action => 'avail.linodeplans' }.merge!(options)
          )

          #hack for plans not filtering by id like they should above, remove when they fix it.
          result.body["DATA"] = result.body["DATA"].select { |item| item['PLANID'] == linodeplan_id } if linodeplan_id
          result
        end

      end

      class Mock
        def avail_linodeplans(linodeplan_id = nil)
          response = Excon::Response.new
          response.status = 200
          body = {
            "ERRORARRAY" => [],
            "ACTION" => "avail.linodeplans"
          }
          if linodeplan_id
            mock_plan = create_mock_linodeplan(linodeplan_id)
            response.body = body.merge("DATA" => [mock_plan])
          else
            mock_plans = []
            10.times do
              plan_id = rand(1..99)
              mock_plans << create_mock_linodeplan(plan_id)
            end
            response.body = body.merge("DATA" => mock_plans)
          end
          response
        end

        private

        def create_mock_linodeplan(linodeplan_id)
          { "PRICE" => 19.95, "RAM" => 512, "XFER" => 200,
            "PLANID" => linodeplan_id, "LABEL" => "Linode #{linodeplan_id}",
            "DISK" => 20,
            "AVAIL" => {
              "3"=>48, "2"=>207, "7"=>161, "6"=>143, "4"=>108, "8"=>60
            }
          }
        end
      end
    end
  end
end

Version data entries

79 entries across 79 versions & 12 rubygems

Version Path
fog-1.22.0 lib/fog/linode/requests/compute/avail_linodeplans.rb
fog-1.21.0 lib/fog/linode/requests/compute/avail_linodeplans.rb
fog-maestrodev-1.20.0.20140305101839 lib/fog/linode/requests/compute/avail_linodeplans.rb
fog-maestrodev-1.20.0.20140305101305 lib/fog/linode/requests/compute/avail_linodeplans.rb
fog-maestrodev-1.19.0.20140212012611 lib/fog/linode/requests/compute/avail_linodeplans.rb
fog-1.20.0 lib/fog/linode/requests/compute/avail_linodeplans.rb
fog-maestrodev-1.19.0.20140110004459 lib/fog/linode/requests/compute/avail_linodeplans.rb
fog-maestrodev-1.19.0.20140110003812 lib/fog/linode/requests/compute/avail_linodeplans.rb
fog-maestrodev-1.19.0.20140109202555 lib/fog/linode/requests/compute/avail_linodeplans.rb
fog-maestrodev-1.19.0.20140107192102 lib/fog/linode/requests/compute/avail_linodeplans.rb
fog-maestrodev-1.19.0.20140107142106 lib/fog/linode/requests/compute/avail_linodeplans.rb
fog-maestrodev-1.19.0.20131219203941 lib/fog/linode/requests/compute/avail_linodeplans.rb
fog-maestrodev-1.18.0.20131219193542 lib/fog/linode/requests/compute/avail_linodeplans.rb
fog-1.19.0 lib/fog/linode/requests/compute/avail_linodeplans.rb
fog-maestrodev-1.18.0.20131219033443 lib/fog/linode/requests/compute/avail_linodeplans.rb
fog-maestrodev-1.18.0.20131219032002 lib/fog/linode/requests/compute/avail_linodeplans.rb
fog-maestrodev-1.18.0.20131219030716 lib/fog/linode/requests/compute/avail_linodeplans.rb
fog-maestrodev-1.18.0.20131219022322 lib/fog/linode/requests/compute/avail_linodeplans.rb
fog-maestrodev-1.18.0.20131218202447 lib/fog/linode/requests/compute/avail_linodeplans.rb
fog-maestrodev-1.18.0.20131209091424 lib/fog/linode/requests/compute/avail_linodeplans.rb