Skip to content

Instantly share code, notes, and snippets.

@matt-thomson
Created July 26, 2014 12:59
Show Gist options
  • Save matt-thomson/218e0433b9ce0aa1af2a to your computer and use it in GitHub Desktop.
Save matt-thomson/218e0433b9ce0aa1af2a to your computer and use it in GitHub Desktop.
Mendeley Wolfram Language example
clientId = "..."
clientSecret = "..."
CreateAuthHeader := "Basic " <> ExportString[clientId <> ":" <> clientSecret, "Base64"]
GetTokenJson := URLFetch["https://api.mendeley.com/oauth/token",
"Method" -> "POST",
"Headers" -> {"Authorization" -> CreateAuthHeader },
"BodyData" -> "scope=all&grant_type=client_credentials"
]
GetAccessToken := "access_token" /. ImportString[GetTokenJson, "JSON"]
GetDocJson[doi_] := URLFetch["https://api.mendeley.com/catalog",
"Headers" -> {"Authorization" -> "Bearer " <> GetAccessToken },
"Parameters" -> {"doi" -> doi, "view" -> "stats"}
]
GetDoc[doi_] := First[ImportString[GetDocJson[doi], "JSON"]]
GetCounts[doi_] := Association["reader_count_by_country" /. GetDoc[doi]]
GetInterpretedCounts[doi_] := KeyMap[Interpreter["Country"], GetCounts[doi]]
DrawMap[doi_] := GeoRegionValuePlot[GetInterpretedCounts[doi], "ImageSize"->Larger]
CloudDeploy[FormFunction[{"DOI" -> "String"}, DrawMap[#DOI] &, "PNG"]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment