Class: Baps::PackagecloudAPI
- Inherits:
-
Object
- Object
- Baps::PackagecloudAPI
- Defined in:
- lib/baps/packagecloud_api.rb
Instance Method Summary collapse
-
#initialize(username, token) ⇒ PackagecloudAPI
constructor
A new instance of PackagecloudAPI.
- #package_exist?(name:, version:, release:, arch: 'amd64', type: 'deb', os: 'ubuntu', dist: 'trusty') ⇒ Boolean
- #publish_package(file) ⇒ Object
Constructor Details
#initialize(username, token) ⇒ PackagecloudAPI
Returns a new instance of 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:, release:, arch: 'amd64', type: 'deb', os: 'ubuntu', dist: 'trusty') ⇒ Boolean
21 22 23 24 25 26 27 28 |
# File 'lib/baps/packagecloud_api.rb', line 21 def package_exist?(name:, version:, release:, arch: 'amd64', type: 'deb', os: 'ubuntu', dist: 'trusty') package = "#{type}/#{os}/#{dist}/#{name}/#{arch}/#{version}" package << "-#{release}" if release url = "/api/v1/repos/shopify/public/package/#{package}/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 |