Class: PackageCloud::Client
- Inherits:
-
Object
- Object
- PackageCloud::Client
- Defined in:
- lib/package_cloud/client.rb
Instance Method Summary collapse
- #create_repo(name, priv) ⇒ Object
- #distributions ⇒ Object
-
#initialize(config) ⇒ Client
constructor
A new instance of Client.
- #repositories ⇒ Object
- #repository(name) ⇒ Object
Constructor Details
#initialize(config) ⇒ Client
Returns a new instance of Client.
6 7 8 |
# File 'lib/package_cloud/client.rb', line 6 def initialize(config) @config = config end |
Instance Method Details
#create_repo(name, priv) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/package_cloud/client.rb', line 38 def create_repo(name, priv) url = PackageCloud::Util.compute_url(@config.base_url, "/api/v1/repos.json") begin JSON.parse(RestClient.post(url, :repository => {:name => name, :private => priv == "private" ? "1" : "0"})) rescue RestClient::UnprocessableEntity => e print "error!\n".color(:red) json = JSON.parse(e.response) json.each do |k,v| puts "\n\t#{k}: #{v.join(", ")}\n" end puts "" exit(1) end end |
#distributions ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/package_cloud/client.rb', line 53 def distributions url = PackageCloud::Util.compute_url(@config.base_url, "/api/v1/distributions.json") begin JSON.parse(RestClient.get(url)) rescue RestClient::ResourceNotFound => e print "failed!\n".color(:red) exit(127) end end |
#repositories ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/package_cloud/client.rb', line 10 def repositories url = PackageCloud::Util.compute_url(@config.base_url, "/api/v1/repos.json") begin attrs = JSON.parse(RestClient.get(url)) attrs.map { |a| Repository.new(a, @config) } rescue RestClient::ResourceNotFound => e print "failed!\n".color(:red) exit(127) end end |
#repository(name) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/package_cloud/client.rb', line 21 def repository(name) user, repo = name.split("/") url = PackageCloud::Util.compute_url(@config.base_url, "/api/v1/repos/#{user}/#{repo}.json") begin attrs = JSON.parse(RestClient.get(url)) if attrs["error"] == "not_found" print "failed... Repository #{user}/#{repo} not found!\n".color(:red) exit(127) end Repository.new(attrs, @config) rescue RestClient::ResourceNotFound => e print "failed!\n".color(:red) exit(127) end end |