Skip to content

Commit

Permalink
Added support for Request Report Response Parser
Browse files Browse the repository at this point in the history
  • Loading branch information
tim hall committed Dec 16, 2020
1 parent 774e39f commit 8786cec
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .phpunit.result.cache
Original file line number Diff line number Diff line change
@@ -1 +1 @@
C:37:"PHPUnit\Runner\DefaultTestResultCache":4998:{a:2:{s:7:"defects";a:5:{s:85:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_parse_review_response";i:4;s:96:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_parse_review_with_image_response";i:4;s:104:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_parse_review_with_early_reviewer_rewards";i:4;s:76:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_use_dom_html";i:4;s:85:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_parse_review_with_bug";i:3;}s:5:"times";a:36:{s:122:"EolabsIo\AmazonMwsClient\Tests\AmazonMwsResponseParserTest::it_throws_an_exception_if_an_invalid_response_type_is_provided";d:0.032;s:83:"EolabsIo\AmazonMwsClient\Tests\ErrorResponseParserTest::it_can_parse_error_response";d:0.005;s:95:"EolabsIo\AmazonMwsClient\Tests\GetMatchingProductResponseParserTest::it_can_get_result_accessor";d:0.003;s:111:"EolabsIo\AmazonMwsClient\Tests\GetMatchingProductResponseParserTest::it_can_parse_get_matching_product_response";d:0.003;s:112:"EolabsIo\AmazonMwsClient\Tests\GetMatchingProductResponseParserTest::it_can_parse_get_matching_products_response";d:0.004;s:119:"EolabsIo\AmazonMwsClient\Tests\InventoryServiceStatusResponseParserTest::it_can_parse_inventory_service_status_response";d:0.004;s:112:"EolabsIo\AmazonMwsClient\Tests\ListFinancialEventGroupsByNextTokenResponseParserTest::it_can_get_result_accessor";d:0.005;s:143:"EolabsIo\AmazonMwsClient\Tests\ListFinancialEventGroupsByNextTokenResponseParserTest::it_can_parse_list_inventory_supply_by_next_token_response";d:0.004;s:101:"EolabsIo\AmazonMwsClient\Tests\ListFinancialEventGroupsResponseParserTest::it_can_get_result_accessor";d:0.004;s:107:"EolabsIo\AmazonMwsClient\Tests\ListFinancialEventGroupsResponseParserTest::it_can_parse_order_list_response";d:0.004;s:107:"EolabsIo\AmazonMwsClient\Tests\ListFinancialEventsByNextTokenResponseParserTest::it_can_get_result_accessor";d:0.004;s:138:"EolabsIo\AmazonMwsClient\Tests\ListFinancialEventsByNextTokenResponseParserTest::it_can_parse_list_financial_events_by_next_token_response";d:0.003;s:96:"EolabsIo\AmazonMwsClient\Tests\ListFinancialEventsResponseParserTest::it_can_get_result_accessor";d:0.015;s:113:"EolabsIo\AmazonMwsClient\Tests\ListFinancialEventsResponseParserTest::it_can_parse_financial_events_list_response";d:0.01;s:107:"EolabsIo\AmazonMwsClient\Tests\ListInventorySupplyByNextTokenResponseParserTest::it_can_get_result_accessor";d:0.006;s:138:"EolabsIo\AmazonMwsClient\Tests\ListInventorySupplyByNextTokenResponseParserTest::it_can_parse_list_inventory_supply_by_next_token_response";d:0.004;s:96:"EolabsIo\AmazonMwsClient\Tests\ListInventorySupplyResponseParserTest::it_can_get_result_accessor";d:0.005;s:113:"EolabsIo\AmazonMwsClient\Tests\ListInventorySupplyResponseParserTest::it_can_parse_list_inventory_supply_response";d:0.004;s:124:"EolabsIo\AmazonMwsClient\Tests\ListInventorySupplyResponseParserTest::it_can_parse_list_inventory_supply_with_token_response";d:0.003;s:106:"EolabsIo\AmazonMwsClient\Tests\ListMarketplaceParticipationsResponseParserTest::it_can_get_result_accessor";d:0.005;s:142:"EolabsIo\AmazonMwsClient\Tests\ListMarketplaceParticipationsResponseParserTest::it_can_parse_list_marketplace_participations_response_response";d:0.004;s:102:"EolabsIo\AmazonMwsClient\Tests\ListOrderItemsByNextTokenResponseParserTest::it_can_get_result_accessor";d:0.005;s:123:"EolabsIo\AmazonMwsClient\Tests\ListOrderItemsByNextTokenResponseParserTest::it_can_parse_list_orders_by_next_token_response";d:0.004;s:91:"EolabsIo\AmazonMwsClient\Tests\ListOrderItemsResponseParserTest::it_can_get_result_accessor";d:0.004;s:97:"EolabsIo\AmazonMwsClient\Tests\ListOrderItemsResponseParserTest::it_can_parse_order_item_response";d:0.004;s:98:"EolabsIo\AmazonMwsClient\Tests\ListOrdersByNextTokenResponseParserTest::it_can_get_result_accessor";d:0.005;s:119:"EolabsIo\AmazonMwsClient\Tests\ListOrdersByNextTokenResponseParserTest::it_can_parse_list_orders_by_next_token_response";d:0.004;s:87:"EolabsIo\AmazonMwsClient\Tests\ListOrdersResponseParserTest::it_can_get_result_accessor";d:0.005;s:93:"EolabsIo\AmazonMwsClient\Tests\ListOrdersResponseParserTest::it_can_parse_order_list_response";d:0.004;s:110:"EolabsIo\AmazonMwsClient\Tests\ListOrdersResponseParserTest::it_can_parse_order_list_removes_elements_response";d:0.004;s:85:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_parse_review_response";d:0.419;s:98:"EolabsIo\AmazonMwsClient\Tests\ReviewRatingResponseParserTest::it_can_parse_review_rating_response";d:0.179;s:96:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_parse_review_with_image_response";d:0.021;s:104:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_parse_review_with_early_reviewer_rewards";d:0.367;s:76:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_use_dom_html";d:0.051;s:85:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_parse_review_with_bug";d:0.025;}}}
C:37:"PHPUnit\Runner\DefaultTestResultCache":5323:{a:2:{s:7:"defects";a:6:{s:85:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_parse_review_response";i:4;s:96:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_parse_review_with_image_response";i:4;s:104:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_parse_review_with_early_reviewer_rewards";i:4;s:76:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_use_dom_html";i:4;s:85:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_parse_review_with_bug";i:3;s:96:"EolabsIo\AmazonMwsClient\Tests\RequestReportResponseParserTest::it_can_parse_order_list_response";i:4;}s:5:"times";a:38:{s:122:"EolabsIo\AmazonMwsClient\Tests\AmazonMwsResponseParserTest::it_throws_an_exception_if_an_invalid_response_type_is_provided";d:0.037;s:83:"EolabsIo\AmazonMwsClient\Tests\ErrorResponseParserTest::it_can_parse_error_response";d:0.006;s:95:"EolabsIo\AmazonMwsClient\Tests\GetMatchingProductResponseParserTest::it_can_get_result_accessor";d:0.004;s:111:"EolabsIo\AmazonMwsClient\Tests\GetMatchingProductResponseParserTest::it_can_parse_get_matching_product_response";d:0.004;s:112:"EolabsIo\AmazonMwsClient\Tests\GetMatchingProductResponseParserTest::it_can_parse_get_matching_products_response";d:0.004;s:119:"EolabsIo\AmazonMwsClient\Tests\InventoryServiceStatusResponseParserTest::it_can_parse_inventory_service_status_response";d:0.005;s:112:"EolabsIo\AmazonMwsClient\Tests\ListFinancialEventGroupsByNextTokenResponseParserTest::it_can_get_result_accessor";d:0.005;s:143:"EolabsIo\AmazonMwsClient\Tests\ListFinancialEventGroupsByNextTokenResponseParserTest::it_can_parse_list_inventory_supply_by_next_token_response";d:0.004;s:101:"EolabsIo\AmazonMwsClient\Tests\ListFinancialEventGroupsResponseParserTest::it_can_get_result_accessor";d:0.006;s:107:"EolabsIo\AmazonMwsClient\Tests\ListFinancialEventGroupsResponseParserTest::it_can_parse_order_list_response";d:0.003;s:107:"EolabsIo\AmazonMwsClient\Tests\ListFinancialEventsByNextTokenResponseParserTest::it_can_get_result_accessor";d:0.006;s:138:"EolabsIo\AmazonMwsClient\Tests\ListFinancialEventsByNextTokenResponseParserTest::it_can_parse_list_financial_events_by_next_token_response";d:0.003;s:96:"EolabsIo\AmazonMwsClient\Tests\ListFinancialEventsResponseParserTest::it_can_get_result_accessor";d:0.016;s:113:"EolabsIo\AmazonMwsClient\Tests\ListFinancialEventsResponseParserTest::it_can_parse_financial_events_list_response";d:0.01;s:107:"EolabsIo\AmazonMwsClient\Tests\ListInventorySupplyByNextTokenResponseParserTest::it_can_get_result_accessor";d:0.005;s:138:"EolabsIo\AmazonMwsClient\Tests\ListInventorySupplyByNextTokenResponseParserTest::it_can_parse_list_inventory_supply_by_next_token_response";d:0.003;s:96:"EolabsIo\AmazonMwsClient\Tests\ListInventorySupplyResponseParserTest::it_can_get_result_accessor";d:0.005;s:113:"EolabsIo\AmazonMwsClient\Tests\ListInventorySupplyResponseParserTest::it_can_parse_list_inventory_supply_response";d:0.004;s:124:"EolabsIo\AmazonMwsClient\Tests\ListInventorySupplyResponseParserTest::it_can_parse_list_inventory_supply_with_token_response";d:0.004;s:106:"EolabsIo\AmazonMwsClient\Tests\ListMarketplaceParticipationsResponseParserTest::it_can_get_result_accessor";d:0.006;s:142:"EolabsIo\AmazonMwsClient\Tests\ListMarketplaceParticipationsResponseParserTest::it_can_parse_list_marketplace_participations_response_response";d:0.004;s:102:"EolabsIo\AmazonMwsClient\Tests\ListOrderItemsByNextTokenResponseParserTest::it_can_get_result_accessor";d:0.004;s:123:"EolabsIo\AmazonMwsClient\Tests\ListOrderItemsByNextTokenResponseParserTest::it_can_parse_list_orders_by_next_token_response";d:0.003;s:91:"EolabsIo\AmazonMwsClient\Tests\ListOrderItemsResponseParserTest::it_can_get_result_accessor";d:0.005;s:97:"EolabsIo\AmazonMwsClient\Tests\ListOrderItemsResponseParserTest::it_can_parse_order_item_response";d:0.004;s:98:"EolabsIo\AmazonMwsClient\Tests\ListOrdersByNextTokenResponseParserTest::it_can_get_result_accessor";d:0.004;s:119:"EolabsIo\AmazonMwsClient\Tests\ListOrdersByNextTokenResponseParserTest::it_can_parse_list_orders_by_next_token_response";d:0.003;s:87:"EolabsIo\AmazonMwsClient\Tests\ListOrdersResponseParserTest::it_can_get_result_accessor";d:0.006;s:93:"EolabsIo\AmazonMwsClient\Tests\ListOrdersResponseParserTest::it_can_parse_order_list_response";d:0.004;s:110:"EolabsIo\AmazonMwsClient\Tests\ListOrdersResponseParserTest::it_can_parse_order_list_removes_elements_response";d:0.004;s:85:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_parse_review_response";d:0.452;s:98:"EolabsIo\AmazonMwsClient\Tests\ReviewRatingResponseParserTest::it_can_parse_review_rating_response";d:0.183;s:96:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_parse_review_with_image_response";d:0.03;s:104:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_parse_review_with_early_reviewer_rewards";d:0.365;s:76:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_use_dom_html";d:0.051;s:85:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_parse_review_with_bug";d:0.035;s:90:"EolabsIo\AmazonMwsClient\Tests\RequestReportResponseParserTest::it_can_get_result_accessor";d:0.004;s:96:"EolabsIo\AmazonMwsClient\Tests\RequestReportResponseParserTest::it_can_parse_order_list_response";d:0.003;}}}
68 changes: 32 additions & 36 deletions src/AmazonMwsResponseParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,45 @@

namespace EolabsIo\AmazonMwsResponseParser;

use EolabsIo\AmazonMwsResponseParser\Exceptions\AmazonMwsResponseParserException;
use EolabsIo\AmazonMwsResponseParser\Support\XMLParser;
use EolabsIo\AmazonMwsResponseParser\Parsers\ErrorResponseParser;
use EolabsIo\AmazonMwsResponseParser\Parsers\GetMatchingProductResponseParser;
use EolabsIo\AmazonMwsResponseParser\Parsers\ListOrdersResponseParser;
use EolabsIo\AmazonMwsResponseParser\Parsers\RequestReportResponseParser;
use EolabsIo\AmazonMwsResponseParser\Parsers\ListOrderItemsResponseParser;
use EolabsIo\AmazonMwsResponseParser\Parsers\GetServiceStatusResponseParser;
use EolabsIo\AmazonMwsResponseParser\Parsers\ListFinancialEventGroupsByNextTokenResponseParser;
use EolabsIo\AmazonMwsResponseParser\Parsers\GetMatchingProductResponseParser;
use EolabsIo\AmazonMwsResponseParser\Parsers\ListFinancialEventsResponseParser;
use EolabsIo\AmazonMwsResponseParser\Parsers\ListInventorySupplyResponseParser;
use EolabsIo\AmazonMwsResponseParser\Parsers\ListOrdersByNextTokenResponseParser;
use EolabsIo\AmazonMwsResponseParser\Parsers\ListFinancialEventGroupsResponseParser;
use EolabsIo\AmazonMwsResponseParser\Parsers\ListOrderItemsByNextTokenResponseParser;
use EolabsIo\AmazonMwsResponseParser\Parsers\ListMarketplaceParticipationsResponseParser;
use EolabsIo\AmazonMwsResponseParser\Parsers\ListFinancialEventsByNextTokenResponseParser;
use EolabsIo\AmazonMwsResponseParser\Parsers\ListFinancialEventsResponseParser;
use EolabsIo\AmazonMwsResponseParser\Parsers\ListInventorySupplyByNextTokenResponseParser;
use EolabsIo\AmazonMwsResponseParser\Parsers\ListInventorySupplyResponseParser;
use EolabsIo\AmazonMwsResponseParser\Parsers\ListFinancialEventGroupsByNextTokenResponseParser;
use EolabsIo\AmazonMwsResponseParser\Parsers\ListMarketplaceParticipationsByNextTokenResponseParser;
use EolabsIo\AmazonMwsResponseParser\Parsers\ListMarketplaceParticipationsResponseParser;
use EolabsIo\AmazonMwsResponseParser\Parsers\ListOrderItemsByNextTokenResponseParser;
use EolabsIo\AmazonMwsResponseParser\Parsers\ListOrderItemsResponseParser;
use EolabsIo\AmazonMwsResponseParser\Parsers\ListOrdersByNextTokenResponseParser;
use EolabsIo\AmazonMwsResponseParser\Parsers\ListOrdersResponseParser;
use EolabsIo\AmazonMwsResponseParser\Support\XMLParser;
use Illuminate\Support\Collection;
use SimpleXMLElement;

class AmazonMwsResponseParser extends XMLParser
{

public function getParsers(): array
{
return [
'ListInventorySupplyResponse' => ListInventorySupplyResponseParser::class,
'ListInventorySupplyByNextTokenResponse' => ListInventorySupplyByNextTokenResponseParser::class,
'GetServiceStatusResponse' => GetServiceStatusResponseParser::class,
'ListOrdersResponse' => ListOrdersResponseParser::class,
'ListOrdersByNextTokenResponse' => ListOrdersByNextTokenResponseParser::class,
'ListOrderItemsResponse' => ListOrderItemsResponseParser::class,
'ListOrderItemsByNextTokenResponse' => ListOrderItemsByNextTokenResponseParser::class,
'ListFinancialEventGroupsResponse' => ListFinancialEventGroupsResponseParser::class,
'ListFinancialEventGroupsByNextTokenResponse' => ListFinancialEventGroupsByNextTokenResponseParser::class,
'ListFinancialEventsResponse' => ListFinancialEventsResponseParser::class,
'ListFinancialEventsByNextTokenResponse' => ListFinancialEventsByNextTokenResponseParser::class,
'GetMatchingProductResponse' => GetMatchingProductResponseParser::class,
'ListMarketplaceParticipationsResponse' => ListMarketplaceParticipationsResponseParser::class,
'ListMarketplaceParticipationsByNextTokenResponse' => ListMarketplaceParticipationsByNextTokenResponseParser::class,
'ErrorResponse' => ErrorResponseParser::class,
];
}


public function getParsers(): array
{
return [
'ListInventorySupplyResponse' => ListInventorySupplyResponseParser::class,
'ListInventorySupplyByNextTokenResponse' => ListInventorySupplyByNextTokenResponseParser::class,
'GetServiceStatusResponse' => GetServiceStatusResponseParser::class,
'ListOrdersResponse' => ListOrdersResponseParser::class,
'ListOrdersByNextTokenResponse' => ListOrdersByNextTokenResponseParser::class,
'ListOrderItemsResponse' => ListOrderItemsResponseParser::class,
'ListOrderItemsByNextTokenResponse' => ListOrderItemsByNextTokenResponseParser::class,
'ListFinancialEventGroupsResponse' => ListFinancialEventGroupsResponseParser::class,
'ListFinancialEventGroupsByNextTokenResponse' => ListFinancialEventGroupsByNextTokenResponseParser::class,
'ListFinancialEventsResponse' => ListFinancialEventsResponseParser::class,
'ListFinancialEventsByNextTokenResponse' => ListFinancialEventsByNextTokenResponseParser::class,
'GetMatchingProductResponse' => GetMatchingProductResponseParser::class,
'ListMarketplaceParticipationsResponse' => ListMarketplaceParticipationsResponseParser::class,
'ListMarketplaceParticipationsByNextTokenResponse' => ListMarketplaceParticipationsByNextTokenResponseParser::class,
'RequestReportResponse' => RequestReportResponseParser::class,
'ErrorResponse' => ErrorResponseParser::class,
];
}
}
43 changes: 18 additions & 25 deletions src/Parsers/ListMarketplaceParticipationsResponseParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,25 @@
namespace EolabsIo\AmazonMwsResponseParser\Parsers;

use EolabsIo\AmazonMwsResponseParser\Parsers\BaseParser;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use SimpleXMLElement;


class ListMarketplaceParticipationsResponseParser extends BaseParser
{

public function getElementsToRemove(): Collection
{
$element = parent::getElementsToRemove();

return $element->merge(['Participation', 'Marketplace',]);
}

public function getContentAccessor(): string
{
return '';
}

public function handle(): Collection
{
return collect(['RequestId' => $this->getRequestId()])
->merge($this->getResponseResult());
}



}
public function getElementsToRemove(): Collection
{
$element = parent::getElementsToRemove();

return $element->merge(['Participation', 'Marketplace',]);
}

public function getContentAccessor(): string
{
return '';
}

public function handle(): Collection
{
return collect(['RequestId' => $this->getRequestId()])
->merge($this->getResponseResult());
}
}
13 changes: 13 additions & 0 deletions src/Parsers/RequestReportResponseParser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace EolabsIo\AmazonMwsResponseParser\Parsers;

use EolabsIo\AmazonMwsResponseParser\Parsers\BaseParser;

class RequestReportResponseParser extends BaseParser
{
public function getContentAccessor(): string
{
return 'ReportRequestInfo';
}
}
40 changes: 40 additions & 0 deletions tests/RequestReportResponseParserTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace EolabsIo\AmazonMwsClient\Tests;

use EolabsIo\AmazonMwsResponseParser\Tests\TestCase;
use EolabsIo\AmazonMwsResponseParser\Parsers\RequestReportResponseParser;
use EolabsIo\AmazonMwsResponseParser\Support\Facades\AmazonMwsResponseParser;

class RequestReportResponseParserTest extends TestCase
{

/** @test */
public function it_can_get_result_accessor()
{
$file = __DIR__ . '/Stubs/Responses/fetchRequestReport.xml';
$xmlString = file_get_contents($file);
$xml = simplexml_load_string($xmlString);

$resultAccessor = (new RequestReportResponseParser($xml) )->getResultAccessor();

$this->assertEquals($resultAccessor, 'RequestReportResult');
}

/** @test */
public function it_can_parse_order_list_response()
{
$file = __DIR__ . '/Stubs/Responses/fetchRequestReport.xml';
$xmlString = file_get_contents($file);

$response = AmazonMwsResponseParser::fromString($xmlString);

$this->assertEquals($response->get('RequestId'), "88faca76-b600-46d2-b53c-0c8c4533e43a");
$this->assertNull($response->get('NextToken'));

$this->assertEquals($response['ReportRequestInfo']['ReportRequestId'], "2291326454");
$this->assertEquals($response['ReportRequestInfo']['ReportType'], "_GET_MERCHANT_LISTINGS_DATA_");
$this->assertEquals($response['ReportRequestInfo']['StartDate'], "2009-01-21T02:10:39+00:00");
$this->assertEquals($response['ReportRequestInfo']['ReportProcessingStatus'], "_SUBMITTED_");
}
}
18 changes: 18 additions & 0 deletions tests/Stubs/Responses/fetchRequestReport.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<RequestReportResponse
xmlns="http://mws.amazonaws.com/doc/2009-01-01/">
<RequestReportResult>
<ReportRequestInfo>
<ReportRequestId>2291326454</ReportRequestId>
<ReportType>_GET_MERCHANT_LISTINGS_DATA_</ReportType>
<StartDate>2009-01-21T02:10:39+00:00</StartDate>
<EndDate>2009-02-13T02:10:39+00:00</EndDate>
<Scheduled>false</Scheduled>
<SubmittedDate>2009-02-20T02:10:39+00:00</SubmittedDate>
<ReportProcessingStatus>_SUBMITTED_</ReportProcessingStatus>
</ReportRequestInfo>
</RequestReportResult>
<ResponseMetadata>
<RequestId>88faca76-b600-46d2-b53c-0c8c4533e43a</RequestId>
</ResponseMetadata>
</RequestReportResponse>

0 comments on commit 8786cec

Please sign in to comment.