Sha256: 1fc41fe7744136a8a4b2ca07084a401a7781567d6da057194e7f4e1e5f193875

Contents?: true

Size: 1.42 KB

Versions: 3

Compression:

Stored size: 1.42 KB

Contents

module ApigeeCli
  class ResourceFile < Base

    RESOURCE_FILE_KEY = 'resourceFile'
    DEFAULT_RESOURCE_TYPE = 'jsc'

    def base_url
      "https://api.enterprise.apigee.com/v1/organizations/#{org}/resourcefiles"
    end

    def all
      response = get(base_url)
      if response.status != 200
        response_error(response)
      else
        JSON.parse(response.body)
      end
    end

    def read(name, resource_type)
      url = [base_url,resource_type,name].join('/')
      response = get(url)
      if response.status == 404
        nil
      elsif response.status != 200
        response_error(response)
      else
        response.body
      end
    end

    def create(name, resource_type, file)
      url = "#{base_url}?name=#{name}&type=#{resource_type}"
      response = upload_file(url, file)
      if response.status != 201
        response_error(response)
      else
        JSON.parse(response.body)
      end
    end

    def remove(name, resource_type)
      url = [base_url,resource_type,name].join('/')
      response = delete(url)
      if response.status != 200
        response_error(response)
      else
        JSON.parse(response.body)
      end
    end

    def upload(name, resource_type, file)
      if read(name, resource_type)
        result = :overwritten
        remove(name, resource_type)
      else
        result = :new_file
      end
      create(name, resource_type, file)
      result
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
apigee_cli-0.0.3 lib/apigee_cli/resource_file.rb
apigee_cli-0.0.2 lib/apigee_cli/resource_file.rb
apigee_cli-0.0.1 lib/apigee_cli/resource_file.rb