@@ -3080,3 +3080,179 @@ def search_package(self, package=None, desc=None, subject=None, repo=None):
30803080 response = self ._requester .get (url , params = params )
30813081 self ._logger .info ("Search successfully" )
30823082 return response
3083+
3084+ # Statistics & Usage Report (This resource is only available for Bintray Premium accounts.)
3085+
3086+ def _get_custom_downloads (self , subject , repo , package , suffix , version = None ,
3087+ from_date = None ,
3088+ to_date = None ):
3089+ """ Get number of downloads, for the passed time range, per package or per version.
3090+ Security: Authenticated user with 'publish' permission for private repositories,
3091+ or package read/write entitlement.
3092+ :param subject: repository owner
3093+ :param repo: repository name
3094+ :param package: package name
3095+ :param suffix: suffix name
3096+ :param version: package version (Optional)
3097+ :param from_date: initial date range ISO8601 (yyyy-MM-dd'T'HH:mm:ss.SSSZ)
3098+ :param to_date: end date range ISO8601 (yyyy-MM-dd'T'HH:mm:ss.SSSZ)
3099+ :return: download details
3100+ """
3101+ url = "{}/packages/{}/{}/{}" .format (Bintray .BINTRAY_URL , subject , repo , package )
3102+ if version :
3103+ url += "/versions/{}/stats/{}" .format (version , suffix )
3104+ else :
3105+ url += "/stats/{}" .format (suffix )
3106+ json_data = {}
3107+ if from_date :
3108+ json_data ["from" ] = from_date
3109+ if to_date :
3110+ json_data ["to" ] = to_date
3111+
3112+ response = self ._requester .post (url , json = json_data )
3113+ self ._logger .info ("Search successfully" )
3114+ return response
3115+
3116+ def get_daily_downloads (self , subject , repo , package , version = None , from_date = None ,
3117+ to_date = None ):
3118+ """ Get number of downloads per day, for the passed time range, per package or per version.
3119+ Security: Authenticated user with 'publish' permission for private repositories,
3120+ or package read/write entitlement.
3121+ :param subject: repository owner
3122+ :param repo: repository name
3123+ :param package: package name
3124+ :param version: package version (Optional)
3125+ :param from_date: initial date range ISO8601 (yyyy-MM-dd'T'HH:mm:ss.SSSZ)
3126+ :param to_date: end date range ISO8601 (yyyy-MM-dd'T'HH:mm:ss.SSSZ)
3127+ :return: download details
3128+ """
3129+ return self ._get_custom_downloads (subject , repo , package , "time_range_downloads" ,
3130+ version ,
3131+ from_date , to_date )
3132+
3133+ def get_total_downloads (self , subject , repo , package , version = None , from_date = None ,
3134+ to_date = None ):
3135+ """ Get total number of downloads, for the passed time range, per package or per version.
3136+ Security: Authenticated user with 'publish' permission for private repositories,
3137+ or package read/write entitlement.
3138+ :param subject: repository owner
3139+ :param repo: repository name
3140+ :param package: package name
3141+ :param version: package version (Optional)
3142+ :param from_date: initial date range ISO8601 (yyyy-MM-dd'T'HH:mm:ss.SSSZ)
3143+ :param to_date: end date range ISO8601 (yyyy-MM-dd'T'HH:mm:ss.SSSZ)
3144+ :return: download details
3145+ """
3146+ return self ._get_custom_downloads (subject , repo , package , "total_downloads" , version ,
3147+ from_date , to_date )
3148+
3149+ def get_downloads_by_country (self , subject , repo , package , version = None , from_date = None ,
3150+ to_date = None ):
3151+ """ Get total number of downloads, for the passed time range, per package or per version.
3152+ Security: Authenticated user with 'publish' permission for private repositories,
3153+ or package read/write entitlement.
3154+ :param subject: repository owner
3155+ :param repo: repository name
3156+ :param package: package name
3157+ :param version: package version (Optional)
3158+ :param from_date: initial date range ISO8601 (yyyy-MM-dd'T'HH:mm:ss.SSSZ)
3159+ :param to_date: end date range ISO8601 (yyyy-MM-dd'T'HH:mm:ss.SSSZ)
3160+ :return: download details
3161+ """
3162+ return self ._get_custom_downloads (subject , repo , package , "country_downloads" , version ,
3163+ from_date , to_date )
3164+
3165+ def get_usage_report_for_subject (self , subject , from_date = None , to_date = None ):
3166+ """ Get monthly download and storage usage report, according to the specified date range
3167+ for a subject.
3168+ Security: Authenticated user with 'admin' permission.
3169+ :param subject: repository owner
3170+ :param from_date: initial date range ISO8601 (yyyy-MM-dd'T'HH:mm:ss.SSSZ)
3171+ :param to_date: end date range ISO8601 (yyyy-MM-dd'T'HH:mm:ss.SSSZ)
3172+ :return: download details
3173+ """
3174+ url = "{}/usage/{}" .format (Bintray .BINTRAY_URL , subject )
3175+ json_data = {}
3176+ if from_date :
3177+ json_data ["from" ] = from_date
3178+ if to_date :
3179+ json_data ["to" ] = to_date
3180+
3181+ response = self ._requester .post (url , json = json_data )
3182+ self ._logger .info ("Search successfully" )
3183+ return response
3184+
3185+ def get_usage_report_for_repository (self , subject , repo , from_date = None , to_date = None ):
3186+ """ Get monthly download and storage usage report, according to the specified date range
3187+ for a specific subject repository.
3188+ Security: Authenticated user with 'admin' permission.
3189+ :param subject: repository owner
3190+ :param repo: repository name
3191+ :param from_date: initial date range ISO8601 (yyyy-MM-dd'T'HH:mm:ss.SSSZ)
3192+ :param to_date: end date range ISO8601 (yyyy-MM-dd'T'HH:mm:ss.SSSZ)
3193+ :return: download details
3194+ """
3195+ url = "{}/usage/{}/{}" .format (Bintray .BINTRAY_URL , subject , repo )
3196+ json_data = {}
3197+ if from_date :
3198+ json_data ["from" ] = from_date
3199+ if to_date :
3200+ json_data ["to" ] = to_date
3201+
3202+ response = self ._requester .post (url , json = json_data )
3203+ self ._logger .info ("Search successfully" )
3204+ return response
3205+
3206+ def get_usage_report_for_package (self , subject , repo , package = None , start_pos = 50 ,
3207+ from_date = None , to_date = None ):
3208+ """ Get current storage usage report. Report can be requested for the specified repository,
3209+ optionally for a specific package.
3210+ Security: Authenticated user with 'admin' permission for repo, or 'publish' permission
3211+ for specific package.
3212+ :param subject: repository owner
3213+ :param repo: repository name
3214+ :param package: package name
3215+ :param start_pos: index position
3216+ :param from_date: initial date range ISO8601 (yyyy-MM-dd'T'HH:mm:ss.SSSZ)
3217+ :param to_date: end date range ISO8601 (yyyy-MM-dd'T'HH:mm:ss.SSSZ)
3218+ :return: download details
3219+ """
3220+ url = "{}/usage/package_usage/{}/{}" .format (Bintray .BINTRAY_URL , subject , repo )
3221+ if package :
3222+ url += "/{}" .format (package )
3223+ params = {"start_pos" : start_pos }
3224+ json_data = {}
3225+ if from_date :
3226+ json_data ["from" ] = from_date
3227+ if to_date :
3228+ json_data ["to" ] = to_date
3229+
3230+ response = self ._requester .post (url , json = json_data , params = params )
3231+ self ._logger .info ("Search successfully" )
3232+ return response
3233+
3234+ def get_usage_report_grouped_by_business_unit (self , subject , business_unit = None ,
3235+ from_date = None ,
3236+ to_date = None ):
3237+ """ Get monthly download and storage usage report, according to the specified date range
3238+ and grouped by business unit. Report can be requested for a subject or for a specific
3239+ subject business unit.
3240+ Security: Authenticated user with 'admin' permission.
3241+ :param subject: repository owner
3242+ :param business_unit: business unit name
3243+ :param from_date: initial date range ISO8601 (yyyy-MM-dd'T'HH:mm:ss.SSSZ)
3244+ :param to_date: end date range ISO8601 (yyyy-MM-dd'T'HH:mm:ss.SSSZ)
3245+ :return: download details
3246+ """
3247+ url = "{}/usage/business_unit_usage/{}" .format (Bintray .BINTRAY_URL , subject )
3248+ if business_unit :
3249+ url += "/{}" .format (business_unit )
3250+ json_data = {}
3251+ if from_date :
3252+ json_data ["from" ] = from_date
3253+ if to_date :
3254+ json_data ["to" ] = to_date
3255+
3256+ response = self ._requester .post (url , json = json_data )
3257+ self ._logger .info ("Search successfully" )
3258+ return response
0 commit comments