Skip to content

Commit

Permalink
close #7
Browse files Browse the repository at this point in the history
  • Loading branch information
Attila Laszlo committed Feb 1, 2017
1 parent 383adac commit 1760916
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 16 deletions.
4 changes: 4 additions & 0 deletions src/DevelopersSite/Controllers/DocsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public IActionResult Index(string product, string version, string file = "index"
{
return RedirectToAction("Index", "Docs", documentService.GetRouteParams("API"));
}
if (string.IsNullOrEmpty(version))
{
return RedirectToAction("Index", "Docs", documentService.GetRouteParams(product));
}

var docVersion = documentService.GetVersion(document, version);

Expand Down
4 changes: 2 additions & 2 deletions src/DevelopersSite/Controllers/TutorialController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public TutorialController(WordPressService wordPressService)
[Route("tutorial/{slug?}")]
public async Task<IActionResult> Index(string slug = null)
{
var tutorials = (await wordPressService.GetPostsByCategory((int)PostCategory.Tutorials)).OrderByDescending(o => o.Id);
var firstSlug = tutorials.Select(s => s.Slug).FirstOrDefault();
var tutorials = (await wordPressService.GetPostsByCategory((int)PostCategory.Tutorials))?.OrderByDescending(o => o.Id);
var firstSlug = tutorials?.Select(s => s.Slug).FirstOrDefault();

if (string.IsNullOrEmpty(firstSlug))
{
Expand Down
24 changes: 16 additions & 8 deletions src/DevelopersSite/Services/WordPressService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,25 @@ private async Task<T> SendRequest<T>(string url)

using (var httpClient = new HttpClient())
{
var json = await httpClient.GetStringAsync(url);
cachedValue = JsonConvert.DeserializeObject<T>(json);

var opts = new MemoryCacheEntryOptions()
var json = string.Empty;
try
{
SlidingExpiration = TimeSpan.FromHours(siteConfig.CacheExpirationHours)
};
json = await httpClient.GetStringAsync(url);
cachedValue = JsonConvert.DeserializeObject<T>(json);

memoryCache.Set(url, cachedValue, opts);
var opts = new MemoryCacheEntryOptions()
{
SlidingExpiration = TimeSpan.FromHours(siteConfig.CacheExpirationHours)
};

return cachedValue;
memoryCache.Set(url, cachedValue, opts);

return cachedValue;
}
catch (Exception ex)
{
return cachedValue;
}
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/DevelopersSite/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,18 @@
</div>
<div class="col-md-6">
<div class="news-panel">
@if (Model.News != null)
{
<h3>News, Updates</h3>
<a href="/news" class="read-all pull-right btn btn-default">Read all</a>
<ul class="list-group">
@foreach (var item in Model.News.Count() > 5 ? Model.News.Take(5) : Model.News) {
<li class="list-group-item">
<a href="/news#@(item.Slug)" target="_self">@Html.Raw(item.Title.Rendered)</a>
</li>}
<li class="list-group-item">
<a href="/news#@(item.Slug)" target="_self">@Html.Raw(item.Title.Rendered)</a>
</li>
}
</ul>
}
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/DevelopersSite/project.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.8.0",
"version": "1.8.1",
"dependencies": {
"Microsoft.AspNetCore.Diagnostics": "1.1.0",
"Microsoft.AspNetCore.Mvc": "1.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h3 id="features">Features</h3>
<h2 id="general">General</h2>
<h3 id="request-basics">Request Basics</h3>
<p>Configuration example:</p>
<pre><code class="lang-cs"><span class="hljs-keyword">var</span> configuration = <span class="hljs-keyword">new</span> Configuration<br> {<br> ApiBaseEndpoint = <span class="hljs-keyword">new</span> Uri(<span class="hljs-string">"https://api.slamby.com/CLIENT_ID/"</span>),<br> ApiSecret = <span class="hljs-string">"API_KEY"</span><br> };
<pre><code class="lang-cs"><span class="hljs-keyword">var</span> configuration = <span class="hljs-keyword">new</span> Configuration<br> {<br> ApiBaseEndpoint = <span class="hljs-keyword">new</span> Uri(<span class="hljs-string">"https://europe.slamby.com/CLIENT_ID/"</span>),<br> ApiSecret = <span class="hljs-string">"API_KEY"</span><br> };
</code></pre>
<p>You have to use this <code>configuration</code> object for every <code>Manager</code>.</p>
<p>You can find more details about the Authentication <a href="/docs/api/{{docversion}}/index#authentication">here</a></p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Configuration example:
```cs
var configuration = new Configuration
{
ApiBaseEndpoint = new Uri("https://api.slamby.com/CLIENT_ID/"),
ApiBaseEndpoint = new Uri("https://europe.slamby.com/CLIENT_ID/"),
ApiSecret = "API_KEY"
};
```
Expand Down

0 comments on commit 1760916

Please sign in to comment.