Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gold ticker plugin #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions lib/gold_price/gold_price.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
module Plugins
class GoldTracker < Base
def locals
{
price: current_price,
performance_7d: performance_7d,
performance_90d: performance_90d,
last_updated: last_updated
}
end

private

def current_price
{
value: 1776.83,
currency: 'USD',
formatted: '$1,776.83'
}
end

def performance_7d
{
percentage: 2.5,
value: 43.21,
is_positive: true,
formatted_percentage: '+2.5%',
formatted_value: '$43.21'
}
end

def performance_90d
{
percentage: 5.8,
value: 97.45,
is_positive: true,
formatted_percentage: '+5.8%',
formatted_value: '$97.45'
}
end

def last_updated
"10:30 AM"
end

# eg https://api.metalpriceapi.com/v1/timeframe
# ?api_key=[API_KEY]
# &start_date=2021-04-22
# &end_date=2021-04-23
# &base=USD
# &currencies=EUR,XAU,XAG

# {
# "success": true,
# "base": "USD",
# "start_date": "2021-04-22",
# "end_date": "2021-04-23",
# "rates": {
# "2021-04-22": {
# "EUR": 0.83233837,
# "XAG": 0.03825732,
# "XAU": 0.00056078,
# "USDEUR": 1.20143446,
# "USDXAG": 26.1387886,
# "USDXAU": 1783.2305
# },
# "2021-04-23": {
# "EUR": 0.82657397,
# "XAG": 0.03846131,
# "XAU": 0.0005628,
# "USDEUR": 1.209813079,
# "USDXAG": 26.00015444,
# "USDXAU": 1776.830135
# },
# }

# And for live prices
# https://api.metalpriceapi.com/v1/latest?api_key=x&base=USD&currencies=EUR,XAU,XAG
# "success": true,
# "base": "USD",
# "timestamp": 1740095999,
# "rates": {
# "EUR": 0.95935,
# "USDEUR": 1.0423724397,
# "USDXAG": 32.7383999975,
# "USDXAU": 2937.0136856027,
# "XAG": 0.0305451702,
# "XAU": 0.0003404819
# }
# }
end
end
Binary file added lib/gold_price/previews/full.bmp
Binary file not shown.
Binary file added lib/gold_price/previews/half_horizontal.bmp
Binary file not shown.
Binary file added lib/gold_price/previews/half_vertical.bmp
Binary file not shown.
Binary file added lib/gold_price/previews/quadrant.bmp
Binary file not shown.
38 changes: 38 additions & 0 deletions lib/gold_price/views/full.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<div class="view view--full">
<div class="layout layout--col gap--space-between">
<div class="item">
<div class="meta"></div>
<div class="content">
<span class="value value--xlarge"><%= price[:formatted] %></span>
<span class="label">Gold Price (<%= price[:currency] %>/oz)</span>
</div>
</div>

<div class="w-full b-h-gray-5"></div>

<div class="grid grid--cols-2">
<div class="item">
<div class="meta"></div>
<div class="content">
<span class="title title--small">7-Day Performance</span>
<span class="value value--small"><%= performance_7d[:formatted_percentage] %></span>
<span class="label label--small"><%= performance_7d[:formatted_value] %> Increase</span>
</div>
</div>
<div class="item">
<div class="meta"></div>
<div class="content">
<span class="title title--small">90-Day Performance</span>
<span class="value value--small"><%= performance_90d[:formatted_percentage] %></span>
<span class="label label--small"><%= performance_90d[:formatted_value] %> Increase</span>
</div>
</div>
</div>
</div>

<div class="title_bar">
<img class="image" src="https://usetrmnl.com/images/plugins/simple-analytics--render.svg" />
<span class="title">Gold Price</span>
<span class="instance">Live Tracker</span>
</div>
</div>
33 changes: 33 additions & 0 deletions lib/gold_price/views/half_horizontal.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<div class="view view--half_horizontal">
<div class="layout gap--space-between">
<div class="columns">
<div class="column">
<div class="item">
<div class="meta"></div>
<div class="content">
<span class="value"><%= price[:formatted] %></span>
<span class="label">Gold Price (<%= price[:currency] %>/oz)</span>
</div>
</div>
</div>
<div class="column">
<div class="item">
<div class="meta"></div>
<div class="content">
<span class="title title--small">Performance</span>
<div class="flex gap--xsmall">
<span class="label label--small label--underline">7d: <%= performance_7d[:formatted_percentage] %></span>
<span class="label label--small label--underline">90d: <%= performance_90d[:formatted_percentage] %></span>
</div>
</div>
</div>
</div>
</div>
</div>

<div class="title_bar">
<img class="image" src="https://usetrmnl.com/images/plugins/simple-analytics--render.svg" />
<span class="title">Gold Price</span>
<span class="instance">Live Tracker</span>
</div>
</div>
38 changes: 38 additions & 0 deletions lib/gold_price/views/half_vertical.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<div class="view view--half_vertical">
<div class="layout layout--col gap--medium">
<div class="item">
<div class="meta"></div>
<div class="content">
<span class="value"><%= price[:formatted] %></span>
<span class="label">Gold Price (<%= price[:currency] %>/oz)</span>
</div>
</div>

<div class="w-full b-h-gray-5"></div>

<div class="list">
<div class="item">
<div class="meta"></div>
<div class="content">
<span class="title title--small">7-Day Performance</span>
<span class="value value--small "><%= performance_7d[:formatted_percentage] %></span>
<span class="label label--small"><%= performance_7d[:formatted_value] %> Increase</span>
</div>
</div>
<div class="item">
<div class="meta"></div>
<div class="content">
<span class="title title--small">90-Day Performance</span>
<span class="value value--small "><%= performance_90d[:formatted_percentage] %></span>
<span class="label label--small"><%= performance_90d[:formatted_value] %> Increase</span>
</div>
</div>
</div>
</div>

<div class="title_bar">
<img class="image" src="https://usetrmnl.com/images/plugins/simple-analytics--render.svg" />
<span class="title">Gold Price</span>
<span class="instance">Live Tracker</span>
</div>
</div>
30 changes: 30 additions & 0 deletions lib/gold_price/views/quadrant.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<div class="view view--quadrant">
<div class="layout layout--col">
<div class="item">
<div class="meta"></div>
<div class="content">
<span class="value"><%= price[:formatted] %></span>
<span class="label">Gold (<%= price[:currency] %>/oz)</span>
</div>
</div>

<div class="w-full b-h-gray-5"></div>

<div class="item">
<div class="meta"></div>
<div class="content">
<span class="title title--small">Performance</span>
<div class="flex gap--xsmall">
<span class="label label--small label--underline">7d: <%= performance_7d[:formatted_percentage] %></span>
<span class="label label--small label--underline">90d: <%= performance_90d[:formatted_percentage] %></span>
</div>
</div>
</div>
</div>

<div class="title_bar">
<img class="image" src="https://usetrmnl.com/images/plugins/simple-analytics--render.svg" />
<span class="title">Gold Price</span>
<span class="instance">Live Tracker</span>
</div>
</div>