Skip to content

Commit

Permalink
Photos.saveWallPhoto
Browse files Browse the repository at this point in the history
  • Loading branch information
Vorkytaka committed Apr 18, 2017
1 parent eb14b29 commit 69c768e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ if err != nil {
* [GetLinks](https://vk.com/dev/fave.getLinks)
* [Photos](https://vk.com/dev/photos)
* [GetWallUploadServer](https://vk.com/dev/photos.getWallUploadServer)
* [SaveWallPhoto](https://vk.com/dev/photos.photos.saveWallPhoto)
* [Status](https://vk.com/dev/status)
* [Get](https://vk.com/dev/status.get)
* [Set](https://vk.com/dev/status.set)
Expand Down
19 changes: 19 additions & 0 deletions easyvk/photos-response.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,22 @@ type WallUploadServer struct {
UserID int `json:"mid"`
} `json:"response"`
}

// SavedWallPhoto describes info about
// saved photo on wall after being uploaded.
type SavedWallPhoto struct {
Response []struct {
Pid int `json:"pid"`
ID string `json:"id"`
Aid int `json:"aid"`
OwnerID int `json:"owner_id"`
Src string `json:"src"`
SrcBig string `json:"src_big"`
SrcSmall string `json:"src_small"`
SrcXbig string `json:"src_xbig"`
Width int `json:"width"`
Height int `json:"height"`
Text string `json:"text"`
Created int `json:"created"`
} `json:"response"`
}
26 changes: 26 additions & 0 deletions easyvk/photos.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,29 @@ func (p *Photos) GetWallUploadServer(groupID uint) (WallUploadServer, error) {
}
return server, nil
}

// SaveWallPhoto saves a photo to a user's or community's wall after being uploaded.
// For upload look at file upload.go.
func (p *Photos) SaveWallPhoto(userID, groupID uint, photo, hash, caption string, server int, latitude, longitude float64) (SavedWallPhoto, error) {
params := map[string]string{
"user_id": fmt.Sprint(userID),
"group_id": fmt.Sprint(groupID),
"photo": photo,
"hash": hash,
"caption": caption,
"server": fmt.Sprint(server),
"latitude": fmt.Sprint(latitude),
"longitude": fmt.Sprint(longitude),
}
resp, err := p.vk.Request("photos.saveWallPhoto", params)
if err != nil {
return SavedWallPhoto{}, err
}

var info SavedWallPhoto
err = json.Unmarshal(resp, &info)
if err != nil {
return SavedWallPhoto{}, err
}
return info, nil
}

0 comments on commit 69c768e

Please sign in to comment.