Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
First Commit.
Browse files Browse the repository at this point in the history
Gostagram, Unofficial instagram client, created with go
programming language. Almost all instagram Endpoints
are supported.

Version: 1.0.0-alpha1
Go Version: go1.8.3
Operating System: Ubuntu 16.04.2 LTS
Arquitecture: amd64
  • Loading branch information
Leonardo Javier Esparis Meza committed Aug 1, 2017
0 parents commit 1a48bad
Show file tree
Hide file tree
Showing 23 changed files with 1,744 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# EditorConfig coding styles definitions. For more information about the
# properties used in this file, please see the EditorConfig documentation:
# http://editorconfig.org/

# indicate this is the root of the project
root = true

[*]
charset = utf-8

end_of_line = LF
insert_final_newline = true
trim_trailing_whitespace = true

indent_style = space
indent_size = 2

[Makefile]
indent_style = tab

[*.md]
trim_trailing_whitespace = false

[*.go]
indent_style = tab
20 changes: 20 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Automatically normalize line endings for all text-based files
# http://git-scm.com/docs/gitattributes#_end_of_line_conversion
* text=auto

# For the following file types, normalize line endings to LF on checking and
# prevent conversion to CRLF when they are checked out (this is required in
# order to prevent newline related issues)
.* text eol=lf
*.go text eol=lf
*.yml text eol=lf
*.html text eol=lf
*.css text eol=lf
*.js text eol=lf
*.json text eol=lf
LICENSE text eol=lf

# Exclude `website` and `cookbook` from GitHub's language statistics
# https://github.com/github/linguist#using-gitattributes
cookbook/* linguist-documentation
website/* linguist-documentation
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.idea
.DS_Store
coverage.txt
_test
vendor
*.iml

# Binaries for programs and plugins
*.exe
*.dll
*.so
*.dylib

# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/
45 changes: 45 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

# Gopkg.toml example
#
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"


[[constraint]]
branch = "master"
name = "github.com/mitchellh/mapstructure"

[[constraint]]
name = "github.com/parnurzeal/gorequest"
version = "0.2.15"
19 changes: 19 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (C) 2017 Leonardo Esparis.

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.
90 changes: 90 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<p align="center">
<p align="center">Gostagram</p>
<p align="center">Unofficial and easy to use instagram client for go.</p>
</p>

---

###Quick Start.

**First step**

Go to instagram developer [website](https://www.instagram.com/developer/)
and create a developer account, then register a new instagram client.

**Download and Installation**
```text
go get github.com/leoxnidas/gostagram
```

**Usage**

Basic example, using an client to
consume an instagram endpoint.

```go
package main

import (
"fmt"
"github.com/leoxnidas/gostagram"
)

func main() {
client := gostagram.NewClient("access_token")
user, err := client.GetCurrentUser()

if err != nil {
fmt.Println(err)
} else {
fmt.Println(user.Id)
fmt.Println(user.Username)
fmt.Println(user.FullName)
}
}
```

If you want to enable instagram signed requests mode
you have to tell gostagram client, that you want to sig
a request.

```go
package main

import (
"fmt"
"github.com/leoxnidas/gostagram"
)

func main() {
client := gostagram.NewClient("access_token")
client.SetSignedRequest(true)
client.SetClientSecret("client secret")


user, err := client.GetCurrentUser()

if err != nil {
fmt.Println(err)
} else {
fmt.Println(user.Id)
fmt.Println(user.Username)
fmt.Println(user.FullName)
}
}
```

###Support us.
* [donate](https://www.paypal.me/leoxnidas).
* [Contribute](https://github.com/leoxnidas/gostagram#contribute).
* Talk about the project.

###Contribute.
Please use [Github issue tracker](https://github.com/leoxnidas/gostagram/issues)
for everything.
* Report issues.
* Improve/Fix documentation.
* Suggest new features or enhancements.

###License.
gostagram license [MIT](./LICENSE.txt)
88 changes: 88 additions & 0 deletions comments.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package gostagram

import (
"fmt"
"errors"
"strings"
"regexp"

"github.com/mitchellh/mapstructure"
)

var (
CommentsUrlExeed = errors.New("Cannot contain more than 1 URL.")
CommentsHashtagExceed = errors.New("Comment cannot contain more than 4 hashtags.")
CommentsMaxLengthExceed = errors.New("Comment cannot exceed 300 characters.")
CommentsCapitalLettersError = errors.New("Comment cannot consist of all capital letters")
)

var (
// take this pattern it from
// https://stackoverflow.com/questions/6883049/regex-to-find-urls-in-string-in-python
// to match an url.
urlMatcher = regexp.MustCompile(`http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+`)
capitalLetterMatcher = regexp.MustCompile(`[A-Z]`)
)

type Comment struct {
From User

Id string
Text string
CreatedTime string `mapstructure:"created_time"`
}

func (c *Client) GetMediaComments(media_id string) ([]*Comment, error) {
tmp, _, err := c.get(fmt.Sprintf("%smedia/%s/comments?access_token=%s", apiUrl, media_id, c.access_token))
if err != nil {
return nil, err
}

tmpComments := (*tmp).([]interface{})
var comments []*Comment
for _, tmpComment := range tmpComments {
var comment Comment

if err := mapstructure.Decode(tmpComment, &comment); err != nil {
return nil, err
}

comments = append(comments, &comment)
}

return comments, nil
}

func (c *Client) PostMediaComment(text, media_id string) error {
if len(text) > 300 {
return CommentsMaxLengthExceed
} else if strings.Count(text, "#") > 4 {
return CommentsHashtagExceed
} else if len(urlMatcher.FindAllSubmatch([]byte(text), -1)) > 1 {
return CommentsUrlExeed
} else {
for _, c := range text {
if capitalLetterMatcher.Match([]byte(string(c))) {
return CommentsCapitalLettersError
}
}
}

_, err := c.post(fmt.Sprintf("%smedia/%s/comments?access_token=%s", apiUrl, media_id, c.access_token), BodyData{
"text": text,
})

if err != nil {
return err
}

return nil
}

func (c *Client) DeleteMediaComment(media_id, comment_id string) error {
_, err := c.delete(fmt.Sprintf("%smedia/%s/comments/%s?access_token=%s", apiUrl, media_id, comment_id, c.access_token))
if err != nil {
return err
}
return nil
}
Loading

0 comments on commit 1a48bad

Please sign in to comment.