Payserv_GoogleFinance - Version 1.0.3

Version Notes

22/01/2014
- Repackage

25/03/2011
- First release.
- Since Google Finance site does not display any Terms & Conditions, it is assumed it is ok to use.

Download this release

Release Info

Developer Michael Mussulis
Extension Payserv_GoogleFinance
Version 1.0.3
Comparing to
See all releases


Code changes from version 1.0.2 to 1.0.3

app/code/local/Payserv/GoogleFinance/Model/Google.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Payserv
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category Payserv
16
+ * @package Payserv
17
+ * @copyright Copyright (c) 2009 JT
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ /**
22
+ * Currency rate import model (From google.com)
23
+ *
24
+ * @category Payserv
25
+ * @package Payserv
26
+ * @author Pay Serv Internatioal SRL
27
+ */
28
+ //class JT_Directory_Model_Currency_Import_Yahoofinance extends Mage_Directory_Model_Currency_Import_Abstract
29
+ class Payserv_GoogleFinance_Model_Google extends Mage_Directory_Model_Currency_Import_Abstract
30
+ {
31
+ //protected $_url = 'http://quote.yahoo.com/d/quotes.csv?s==X&f=l1&e=.csv';
32
+ protected $_url = 'http://www.google.com/finance/converter?a=1&from={{CURRENCY_FROM}}&to={{CURRENCY_TO}}';
33
+ protected $_messages = array();
34
+
35
+ protected function _convert($currencyFrom, $currencyTo, $retry=0)
36
+ {
37
+ $url = str_replace('{{CURRENCY_FROM}}', $currencyFrom, $this->_url);
38
+ $url = str_replace('{{CURRENCY_TO}}', $currencyTo, $url);
39
+
40
+ try {
41
+ sleep(1); //Be nice to Google, they don't have a lot of hi-spec servers
42
+
43
+ $ch = curl_init();
44
+
45
+ // set URL and other appropriate options
46
+ curl_setopt($ch, CURLOPT_URL, $url);
47
+ curl_setopt($ch, CURLOPT_HEADER, 0);
48
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
49
+
50
+ // grab URL and pass it to the browser
51
+ $res = curl_exec($ch);
52
+ curl_close($ch);
53
+
54
+ if(preg_match("'<span class=bld>([0-9\.]+)\s\w+</span>'", $res, $m))
55
+ $exchange_rate = $m[1];
56
+
57
+ if( !$exchange_rate ) {
58
+ $this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s', $this->_url);
59
+ return null;
60
+ }
61
+
62
+ return (float) $exchange_rate * 1.0; // change 1.0 to influence rate;
63
+ }
64
+ catch (Exception $e) {
65
+ if( $retry == 0 ) {
66
+ $this->_convert($currencyFrom, $currencyTo, 1);
67
+ } else {
68
+ $this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s', $url);
69
+ }
70
+ }
71
+ }
72
+ }
app/code/local/Payserv/GoogleFinance/etc/config.xml ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+
3
+ <config>
4
+
5
+ <modules>
6
+ <Payserv_GoogleFinance>
7
+ <version>1.0.0</version>
8
+ </Payserv_GoogleFinance>
9
+ </modules>
10
+
11
+ <global>
12
+ <models>
13
+ <GoogleFinance>
14
+ <class>Payserv_GoogleFinance_Model</class>
15
+ </GoogleFinance>
16
+ </models>
17
+ <currency>
18
+ <import>
19
+ <services>
20
+ <GoogleFinance>
21
+ <name>Google Finance</name>
22
+ <model>Payserv_GoogleFinance_Model_Google</model>
23
+ </GoogleFinance>
24
+ </services>
25
+ </import>
26
+ </currency>
27
+ </global>
28
+ </config>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Payserv_GoogleFinance</name>
4
- <version>1.0.2</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
@@ -15,9 +15,9 @@
15
  - First release.&#xD;
16
  - Since Google Finance site does not display any Terms &amp;amp; Conditions, it is assumed it is ok to use.</notes>
17
  <authors><author><name>Michael Mussulis</name><user>mpgjunky</user><email>michael@payserv.ro</email></author></authors>
18
- <date>2014-01-22</date>
19
- <time>21:16:24</time>
20
- <contents><target name="mageetc"><dir name="modules"><file name="Payserv_GoogleFinance.xml" hash="01e968797e7f8e021398b0605fbc32b0"/></dir></target></contents>
21
  <compatible/>
22
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
23
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Payserv_GoogleFinance</name>
4
+ <version>1.0.3</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
15
  - First release.&#xD;
16
  - Since Google Finance site does not display any Terms &amp;amp; Conditions, it is assumed it is ok to use.</notes>
17
  <authors><author><name>Michael Mussulis</name><user>mpgjunky</user><email>michael@payserv.ro</email></author></authors>
18
+ <date>2014-01-23</date>
19
+ <time>06:58:07</time>
20
+ <contents><target name="mageetc"><dir name="modules"><file name="Payserv_GoogleFinance.xml" hash="01e968797e7f8e021398b0605fbc32b0"/></dir></target><target name="magelocal"><dir name="Payserv"><dir name="GoogleFinance"><dir name="Model"><file name="Google.php" hash="d3c2b6fc79943484760eaec84736d14a"/></dir><dir name="etc"><file name="config.xml" hash="f9ce58a2c5092b79e7e62ef8e7c1da00"/></dir></dir></dir></target></contents>
21
  <compatible/>
22
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
23
  </package>