Sha256: 294ff8b153ae191abf29d8ea269f9bc2ee9f16ff4cfab2e0735c952ab1003f60

Contents?: true

Size: 1.99 KB

Versions: 17

Compression:

Stored size: 1.99 KB

Contents

require "multi_json"

require "cfoundry/baseclient"
require "cfoundry/uaaclient"

require "cfoundry/errors"

module CFoundry::V2
  class Base < CFoundry::BaseClient
    include BaseClientMethods

    def resource_match(fingerprints)
      put("v2", "resource_match", :content => :json, :accept => :json, :payload => fingerprints)
    end

    def upload_app(guid, zipfile = nil, resources = [])
      payload = {}
      payload[:resources] = MultiJson.dump(resources)

      if zipfile
        payload[:application] =
          UploadIO.new(
            if zipfile.is_a? File
              zipfile
            elsif zipfile.is_a? String
              File.new(zipfile, "rb")
            end,
            "application/zip")
      end

      put("v2", "apps", guid, "bits", :payload => payload)
    rescue EOFError
      retry
    end

    def files(guid, instance, *path)
      get("v2", "apps", guid, "instances", instance, "files", *path)
    end
    alias :file :files

    def stream_file(guid, instance, *path, &blk)
      path_and_options = path + [{:return_response => true, :follow_redirects => false}]
      redirect = get("v2", "apps", guid, "instances", instance, "files", *path_and_options)

      if location = redirect[:headers]["location"]
        stream_url(location + "&tail", &blk)
      else
        yield redirect[:body]
      end
    end

    def instances(guid)
      get("v2", "apps", guid, "instances", :accept => :json)
    end

    def crashes(guid)
      get("v2", "apps", guid, "crashes", :accept => :json)
    end

    def stats(guid)
      get("v2", "apps", guid, "stats", :accept => :json)
    end

    def update_app(guid, diff)
      put("v2", "apps", guid,
          :content => :json,
          :payload => diff,
          :return_response => true)
    end

    def all_pages(paginated)
      payload = paginated[:resources]

      while next_page = paginated[:next_url]
        paginated = get(next_page, :accept => :json)
        payload += paginated[:resources]
      end

      payload
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
cfoundry-4.3.2.rc1 lib/cfoundry/v2/base.rb
cfoundry-4.3.1 lib/cfoundry/v2/base.rb
cfoundry-4.3.0 lib/cfoundry/v2/base.rb
cfoundry-4.2.0.rc lib/cfoundry/v2/base.rb
cfoundry-4.1.0 lib/cfoundry/v2/base.rb
cfoundry-4.0.4.rc2 lib/cfoundry/v2/base.rb
cfoundry-4.0.4.rc1 lib/cfoundry/v2/base.rb
cfoundry-4.0.3 lib/cfoundry/v2/base.rb
cfoundry-4.0.2.rc5 lib/cfoundry/v2/base.rb
cfoundry-4.0.2.rc4 lib/cfoundry/v2/base.rb
cfoundry-4.0.2.rc3 lib/cfoundry/v2/base.rb
cfoundry-4.0.2.rc2 lib/cfoundry/v2/base.rb
cfoundry-4.0.2.rc1 lib/cfoundry/v2/base.rb
cfoundry-4.0.1 lib/cfoundry/v2/base.rb
cfoundry-4.0.0 lib/cfoundry/v2/base.rb
cfoundry-3.0.1 lib/cfoundry/v2/base.rb
cfoundry-3.0.0 lib/cfoundry/v2/base.rb