Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
guru
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DeStream-public
guru
Commits
ebe8f8e8
Commit
ebe8f8e8
authored
Oct 17, 2018
by
Clint Mourlevat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finishing autorefreshing with SignalR
parent
9ace9991
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
4 deletions
+60
-4
ApiController.cs
Controllers/ApiController.cs
+48
-0
TickerApi.cs
Models/TickerApi.cs
+8
-0
Index.cshtml
Views/Home/Index.cshtml
+4
-4
No files found.
Controllers/ApiController.cs
0 → 100644
View file @
ebe8f8e8
using
System
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.Extensions.Caching.Memory
;
using
Newtonsoft.Json
;
using
Stratis.Guru.Models
;
namespace
Stratis.Guru.Controllers
{
[
Route
(
"api"
)]
[
ApiController
]
public
class
ApiController
:
ControllerBase
{
private
readonly
IMemoryCache
_memoryCache
;
public
ApiController
(
IMemoryCache
memoryCache
)
{
_memoryCache
=
memoryCache
;
}
[
HttpGet
]
[
Route
(
"price"
)]
public
ActionResult
<
object
>
Price
(
bool
stringify
)
{
try
{
dynamic
coinmarketcap
=
JsonConvert
.
DeserializeObject
(
_memoryCache
.
Get
(
"Coinmarketcap"
).
ToString
());
if
(
stringify
)
{
return
new
TickerApi
{
UsdPrice
=
coinmarketcap
.
data
.
quotes
.
USD
.
price
.
ToString
(
"C"
),
Last24Change
=
(
coinmarketcap
.
data
.
quotes
.
USD
.
percent_change_24h
/
100
).
ToString
(
"P2"
)
};
}
return
new
Ticker
{
UsdPrice
=
coinmarketcap
.
data
.
quotes
.
USD
.
price
,
Last24Change
=
coinmarketcap
.
data
.
quotes
.
USD
.
percent_change_24h
/
100
};
}
catch
(
Exception
e
)
{
//TODO: implement errors / logging
return
null
;
}
}
}
}
\ No newline at end of file
Models/TickerApi.cs
0 → 100644
View file @
ebe8f8e8
namespace
Stratis.Guru.Models
{
public
class
TickerApi
{
public
string
UsdPrice
{
get
;
set
;
}
public
string
Last24Change
{
get
;
set
;
}
}
}
\ No newline at end of file
Views/Home/Index.cshtml
View file @
ebe8f8e8
...
...
@@ -28,13 +28,13 @@
<script type="text/javascript">
$(document).ready(function() {
var stratisPrice = @Model.UsdPrice;
var signalr = new signalR.HubConnectionBuilder().withUrl("/update").build();
signalr.on("UpdateTicker", function (message) {
$.getJSON("/api/price?stringify=true", function(e) {
$("#amount").text(e.usdPrice);
$("#lastchange").text(e.last24Change);
});
});
signalr.start();
$(".click-edit").click(function() {
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment