bintray.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.BintrayClient = undefined;
  6. exports.bintrayRequest = bintrayRequest;
  7. var _httpExecutor;
  8. function _load_httpExecutor() {
  9. return _httpExecutor = require("./httpExecutor");
  10. }
  11. function bintrayRequest(path, auth) {
  12. let data = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  13. let cancellationToken = arguments[3];
  14. let method = arguments[4];
  15. return (0, (_httpExecutor || _load_httpExecutor()).request)((0, (_httpExecutor || _load_httpExecutor()).configureRequestOptions)({ hostname: "api.bintray.com", path: path }, auth, method), cancellationToken, data);
  16. }
  17. class BintrayClient {
  18. constructor(options, cancellationToken, apiKey) {
  19. this.cancellationToken = cancellationToken;
  20. if (options.owner == null) {
  21. throw new Error("owner is not specified");
  22. }
  23. if (options.package == null) {
  24. throw new Error("package is not specified");
  25. }
  26. this.repo = options.repo || "generic";
  27. this.packageName = options.package;
  28. this.owner = options.owner;
  29. this.user = options.user || options.owner;
  30. this.auth = apiKey == null ? null : `Basic ${new Buffer(`${this.user}:${apiKey}`).toString("base64")}`;
  31. this.basePath = `/packages/${this.owner}/${this.repo}/${this.packageName}`;
  32. }
  33. getVersion(version) {
  34. return bintrayRequest(`${this.basePath}/versions/${version}`, this.auth, null, this.cancellationToken);
  35. }
  36. getVersionFiles(version) {
  37. return bintrayRequest(`${this.basePath}/versions/${version}/files`, this.auth, null, this.cancellationToken);
  38. }
  39. createVersion(version) {
  40. return bintrayRequest(`${this.basePath}/versions`, this.auth, {
  41. name: version
  42. }, this.cancellationToken);
  43. }
  44. deleteVersion(version) {
  45. return bintrayRequest(`${this.basePath}/versions/${version}`, this.auth, null, this.cancellationToken, "DELETE");
  46. }
  47. }
  48. exports.BintrayClient = BintrayClient; //# sourceMappingURL=bintray.js.map