Skip to content

Commit

Permalink
feat: add sell feed api
Browse files Browse the repository at this point in the history
close #45
  • Loading branch information
dantio committed Apr 7, 2021
1 parent 103e116 commit 4d85a68
Show file tree
Hide file tree
Showing 7 changed files with 3,965 additions and 664 deletions.
2 changes: 2 additions & 0 deletions src/api/apiFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
Metadata,
Recommendation,
Sell,
Feed as SellFeed
} from './restful/sell';
import Traditional from './traditional';

Expand Down Expand Up @@ -74,6 +75,7 @@ export default class ApiFactory extends Api {
metadata: this.createRestfulApi(Metadata),
recommendation: this.createRestfulApi(Recommendation),
finances: this.createRestfulApi(Finances),
feed: this.createRestfulApi(SellFeed),
};
}

Expand Down
18 changes: 9 additions & 9 deletions src/api/restful/buy/feed/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Restful from '../../';
import {FeedParams} from '../../../../types';
import {BuyFeedParams} from '../../../../types';

/**
* The Feed API provides the ability to download TSV_GZIP feed files containing eBay items and an hourly snapshot file
Expand All @@ -14,12 +14,12 @@ export default class Feed extends Restful {
/**
* This method lets you download a TSV_GZIP (tab separated value gzip) Item feed file.
*
* @param {FeedParams} params
* @param {BuyFeedParams} params
* @param marketplaceId The ID of the eBay marketplace where the item is hosted.
* @param range his header specifies the range in bytes of the chunks of the gzip file being returned.
* Format: bytes=startpos-endpos For example, the following retrieves the first 10 MBs of the feed file.
*/
public getItemFeed(params: FeedParams, marketplaceId: string, range: string) {
public getItemFeed(params: BuyFeedParams, marketplaceId: string, range: string) {
return this.get(`/item`, {
params,
headers: {
Expand All @@ -31,12 +31,12 @@ export default class Feed extends Restful {

/**
* This method lets you download a TSV_GZIP (tab separated value gzip) Item Group feed file.
* @param {FeedParams} params
* @param {BuyFeedParams} params
* @param marketplaceId The ID of the eBay marketplace where the item is hosted.
* @param range his header specifies the range in bytes of the chunks of the gzip file being returned.
* Format: bytes=startpos-endpos For example, the following retrieves the first 10 MBs of the feed file.
*/
public getItemGroupFeed(params: FeedParams, marketplaceId: string, range: string) {
public getItemGroupFeed(params: BuyFeedParams, marketplaceId: string, range: string) {
return this.get(`/item_group`, {
params,
headers: {
Expand All @@ -49,13 +49,13 @@ export default class Feed extends Restful {
/**
* The Hourly Snapshot feed file is generated each hour every day for all categories.
*
* @param {FeedParams} params
* @param {BuyFeedParams} params
* @param {String} snapshotDate
* @param marketplaceId The ID of the eBay marketplace where the item is hosted.
* @param range his header specifies the range in bytes of the chunks of the gzip file being returned.
* Format: bytes=startpos-endpos For example, the following retrieves the first 10 MBs of the feed file.
*/
public getItemSnapshotFeed(params: FeedParams, snapshotDate: string, marketplaceId: string, range: string) {
public getItemSnapshotFeed(params: BuyFeedParams, snapshotDate: string, marketplaceId: string, range: string) {
return this.get(`/item_snapshot`, {
params: {
...params,
Expand All @@ -71,13 +71,13 @@ export default class Feed extends Restful {
/**
* The Hourly Snapshot feed file is generated each hour every day for all categories.
*
* @param {FeedParams} params
* @param {BuyFeedParams} params
* @param {String} snapshotDate
* @param marketplaceId The ID of the eBay marketplace where the item is hosted.
* @param range his header specifies the range in bytes of the chunks of the gzip file being returned.
* Format: bytes=startpos-endpos For example, the following retrieves the first 10 MBs of the feed file.
*/
public getProductFeed(params: FeedParams, snapshotDate: string, marketplaceId: string, range: string) {
public getProductFeed(params: BuyFeedParams, snapshotDate: string, marketplaceId: string, range: string) {
return this.get(`/product`, {
params: {
...params,
Expand Down
309 changes: 309 additions & 0 deletions src/api/restful/sell/feed/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,309 @@
import Restful from '../../';
import {SellFeedParams} from '../../../../types';

/**
* The <strong>Feed API</strong> lets sellers upload input files, download reports and files including their status, filter reports using URI parameters, and retrieve customer service metrics task details.
*/
export default class Feed extends Restful {
get basePath(): string {
return '/sell/feed/v1';
}

/**
* This method returns the details and status for an array of order tasks based on a specified feed_type or scheduled_id.
*
* @param dateRange The order tasks creation date range.
* @param feedType The feed type associated with the task.
* @param limit The maximum number of order tasks that can be returned on each page of the paginated response.
* @param lookBackDays The number of previous days in which to search for tasks. Do not use with the date_range parameter.
* @param offset The number of order tasks to skip in the result set before returning the first order in the paginated response.
* @param scheduleId The schedule ID associated with the order task.
*/
public getOrderTasks({
dateRange,
feedType,
limit,
lookBackDays,
offset,
scheduleId
}: SellFeedParams) {
return this.get(`/order_task`, {
params: {
date_range: dateRange,
feed_type: feedType,
limit,
look_back_days: lookBackDays,
offset,
schedule_id: scheduleId
}
});
}

/**
* This method creates an order download task with filter criteria for the order report.
*
* @param marketplaceId The ID of the eBay marketplace where the item is hosted.
* @param data The CreateOrderTaskRequest
*/
public createOrderTask(marketplaceId: string, data: any) {
return this.post(`/order_task`, data, {
headers: {
'X-EBAY-C-MARKETPLACE-ID': marketplaceId
}
})
}

/**
* This method retrieves the task details and status of the specified task.
*
* @param taskId The ID of the task. This ID is generated when the task was created by the createOrderTask method.
*/
public getOrderTask(taskId: string,) {
taskId = encodeURIComponent(taskId);

return this.get(`/order_task/${taskId}`);
}

/**
* This method retrieves an array containing the details and status of all schedules based on the specified feed_type.
*
* @param feedType The feedType associated with the schedule.
* @param limit The maximum number of schedules that can be returned on each page of the paginated response.
* @param offset The number of schedules to skip in the result set before returning the first schedule in the paginated response.
*/
public getSchedules({
feedType,
limit,
offset,
}: SellFeedParams) {
return this.get(`/schedule`, {
params: {
feed_type: feedType,
limit,
offset
}
});
}

/**
* This method creates a schedule, which is a subscription to the specified schedule template.
*
* @params data The CreateUserScheduleRequest
*/
public createSchedule(data: any) {
return this.post(`/schedule`, data)
}

/**
* This method retrieves schedule details and status of the specified schedule.
*
* @param scheduleId The ID of the schedule for which to retrieve the details.
*/
public getSchedule(scheduleId: string) {
scheduleId = encodeURIComponent(scheduleId)
return this.get(`/schedule/${scheduleId}`);
}

/**
* This method updates an existing schedule.
*
* @param scheduleId The ID of the schedule to update.
* @param data The UpdateUserScheduleRequest.
*/
public updateSchedule(scheduleId: string, data?: any) {
scheduleId = encodeURIComponent(scheduleId)
return this.put(`/schedule/${scheduleId}`, data);
}

/**
* This method deletes an existing schedule.
*
* @param scheduleId The schedule_id of the schedule to delete.
*/
public deleteSchedule(scheduleId: string) {
scheduleId = encodeURIComponent(scheduleId)
return this.delete(`/schedule/${scheduleId}`);
}

/**
* This method downloads the latest result file generated by the schedule.
*
* @param scheduleId The ID of the schedule for which to retrieve the latest result file.
*/
public getLatestResultFile(scheduleId: string) {
scheduleId = encodeURIComponent(scheduleId)
return this.get(`/schedule/${scheduleId}/download_result_file`);
}

/**
* This method downloads the latest result file generated by the schedule.
*
* @param scheduleTemplateId The ID of the template to retrieve.
*/
public getScheduleTemplate(scheduleTemplateId: string) {
scheduleTemplateId = encodeURIComponent(scheduleTemplateId)
return this.get(`/schedule_template/${scheduleTemplateId}`);
}

/**
* This method retrieves an array containing the details and status of all schedule templates based on the specified feed_type.
*
* @param feedType The feedType associated with the schedule.
* @param limit The maximum number of schedules that can be returned on each page of the paginated response.
* @param offset The number of schedules to skip in the result set before returning the first schedule in the paginated response.
*/
public getScheduleTemplates({
feedType,
limit,
offset,
}: SellFeedParams) {
return this.get(`/schedule_template`, {
params: {
feed_type: feedType,
limit,
offset
}
});
}

/**
* This method returns the details and status for an array of tasks based on a specified feed_type or scheduledId.
*
* @param dateRange The order tasks creation date range.
* @param feedType The feed type associated with the task.
* @param limit The maximum number of order tasks that can be returned on each page of the paginated response.
* @param lookBackDays The number of previous days in which to search for tasks. Do not use with the date_range parameter.
* @param offset The number of order tasks to skip in the result set before returning the first order in the paginated response.
* @param scheduleId The schedule ID associated with the task.
*/
public getTasks({
dateRange,
feedType,
limit,
lookBackDays,
offset,
scheduleId
}: SellFeedParams) {
return this.get(`/task`, {
params: {
date_range: dateRange,
feed_type: feedType,
limit,
look_back_days: lookBackDays,
offset,
schedule_id: scheduleId
}
});
}

/**
* This method creates an upload task or a download task without filter criteria.
*
* @param marketplaceId The ID of the eBay marketplace where the item is hosted.
* @param data The CreateTaskRequest.
*/
public createTask(marketplaceId: string, data: any) {
return this.post(`/task`, data, {
headers: {
'X-EBAY-C-MARKETPLACE-ID': marketplaceId
}
})
}

/**
* This method downloads the file previously uploaded using uploadFile.
*
* @param taskId The task ID associated with the file to be downloaded.
*/
public getInputFile(taskId: string) {
taskId = encodeURIComponent(taskId)
return this.get(`/task/${taskId}/download_input_file`);
}

/**
* This method retrieves the generated file that is associated with the specified task ID.
*
* @param taskId The task ID associated with the file to be downloaded.
*/
public getResultFile(taskId: string) {
taskId = encodeURIComponent(taskId)
return this.get(`/task/${taskId}/download_result_file`);
}

/**
* This method retrieves the details and status of the specified task.
*
* @param taskId The ID of the task.
*/
public getTask(taskId: string) {
taskId = encodeURIComponent(taskId)
return this.get(`/task/${taskId}`);
}

/**
* This method associates the specified file with the specified task ID and uploads the input file.
*
* @param taskId The task_id associated with the file that will be uploaded.
* @param data FormDataContentDisposition.
*/
public uploadFile(taskId: string, data?: any) {
taskId = encodeURIComponent(taskId)
return this.post(`/task/${taskId}/upload_file`, data, {
headers: {
'Content-Type': 'multipart/form-data'
},
});
}

/**
* Use this method to return an array of customer service metric tasks.
*
* @param dateRange The order tasks creation date range.
* @param feedType The feed type associated with the task.
* @param limit The maximum number of order tasks that can be returned on each page of the paginated response.
* @param lookBackDays The number of previous days in which to search for tasks. Do not use with the date_range parameter.
* @param offset The number of order tasks to skip in the result set before returning the first order in the paginated response.
* @param scheduleId The schedule ID associated with the task.
*/
public getCustomerServiceMetricTasks({
dateRange,
feedType,
limit,
lookBackDays,
offset,
}: SellFeedParams) {
return this.get(`/customer_service_metric_task`, {
params: {
date_range: dateRange,
feed_type: feedType,
limit,
look_back_days: lookBackDays,
offset,
}
});
}

/**
* Use this method to create a customer service metrics download task with filter criteria for the customer service metrics report.
*
* @params acceptLanguage Use this header to specify the natural language in which the authenticated user desires the response.
* @params data The CreateServiceMetricsTaskRequest
*/
public createCustomerServiceMetricTask(acceptLanguage: string, data: any) {
return this.post(`/customer_service_metric_task`, data, {
headers: {
'accept-language': acceptLanguage
}
});
}

/**
* Use this method to retrieve customer service metric task details for the specified task.
*
* @param taskId Use this path parameter to specify the task ID value for the customer service metric task to retrieve.
*/
public getCustomerServiceMetricTask(taskId: string) {
taskId = encodeURIComponent(taskId)
return this.get(`/customer_service_metric_task/${taskId}`);
}
}
Loading

0 comments on commit 4d85a68

Please sign in to comment.