getOpenGraphDataFromResponse method

Map<String, dynamic> getOpenGraphDataFromResponse (
  1. Response response
)

Implementation

static Map<String, dynamic> getOpenGraphDataFromResponse(http.Response response) {
  var requiredAttributes = ['title', 'image'];
  var data = {};

  if (response.statusCode == 200) {
    var document = parser.parse(utf8.decode(response.bodyBytes));
    var openGraphMetaTags = _getOpenGraphData(document);

    openGraphMetaTags.forEach((element) {
      var ogTagTitle = element.attributes['property'].split("og:")[1];
      var ogTagValue = element.attributes['content'];

      if ((ogTagValue != null && ogTagValue != "") ||
          requiredAttributes.contains(ogTagTitle)) {
        if (ogTagValue == null || ogTagValue.length == 0) {
          ogTagValue = _scrapeAlternateToEmptyValue(ogTagTitle, document);
        }
        data[ogTagTitle] = ogTagValue;
      }
    });
  }

  return data;
}