Class: Baps::PackagecloudAPI

Inherits:
Object
  • Object
show all
Defined in:
lib/baps/packagecloud_api.rb

Instance Method Summary collapse

Constructor Details

#initialize(username, token) ⇒ PackagecloudAPI



5
6
7
8
9
# File 'lib/baps/packagecloud_api.rb', line 5

def initialize(username, token)
  connection = Packagecloud::Connection.new('https', 'packages.shopify.io')
  credentials = Packagecloud::Credentials.new(username, token)
  @client = Packagecloud::Client.new(credentials, "packagecloud-ruby #{Packagecloud::VERSION}", connection)
end

Instance Method Details

#package_exist?(name:, version:, arch: 'amd64', type: 'deb') ⇒ Boolean



21
22
23
24
25
26
# File 'lib/baps/packagecloud_api.rb', line 21

def package_exist?(name:, version:, arch: 'amd64', type: 'deb')
  url = "/api/v1/repos/shopify/public/package/#{type}/ubuntu/trusty/#{name}/#{arch}/#{version}/stats/downloads/count.json"
  json = @client.send(:get, url)
  result = @client.send(:parsed_json_result, json)
  result.succeeded
end

#publish_package(file) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/baps/packagecloud_api.rb', line 11

def publish_package(file)
  package = Packagecloud::Package.new(file: file)
  result = @client.put_package('public', package, 'ubuntu/trusty')
  if result.succeeded
    puts "Package #{file} has been pushed to packagecloud"
  else
    puts "Could not push #{file} to packagecoud: #{result.response}"
  end
end