Skip to content

Commit

Permalink
v0.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
aerth committed Sep 17, 2016
1 parent 44cb825 commit b5c8f54
Show file tree
Hide file tree
Showing 15 changed files with 749 additions and 168 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
bin
pkg
cmd/go-quitter/test
cmd/go-quitter/go-quitter*
cmd/go-quitter/go-quitter/bin/*
cmd/example/example
*~
*.log

57 changes: 29 additions & 28 deletions quitter.go → 00-quitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"net/url"
)

// GetPublic shows 20 new messages. Defaults to a 2 second delay, but can be called with GetPublic(fast) for a quick dump. This and DoSearch() and GetUserTimeline() are some of the only functions that don't require auth.Username + auth.Password
// GetPublic shows 20 new messages.
func (a Social) GetPublic() ([]Quip, error) {
resp, err := apigun.Get(a.Scheme + a.Node + "/api/statuses/public_timeline.json")
if err != nil {
Expand All @@ -46,7 +46,7 @@ func (a Social) GetPublic() ([]Quip, error) {
return quips, err
}

// GetMentions shows 20 newest mentions of your username. Defaults to a 2 second delay, but can be called with GetPublic(fast) for a quick dump.
// GetMentions shows 20 newest mentions of your username.
func (a Social) GetMentions() ([]Quip, error) {
if a.Username == "" || a.Password == "" {
return nil, errors.New("No user/password")
Expand All @@ -62,7 +62,7 @@ func (a Social) GetMentions() ([]Quip, error) {
return quips, err
}

// GetHome shows 20 from home timeline. Defaults to a 2 second delay, but can be called with GetHome(fast) for a quick dump.
// GetHome shows 20 from home timeline.
func (a Social) GetHome() ([]Quip, error) {
if a.Username == "" || a.Password == "" {
return nil, errors.New("No user/password")
Expand All @@ -81,7 +81,7 @@ func (a Social) GetHome() ([]Quip, error) {

}

// command: go-quitter search
// DoSearch returns results for query searchstr. Does send auth info.
func (a Social) DoSearch(searchstr string) ([]Quip, error) {
if a.Username == "" || a.Password == "" {
return nil, errors.New("No user/password")
Expand All @@ -106,7 +106,7 @@ func (a Social) DoSearch(searchstr string) ([]Quip, error) {

}

// command: go-quitter psearch
// DoPublicSearch returns results for query searchstr. Does not send auth info.
func (a Social) DoPublicSearch(searchstr string) ([]Quip, error) {
if searchstr == "" {
return nil, errors.New("No query")
Expand Down Expand Up @@ -135,7 +135,7 @@ func (a Social) DoPublicSearch(searchstr string) ([]Quip, error) {

}

// command: go-quitter follow
// DoFollow sends a request to follow a user
func (a Social) DoFollow(followstr string) (user User, err error) {
if a.Username == "" || a.Password == "" {
return user, errors.New("No user/password")
Expand Down Expand Up @@ -163,7 +163,7 @@ func (a Social) DoFollow(followstr string) (user User, err error) {

}

// go-quitter command: go-quitter unfollow
// DoUnfollow sends a request to unfollow a user
func (a Social) DoUnfollow(followstr string) (user User, err error) {
if a.Username == "" || a.Password == "" {
return user, errors.New("No user/password")
Expand All @@ -185,7 +185,7 @@ func (a Social) DoUnfollow(followstr string) (user User, err error) {

}

// go-quitter command: go-quitter user
// GetUserTimeline returns a userlookup's timeline
func (a Social) GetUserTimeline(userlookup string) ([]Quip, error) {

path := "/api/statuses/user_timeline.json?screen_name=" + userlookup
Expand Down Expand Up @@ -223,7 +223,8 @@ func (a Social) PostNew(content string) (q Quip, err error) {

}

// command: go-quitter groups
// ListAllGroups lists each group in a.Node
// Some nodes don't return anything.
func (a Social) ListAllGroups() ([]Group, error) {
if a.Username == "" || a.Password == "" {
return nil, errors.New("No user/password")
Expand All @@ -241,7 +242,7 @@ func (a Social) ListAllGroups() ([]Group, error) {
return groups, err
}

// command: go-quitter mygroups
// ListMyGroups lists each group a a.Username is a member of
func (a Social) ListMyGroups() ([]Group, error) {
if a.Username == "" || a.Password == "" {
return nil, errors.New("No user/password")
Expand All @@ -260,24 +261,24 @@ func (a Social) ListMyGroups() ([]Group, error) {

}

// command: go-quitter join ____
func (a Social) JoinGroup(groupstr string) (g Group, err error) {
// JoinGroup sends a request to join group grp.
func (a Social) JoinGroup(grp string) (g Group, err error) {
if a.Username == "" || a.Password == "" {
return g, errors.New("No user/password")
}

if groupstr == "" {
if grp == "" {
return g, errors.New("Blank group detected. Not going furthur.")
}
v := url.Values{}

v.Set("group_name", groupstr)
v.Set("group_id", groupstr)
v.Set("id", groupstr)
v.Set("nickname", groupstr)
groupstr = url.Values.Encode(v)
v.Set("group_name", grp)
v.Set("group_id", grp)
v.Set("id", grp)
v.Set("nickname", grp)
grp = url.Values.Encode(v)

path := "/api/statusnet/groups/join.json?" + groupstr
path := "/api/statusnet/groups/join.json?" + grp
body, err := a.FirePOST(path, v)
if err != nil {
return g, err
Expand All @@ -288,23 +289,23 @@ func (a Social) JoinGroup(groupstr string) (g Group, err error) {
return g, err
}

// command: go-quitter part ____
func (a Social) PartGroup(groupstr string) (g Group, err error) {
// PartGroup sends a request to part group grp.
func (a Social) PartGroup(grp string) (g Group, err error) {
if a.Username == "" || a.Password == "" {
return g, errors.New("No user/password")
}

if groupstr == "" {
if grp == "" {
return g, errors.New("Blank group detected. Not going furthur.")
}

v := url.Values{}
v.Set("group_name", groupstr)
v.Set("group_id", groupstr)
v.Set("id", groupstr)
v.Set("nickname", groupstr)
groupstr = url.Values.Encode(v)
path := "/api/statusnet/groups/leave.json?" + groupstr
v.Set("group_name", grp)
v.Set("group_id", grp)
v.Set("id", grp)
v.Set("nickname", grp)
grp = url.Values.Encode(v)
path := "/api/statusnet/groups/leave.json?" + grp
body, err := a.FirePOST(path, v)
if err != nil {
return g, err
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
19 changes: 19 additions & 0 deletions quitter_test.go → 08-quitter_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
Some example functions for godoc
*/

package quitter_test

import (
Expand All @@ -7,6 +11,21 @@ import (
quitter "github.com/aerth/go-quitter"
)

func Example() {
q := quitter.NewSocial()
q.Username = "username"
q.Password = "password"
q.Node = "localhost"
quips, err := q.GetHome()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
for _, quip := range quips {
fmt.Printf("%s %s", quip.IdStr, quip.Text)
}
}

func ExampleNewSocial() {
q := quitter.NewSocial()
q.Username = "username"
Expand Down
42 changes: 42 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# aerth [https://isupon.us]
# https://github.com/aerth

NAME=go-quitter
VERSION=0.0.9
RELEASE:=v${VERSION}.$(shell git rev-parse --verify --short HEAD)
PREFIX=/usr/local/bin
all:
@echo
@echo "building go-quitter command line GNU Social client to"
@echo " \"bin/${NAME}-${RELEASE}\""
@echo
@mkdir -p bin
@go build -v -o bin/${NAME}-${RELEASE} ./cmd/go-quitter

deps:
go get -d ./...


install:
sudo mv bin/${NAME}-${RELEASE} ${PREFIX}/${NAME}


update: upgrade deps all install

upgrade:
git pull origin master

cross:
mkdir -p bin
GOOS=windows GOARCH=386 go build -v -o bin/${NAME}-${RELEASE}-WIN32.exe
GOOS=windows GOARCH=amd64 go build -v -o bin/${NAME}-${RELEASE}-WIN64.exe
GOOS=darwin GOARCH=386 go build -v -o bin/${NAME}-${RELEASE}-OSX-x86
GOOS=darwin GOARCH=amd64 go build -v -o bin/${NAME}-${RELEASE}-OSX-amd64
GOOS=linux GOARCH=amd64 go build -v -o bin/${NAME}-${RELEASE}-linux-amd64
GOOS=linux GOARCH=386 go build -v -o bin/${NAME}-${RELEASE}-linux-x86
GOOS=freebsd GOARCH=amd64 go build -v -o bin/${NAME}-${RELEASE}-freebsd-amd64
GOOS=freebsd GOARCH=386 go build -v -o bin/${NAME}-${RELEASE}-freebsd-x86
GOOS=openbsd GOARCH=amd64 go build -v -o bin/${NAME}-${RELEASE}-openbsd-amd64
GOOS=openbsd GOARCH=386 go build -v -o bin/${NAME}-${RELEASE}-openbsd-x86
GOOS=netbsd GOARCH=amd64 go build -v -o bin/${NAME}-${RELEASE}-netbsd-amd64
GOOS=netbsd GOARCH=386 go build -v -o bin/${NAME}-${RELEASE}-netbsd-x86
79 changes: 45 additions & 34 deletions cmd/example/main.go
Original file line number Diff line number Diff line change
@@ -1,54 +1,65 @@
/*
Copyright 2016 aerth
This is a simple example program showing
the usage of the quitter (GNU Social) library.
You can import the libary as whatever name you want.
Default is quitter, here it has an alias of qw.
*/
package main

import (
qw "github.com/aerth/go-quitter"
"fmt"
"os"
"fmt"

qw "github.com/aerth/go-quitter"
)

func main() {

if len(os.Args) == 2 && os.Args[1] == "home" {
q := qw.NewSocial()
q.Username = "obviouslychangethis"
q.Password = "nopassword?"
q.Username = "username"
q.Password = "nopassword"
q.Node = "gnusocial.de"
quips, err := q.GetHome(false)
if err != nil {
fmt.Println(err)
}
for i := range quips {
if quips[i].User.Screenname == quips[i].User.Name {
fmt.Printf("[@" + quips[i].User.Screenname + "] " + quips[i].Text + "\n\n")
} else {
fmt.Printf("@" + quips[i].User.Screenname + " [" + quips[i].User.Name + "] " + quips[i].Text + "\n\n")
}
}
os.Exit(1)
if err != nil {
fmt.Println(err)
}
for i := range quips {
if quips[i].User.Screenname == quips[i].User.Name {
fmt.Printf("[@" + quips[i].User.Screenname + "] " + quips[i].Text + "\n\n")
} else {
fmt.Printf("@" + quips[i].User.Screenname + " [" + quips[i].User.Name + "] " + quips[i].Text + "\n\n")
}
}
os.Exit(1)
// Return: Could not authenticate you.
}

if len(os.Args) == 2 && os.Args[1] == "public" {
q2 := qw.NewSocial()
q2.Node = "gnusocial.de"
quips, err := q2.GetPublic(true)
if err != nil {
fmt.Println(err)
}
for i := range quips {
if quips[i].User.Screenname == quips[i].User.Name {
fmt.Printf("[@" + quips[i].User.Screenname + "] " + quips[i].Text + "\n\n")
} else {
fmt.Printf("@" + quips[i].User.Screenname + " [" + quips[i].User.Name + "] " + quips[i].Text + "\n\n")
}
}
os.Exit(1)


}else {

// Example usage
fmt.Println(os.Args[0], "public")
fmt.Println(os.Args[0], "home")
}
if err != nil {
fmt.Println(err)
}
for i := range quips {
if quips[i].User.Screenname == quips[i].User.Name {
fmt.Printf("[@" + quips[i].User.Screenname + "] " + quips[i].Text + "\n\n")
} else {
fmt.Printf("@" + quips[i].User.Screenname + " [" + quips[i].User.Name + "] " + quips[i].Text + "\n\n")
}
}
os.Exit(1)

} else {

// Example usage
fmt.Println(os.Args[0], "public")
fmt.Println(os.Args[0], "home")
}
}
Loading

0 comments on commit b5c8f54

Please sign in to comment.