Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

Allow importing collections from gist

Liyas Thomas2978c8adfea8
diff --git a/components/collections/import-export-collections.vue b/components/collections/import-export-collections.vue
index c67d3e286..1e33d59cf 100644
--- a/components/collections/import-export-collections.vue
+++ b/components/collections/import-export-collections.vue
@@ -14,15 +14,17 @@
<div
v-tooltip="{
content:
- !fb.currentUser &&
this.$store.state.postwoman.providerInfo.providerId !== 'github.com'
? $t('login_with_github_to') + $t('create_secret_gist')
: null,
}"
>
+ <button class="icon" @click="readCollectionGist" v-close-popover>
+ <i class="material-icons">code</i>
+ <span>{{ $t("import_from_gist") }}</span>
+ </button>
<button
:disabled="
- !fb.currentUser &&
this.$store.state.postwoman.providerInfo.providerId !== 'github.com'
"
class="icon"
@@ -153,6 +155,26 @@ export default {
console.log(error)
})
},
+ async readCollectionGist() {
+ let gist = prompt(this.$t("enter_gist_url"))
+ if (!gist) return
+ await this.$axios
+ .$get(`https://api.github.com/gists/${gist.split("/").pop()}`, {
+ headers: {
+ Accept: "application/vnd.github.v3+json",
+ },
+ })
+ .then((response) => {
+ let collections = JSON.parse(Object.values(response.files)[0].content)
+ this.$store.commit("postwoman/replaceCollections", collections)
+ this.fileImported()
+ this.syncToFBCollections()
+ })
+ .catch((error) => {
+ this.failedImport()
+ console.log(error)
+ })
+ },
hideModal() {
this.$emit("hide-modal")
},
diff --git a/lang/en-US.json b/lang/en-US.json
index 84056defd..bf22fc4f9 100644
--- a/lang/en-US.json
+++ b/lang/en-US.json
@@ -297,5 +297,7 @@
"select_environment": "Select environment",
"login_with_github_to": "Login with GitHub to ",
"create_secret_gist": "Create secret Gist",
- "gist_created": "Gist created"
+ "gist_created": "Gist created",
+ "import_from_gist": "Import from Gist",
+ "enter_gist_url": "Enter Gist URL"
}