Ruby library for communicating with the packagecloud.io API.
- Get Package Contents
- Upload Package
- List Distributions
- View Repository
- View Repositories
- Create Repository
gem install packagecloud-ruby
Login to packagecloud.io and go to your Account Settings to see your API token.
Note that you should not use the email address associated with your packagecloud.io account when accessing the API. Please use your username on the site.
require 'packagecloud'
# Create a client using your username and API token
credentials = Packagecloud::Credentials.new("joedamato", "my_api_token")
@client = Packagecloud::Client.new(credentials)
Every client API method call returns a Result
object, which is simply:
module Packagecloud
class Result
attr_accessor :response
attr_accessor :succeeded
end
end
If .succeeded
is true
then, .response
is the parsed JSON response
of that endpoint, otherwise .response
is the error text explaining what went wrong.
This is the list of currently supported distributions.
# Get all distributions
distros = @client.distributions
# Looking up a distribution id by name
id = @client.find_distribution_id("el/6") # returns 27
# Looking up all repositories available for a client
repos = @client.repositories
# Lookup info on a single repo
repo = @client.repository("my_repo")
# Creating a repository
@client.create_repository("my_repo")
When specifiying your repository name, you should use just the name and not the fully qualified name (fqname).
For example:
# INCORRECT: this should just be "my_repo"
repo = @client.repository("user/my_repo")
# Create RPM Packages (takes IO object for file)
distro_id = @client.find_distribution_id("el/6")
rpm_package = Packagecloud::Package.new(open("libcurl-0.1.2.rpm"), distro_id)
# Creating gem Packages (no distribution required)
gem_package = Packagecloud::Package.new(open("rails-4.0.0.gem"))
# Creating source Packages
distro_id = @client.find_distribution_id("ubuntu/trusty")
source_files = { "jake_1.0.orig.tar.bz2" => open("/path/jake_1.0.orig.tar.bz2"),
"jake_1.0-7.debian.tar.gz" => open("/path/jake_1.0-7.debian.tar.gz") }
dsc_package = Packagecloud::Package.new(open("jake_1.0-7.dsc"), distro_id, source_files)
# Upload Packages
@client.put_package("test_repo", gem_package)
@client.put_package("test_repo", rpm_package)
@client.put_package("test_repo", dsc_package)
Copyright (c) 2014-2015 Computology, LLC
See LICENSE.txt for details.