Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Herzog committed Sep 8, 2016
0 parents commit 4affb27
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2016 Benjamin Herzog

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Binary file added alfred
Binary file not shown.
75 changes: 75 additions & 0 deletions alfred.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package main

import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"strings"

"github.com/BenchR267/goalfred"
)

func main() {
queryTerms := os.Args[1:]

resp := goalfred.NewResponse()

pods := getPods(strings.Join(queryTerms, "%20"))

for _, pod := range pods {
resp.AddItem(pod)
}

resp.Print()
}

type Pod struct {
Link string
Name string `json:"id"`
Summary string
Version string
Platforms []string
}

func (p Pod) Documentation() string {
return fmt.Sprintf("http://cocoadocs.org/docsets/%s/%s", p.Name, p.Version)
}

func (p Pod) Item() *goalfred.Item {

title := fmt.Sprintf("%s (%s)", p.Name, p.Version)
instruction := fmt.Sprintf("pod '%s', '%s'", p.Name, p.Version)
i := goalfred.NewItem(title, p.Summary, p.Link)
i.Mod.Cmd = goalfred.NewModElement(p.Documentation(), "Open documentation!")
i.Mod.Alt = goalfred.NewModElement(instruction, "Copy pod install instructions")
return i
}

type Response struct {
Allocations [][]json.RawMessage `json:"allocations"`
}

func getPods(searchTerm string) []Pod {

url := fmt.Sprintf("https://search.cocoapods.org/api/v1/pods.picky.hash.json?query=%v&ids=20&offset=0&sort=quality", searchTerm)

resp, err := http.Get(url)
if err != nil {
panic(err)
}

defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)

var response Response
json.Unmarshal(body, &response)

rawJson := response.Allocations[0][5]

var pods []Pod
err = json.Unmarshal(rawJson, &pods)

return pods
}

0 comments on commit 4affb27

Please sign in to comment.