Skip to content

Commit

Permalink
moving service description to module.config.php
Browse files Browse the repository at this point in the history
  • Loading branch information
Plamen Garkov committed Dec 20, 2016
1 parent 8620093 commit 183b032
Show file tree
Hide file tree
Showing 9 changed files with 349 additions and 641 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ other configuration settings. Make sure to remove `.dist` from your file.Your `n
<?php
return [
'nytimes_service' => [
'service_url' => 'https://api.nytimes.com',
'version' => 'v3',
'format' => 'json',
'api_key' => '<your-api-key>',
]
];
Expand All @@ -57,8 +54,12 @@ Calling from your code:
$request->setList('hardcover-fiction')
->setSortOrder(AbstractRequest::SORT_ORDER_ASC);

$records = $this->getService()->bestSellerList($request);
$result = $this->getService()->bestSellerList($request);

$numberOfRecords = $result->toArray()['num_results];
var_dump($numberOfRecords);

$records= $result->toArray()['results];
var_dump($records);

```
Expand Down
254 changes: 253 additions & 1 deletion config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,259 @@
)
)
)
)
),
'nytimes_service' => [
'description' => [
'baseUri' => 'https://api.nytimes.com',
'apiVersion' => 'v3',
'operations' => [
'lists_command' => [
'httpMethod' => 'GET',
'uri' => '/svc/books/v3/lists.json',
'responseModel' => 'getResponse',
'parameters' => [
'api-key' => [
'type' => 'string',
'required' => true,
'location' => 'query'
],
'list' => [
'type' => 'string',
'location' => 'query'
],
'weeks-on-list' => [
'type' => 'integer',
'location' => 'query'
],
'bestsellers-date' => [
'type' => 'date-time',
'required' => false,
'location' => 'query',
],
'date' => [
'type' => 'string',
'required' => false,
'location' => 'query'
],
'isbn' => [
'type' => 'string',
'location' => 'query'
],
'published-date' => [
'type' => 'string',
'required' => false,
'location' => 'query'
],
'rank' => [
'type' => 'integer',
'location' => 'query'
],
'rank-last-week' => [
'type' => 'integer',
'location' => 'query'
],
'offset' => [
'type' => 'integer',
'location' => 'query'
],
'sort-order' => [
'type' => 'string',
'location' => 'query'
]
]
],
'history_command' => [
'httpMethod' => 'GET',
'uri' => '/svc/books/v3/lists/best-sellers/history.json',
'responseModel' => 'getResponse',
'parameters' => [
'age-group' => [
"location" => "query",
"description" => "The target age group for the best seller.",
"type" => "string"
],
'author' => [
"location" => "query",
"description" => "The author of the best seller. The author field does not include additional contributors (see Data Structure for more details about the author and contributor fields).\n\nWhen searching the author field, you can specify any combination of first, middle and last names.\n\nWhen sort-by is set to author, the results will be sorted by author's first name. ",
"type" => "string"
],
'contributor' => [
"name" => "contributor",
"location" => "query",
"description" => "The author of the best seller, as well as other contributors such as the illustrator (to search or sort by author name only, use author instead).\n\nWhen searching, you can specify any combination of first, middle and last names of any of the contributors.\n\nWhen sort-by is set to contributor, the results will be sorted by the first name of the first contributor listed. ",
"type" => "string"
],
'isbn' => [
"location" => "query",
"description" => "International Standard Book Number, 10 or 13 digits\n\nA best seller may have both 10-digit and 13-digit ISBNs, and may have multiple ISBNs of each type. To search on multiple ISBNs, separate the ISBNs with semicolons (example: 9780446579933;0061374229).",
"type" => "string"
],
'price' => [
"location" => "query",
"description" => "The publisher's list price of the best seller, including decimal point",
"type" => "string"
],
'publisher' => [
"location" => "query",
"description" => "The standardized name of the publisher",
"type" => "string"
],
'title' => [
"location" => "query",
"description" => "The title of the best seller\n\nWhen searching, you can specify a portion of a title or a full title.",
"type" => "string"
],
'api-key' => [
"location" => "query",
'required' => true,
"description" => "api key",
"type" => "string"
]
]
],
'list_names_command' => [
'httpMethod' => 'GET',
'uri' => '/svc/books/v3/lists/names.json',
'responseModel' => 'getResponse',
'parameters' => [
'api-key' => [
'type' => 'string',
'required' => true,
'location' => 'query'
]
]
],
'overview_command' => [
'httpMethod' => 'GET',
'uri' => '/svc/books/v3/lists/overview.json',
'responseModel' => 'getResponse',
'parameters' => [
'api-key' => [
'type' => 'string',
'required' => true,
'location' => 'query'
],
'published_date' => [
'type' => 'string',
'location' => 'query'
],
]
],
'lists_by_date_command' => [
'httpMethod' => 'GET',
'uri' => '/svc/books/v3/lists/{date}/{list}.json',
'responseModel' => 'getResponse',
'parameters' => [
'api-key' => [
'type' => 'string',
'required' => true,
'location' => 'query'
],
'date' => [
'type' => 'string',
'required' => true,
'location' => 'uri'
],
'list' => [
'type' => 'string',
'required' => true,
'location' => 'uri'
],
'isbn' => [
'type' => 'integer',
'location' => 'query'
],
'list-name' => [
'type' => 'string',
'location' => 'query'
],
'published-date' => [
'type' => 'date-time',
'location' => 'query'
],
'bestsellers-date' => [
'type' => 'string',
'location' => 'query'
],
'weeks-on-list' => [
'type' => 'integer',
'location' => 'query'
],
'rank' => [
'type' => 'string',
'location' => 'query'
],
'rank-last-week' => [
'type' => 'integer',
'location' => 'query'
],
'offset' => [
'type' => 'integer',
'location' => 'query'
],
'sort-order' => [
'type' => 'string',
'location' => 'query'
],
],
],
'reviews_command' => [
'httpMethod' => 'GET',
'uri' => '/svc/books/v3/reviews.json',
'responseModel' => 'getResponse',
'parameters' => [
'api-key' => [
'type' => 'string',
'required' => true,
'location' => 'query'
],
'isbn' => [
'type' => 'integer',
'location' => 'query'
],
'title' => [
'type' => 'string',
'location' => 'query'
],
'author' => [
'type' => 'string',
'location' => 'query'
]
]
]
],
'models' => [
'getResponse' => [
'type' => 'object',
"properties" => [
"success" => [
"type" => "string",
"required" => true
],
"errors" => [
"type" => "array",
"items" => [
"type" => "object",
"properties" => [
"code" => [
"type" => "string",
"description" => "The error code."
],
"message" => [
"type" => "string",
"description" => "The detailed message from the server."
]
]
]
]
],
'additionalProperties' => [
'location' => 'json'
]
]
]
]
]
);


3 changes: 0 additions & 3 deletions config/nytimes.local.php.dist
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<?php
return [
'nytimes_service' => [
'service_url' => 'https://api.nytimes.com',
'version' => 'v3',
'format' => 'json',
'api_key' => '',
]
];
Expand Down
25 changes: 19 additions & 6 deletions src/Controller/ConsoleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ public function listsAction()

$request->setSortOrder(AbstractRequest::SORT_ORDER_ASC);

$records = $this->getService()->bestSellerList($request);
$result = $this->getService()->bestSellerList($request);

$records = $result->toArray()['results'];

var_dump($records);

Expand All @@ -52,7 +54,9 @@ public function historyAction()
$request->setAuthor('Michael Connelly');
}

$records = $this->getService()->bestSellerHistoryList($request);
$result = $this->getService()->bestSellerHistoryList($request);

$records = $result->toArray()['results'];

var_dump($records);

Expand All @@ -65,7 +69,9 @@ public function listNamesAction()

$request = new ListNames();

$records = $this->getService()->bestSellerListNames($request);
$result = $this->getService()->bestSellerListNames($request);

$records = $result->toArray()['results'];

var_dump($records);

Expand All @@ -79,7 +85,9 @@ public function overviewAction()
$request = new Overview();
$request->setPublishedDate('2016-01-10');

$records = $this->getService()->bestSellerListOverview($request);
$result = $this->getService()->bestSellerListOverview($request);

$records = $result->toArray()['results'];

var_dump($records);

Expand All @@ -106,7 +114,9 @@ public function listByDateAction()
$request->setDate('2016-10-21');
}

$records = $this->getService()->bestSellerListByDate($request);
$result = $this->getService()->bestSellerListByDate($request);

$records = $result->toArray()['results'];

var_dump($records);

Expand All @@ -126,7 +136,10 @@ public function reviewsAction()
$request->setAuthor('John Grisham');
}

$records = $this->getService()->reviews($request);
$result = $this->getService()->reviews($request);

$records = $result->toArray()['results'];

var_dump($records);


Expand Down
Loading

0 comments on commit 183b032

Please sign in to comment.