Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
SUSE:SLE-12-SP2:GA
perl-Finance-Quote
perl-Finance-Quote-64897-0002-support-palladium...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File perl-Finance-Quote-64897-0002-support-palladium-lookup.patch of Package perl-Finance-Quote
https://rt.cpan.org/Public/Bug/Display.html?id=64897 This is a merge of the patch provided by the bug tracker to the upstream GIT snapshot. Date: Tue Jan 18 15:29:56 2011 stephan.ebelt [...] gmx.net - Ticket created Subject: GoldMoney site has changed (patch attached) the goldmoney site has been updated recently and they now allow to purchase palladium as well. attached are two patches for the GoldMoney.pm module and its test. From e410b33151f394d76219a0f0de24de232f4e8750 Mon Sep 17 00:00:00 2001 From: Stephan Ebelt <ste@shared-files.de> Date: Tue, 18 Jan 2011 20:47:11 +0100 Subject: [PATCH] support 'palladium' lookup --- lib/Finance/Quote/GoldMoney.pm | 46 +++++++++++++++++++++++++++++++-------- t/goldmoney.t | 13 +++++++++- 2 files changed, 47 insertions(+), 12 deletions(-) Index: Finance-Quote-1.18/lib/Finance/Quote/GoldMoney.pm =================================================================== --- Finance-Quote-1.18.orig/lib/Finance/Quote/GoldMoney.pm +++ Finance-Quote-1.18/lib/Finance/Quote/GoldMoney.pm @@ -7,7 +7,7 @@ # Copyright (C) 2000, Brent Neal <brentn@users.sourceforge.net> # Copyright (C) 2000, Volker Stuerzl <volker.stuerzl@gmx.de> # Copyright (C) 2006, Klaus Dahlke <klaus.dahlke@gmx.de> -# Copyright (C) 2008, Stephan Ebelt <stephan.ebelt@gmx.de> +# Copyright (C) 2011, Stephan Ebelt <ste -at- shared-files -dot- de> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -31,7 +31,6 @@ require 5.005; require Crypt::SSLeay; use HTTP::Request::Common; -use HTML::TableExtract; use HTML::TreeBuilder; use strict; @@ -51,7 +50,8 @@ sub labels { # goldmoney($quoter, @symbols) # -# - get 'gold' and 'silver' spot rates from goldmoney.com +# - get 'gold', 'silver', 'platinum' and 'palladium' spot rates from +# goldmoney.com # - error out properly (that is: ignore) all other symbols # sub goldmoney { @@ -64,12 +64,14 @@ sub goldmoney { my $ua = $quoter->user_agent; my (%symbolhash, @q, %info); my ( - $html_string, $tree, $gold_gg, $gold_oz, $silver_oz, $platinum_oz, $platinum_pg, $currency + $html_string, $tree, $gold_oz, $silver_oz, $platinum_oz, + $palladium_oz, $currency ); my $_want_gold = 0; my $_want_silver = 0; my $_want_platinum = 0; + my $_want_palladium = 0; # - feed all requested symbols into %info (to be returned later) # - set error state to false by default @@ -86,8 +88,10 @@ sub goldmoney { $_want_silver = 1; } elsif($s eq 'platinum') { $_want_platinum = 1; + } elsif($s eq 'palladium') { + $_want_palladium = 1; } else { - $info{$s,'errormsg'} = "No data returned (note: this module only works for 'gold' and 'silver')"; + $info{$s,'errormsg'} = "No data returned (note: this module only works for 'gold', 'silver', 'platinum' and 'palladium')"; } } @@ -182,6 +186,28 @@ sub goldmoney { $info{'platinum','currency'} = $currency; $info{'platinum','success'} = 1; } + + # get palladium rate + # + if( $_want_palladium ) { + $_ = $tree->look_down("_tag", "span", "id", "spot-price-palladium-oz"); + + if( $_->as_text =~ /([\d,]*\.\d*)/ ) { + $palladium_oz = $1; + $palladium_oz =~ s/,//g; + } + + # assemble final dataset + # - take "now" as date/time as the site is always current and does + # not provide this explicitly - so there is a time-slip + $quoter->store_date(\%info, 'palladium', {isodate => _goldmoney_time('isodate')}); + $info{'palladium','time'} = _goldmoney_time('time'); + $info{'palladium','name'} = 'Palladium Spot'; + $info{'palladium','last'} = $palladium_oz; + $info{'palladium','price'} = $palladium_oz; + $info{'palladium','currency'} = $currency; + $info{'palladium','success'} = 1; + } } return wantarray() ? %info : \%info; @@ -229,12 +255,12 @@ Finance::Quote::GoldMoney - obtain spot $q = Finance::Quote->new; - %rates = $q->fetch('goldmoeny','gold', 'silver', 'platinum'); + %rates = $q->fetch('goldmoney','gold', 'silver', 'platinum', 'palladium'); =head1 DESCRIPTION -This module obtains current spot rates for 'gold', 'silver' and -'platinum' from Goldmoney (http://www.goldmoney.com). All other +This module obtains current spot rates for 'gold', 'silver', 'platinum' +and 'palladium' from GoldMoney (http://goldmoney.com). All other symbols are ignored. Information returned by this module is governed by Net Transactions @@ -248,8 +274,8 @@ The following labels are returned by Fin - exchange - name - date, time - - price (per ounce), price_gg (per goldgram, gold only), - price_pg (per platinumgram, platinum only) + - price (per ounce) + - last (per ounce, same as 'price') - currency =head1 SEE ALSO Index: Finance-Quote-1.18/t/goldmoney.t =================================================================== --- Finance-Quote-1.18.orig/t/goldmoney.t +++ Finance-Quote-1.18/t/goldmoney.t @@ -7,12 +7,12 @@ if (not $ENV{ONLINE_TEST}) { plan skip_all => 'Set $ENV{ONLINE_TEST} to run this test'; } -plan tests => 23; +plan tests => 31; # Test GoldMoney functions. my $q = Finance::Quote->new("GoldMoney"); $q->set_currency('EUR'); -my %quotes = $q->fetch("goldmoney","gold", "silver", "platinum", "BOGUS"); +my %quotes = $q->fetch("goldmoney","gold", "silver", "platinum", "palladium", "BOGUS"); ok(%quotes); # Check that sound information is returned for gold, silver and platinum. @@ -34,6 +34,13 @@ ok($quotes{"platinum","currency"} eq "EU ok(length($quotes{"platinum","date"}) > 0); ok(length($quotes{"platinum","time"}) > 0); +ok($quotes{"palladium","success"}, 'palladium price lookup'); +ok($quotes{"palladium","last"} > 0); +ok( $quotes{"palladium","last"} !~ /^0/ ); +ok($quotes{"palladium","currency"} eq "EUR"); +ok(length($quotes{"palladium","date"}) > 0); +ok(length($quotes{"palladium","time"}) > 0); + my $year = (localtime())[5] + 1900; ok((substr($quotes{"gold","isodate"},0,4) == $year)); ok((substr($quotes{"gold","date"},6,4) == $year)); @@ -41,6 +48,8 @@ ok((substr($quotes{"silver","isodate"},0 ok((substr($quotes{"silver","date"},6,4) == $year)); ok((substr($quotes{"platinum","isodate"},0,4) == $year)); ok((substr($quotes{"platinum","date"},6,4) == $year)); +ok((substr($quotes{"palladium","isodate"},0,4) == $year)); +ok((substr($quotes{"palladium","date"},6,4) == $year)); # Check that a bogus symbol returns no-success. ok(! $quotes{"BOGUS","success"});
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor