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
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/package_cloud/client.rb', line 33 def create_repo(name, priv) base_url = @config.base_url begin JSON.parse(RestClient.post("#{base_url}/repositories.json", repository: {name: name, private: priv == "private" ? "1" : "0"})) rescue RestClient::UnprocessableEntity => e print "error!\n".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
48 49 50 51 52 53 54 55 56 |
# File 'lib/package_cloud/client.rb', line 48 def distributions base_url = @config.base_url begin JSON.parse(RestClient.get("#{base_url}/distributions.json")) rescue RestClient::ResourceNotFound => e print "failed!\n".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 base_url = @config.base_url begin attrs = JSON.parse(RestClient.get("#{base_url}/repositories.json")) attrs.map { |a| Repository.new(a, @config) } rescue RestClient::ResourceNotFound => e print "failed!\n".red exit(127) end end |
#repository(name) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/package_cloud/client.rb', line 21 def repository(name) base_url = @config.base_url user, repo = name.split("/") begin attrs = JSON.parse(RestClient.get("#{base_url}/#{user}/#{repo}.json")) Repository.new(attrs, @config) rescue RestClient::ResourceNotFound => e print "failed!\n".red exit(127) end end |