Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

docs($http): update YQL currency exchange API example #16137

Closed
Closed
Show file tree
Hide file tree
Changes from 5 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
19 changes: 5 additions & 14 deletions docs/content/guide/concepts.ngdoc
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ Right now, the `InvoiceController` contains all logic of our example. When the a
is a good practice to move view-independent logic from the controller into a
<a name="service">{@link services service}</a>, so it can be reused by other parts
of the application as well. Later on, we could also change that service to load the exchange rates
from the web, e.g. by calling the Yahoo Finance API, without changing the controller.
from the web, e.g. by calling the <a href="http://fixer.io" title="fixer" target="_blank">Fixer.io</a> exchange rate API, without changing the controller.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.ngdoc files understand markdown. You can use [Fixer.io](http://fixer.io) for brevity.


Let's refactor our example and move the currency conversion into a service in another file:

Expand Down Expand Up @@ -300,7 +300,7 @@ to something shorter like `a`.

## Accessing the backend

Let's finish our example by fetching the exchange rates from the Yahoo Finance API.
Let's finish our example by fetching the exchange rates from the <a href="http://fixer.io" title="fixer" target="_blank">Fixer.io</a> exchange rate API.
The following example shows how this is done with AngularJS:

<example name="guide-concepts-3" ng-app-included="true">
Expand All @@ -323,10 +323,6 @@ The following example shows how this is done with AngularJS:
<file name="finance3.js">
angular.module('finance3', [])
.factory('currencyConverter', ['$http', function($http) {
var YAHOO_FINANCE_URL_PATTERN =
'//query.yahooapis.com/v1/public/yql?q=select * from ' +
'yahoo.finance.xchange where pair in ("PAIRS")&format=json&' +
'env=store://datatables.org/alltableswithkeys';
var currencies = ['USD', 'EUR', 'CNY'];
var usdToForeignRates = {};

Expand All @@ -335,15 +331,10 @@ The following example shows how this is done with AngularJS:
};

var refresh = function() {
var url = YAHOO_FINANCE_URL_PATTERN.
replace('PAIRS', 'USD' + currencies.join('","USD'));
var url = 'https://api.fixer.io/latest?base=USD&symbols=' + currencies.join(",");
return $http.get(url).then(function(response) {
var newUsdToForeignRates = {};
angular.forEach(response.data.query.results.rate, function(rate) {
var currency = rate.id.substring(3,6);
newUsdToForeignRates[currency] = window.parseFloat(rate.Rate);
});
usdToForeignRates = newUsdToForeignRates;
usdToForeignRates = response.data.rates;
usdToForeignRates['USD'] = 1;
});
};

Expand Down
2 changes: 1 addition & 1 deletion docs/content/guide/security.ngdoc
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Protection from JSON Hijacking is provided if the server prefixes all JSON reque
AngularJS will automatically strip the prefix before processing it as JSON.
For more information please visit {@link $http#json-vulnerability-protection JSON Hijacking Protection}.

Bear in mind that calling `$http.jsonp`, like in [our Yahoo! finance example](https://docs.angularjs.org/guide/concepts#accessing-the-backend),
Bear in mind that calling `$http.jsonp`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the ,. It is not necessary any more.

gives the remote server (and, if the request is not secured, any Man-in-the-Middle attackers)
instant remote code execution in your application: the result of these requests is handed off
to the browser as regular `<script>` tag.
Expand Down