| 76 | } |
| 77 | |
| 78 | std::unique_ptr<VersionInfo> VersionInfo::fetch (const juce::String& endpoint) |
| 79 | { |
| 80 | juce::URL latestVersionURL ("https://api.github.com/repos/jerryuhoo/Fire/releases/" + endpoint); |
| 81 | std::unique_ptr<juce::InputStream> inStream (latestVersionURL.createInputStream (juce::URL::InputStreamOptions (juce::URL::ParameterHandling::inAddress).withConnectionTimeoutMs (5000))); |
| 82 | |
| 83 | if (inStream == nullptr) |
| 84 | return nullptr; |
| 85 | |
| 86 | auto content = inStream->readEntireStreamAsString(); |
| 87 | auto latestReleaseDetails = juce::JSON::parse (content); |
| 88 | |
| 89 | auto* json = latestReleaseDetails.getDynamicObject(); |
| 90 | |
| 91 | if (json == nullptr) |
| 92 | return nullptr; |
| 93 | |
| 94 | auto versionString = json->getProperty ("tag_name").toString(); |
| 95 | |
| 96 | if (versionString.isEmpty()) |
| 97 | return nullptr; |
| 98 | |
| 99 | auto* assets = json->getProperty ("assets").getArray(); |
| 100 | |
| 101 | if (assets == nullptr) |
| 102 | return nullptr; |
| 103 | |
| 104 | auto releaseNotes = json->getProperty ("body").toString(); |
| 105 | std::vector<VersionInfo::Asset> parsedAssets; |
| 106 | |
| 107 | for (auto& asset : *assets) |
| 108 | { |
| 109 | if (auto* assetJson = asset.getDynamicObject()) |
| 110 | { |
| 111 | parsedAssets.push_back ({ assetJson->getProperty ("name").toString(), |
| 112 | assetJson->getProperty ("url").toString() }); |
| 113 | jassert (parsedAssets.back().name.isNotEmpty()); |
| 114 | jassert (parsedAssets.back().url.isNotEmpty()); |
| 115 | } |
| 116 | else |
| 117 | { |
| 118 | jassertfalse; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | return std::unique_ptr<VersionInfo> (new VersionInfo { versionString, releaseNotes, std::move (parsedAssets) }); |
| 123 | } |
nothing calls this directly
no outgoing calls
no test coverage detected