Skip to content
This repository has been archived by the owner on Aug 25, 2023. It is now read-only.

feat: implement func to get media id from private account post id #336

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions privateid.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package goinsta

import "fmt"

const shortIDLen = 11

func MediaIDFromPrivateID(code string) (string, error) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be great if the original function could handle private IDs too. Move these lines to the original function.

if len(code) < shortIDLen {
return "", fmt.Errorf("private id is shorter than %v characters", shortIDLen)
}
shortID := code[:11]
return MediaIDFromShortID(shortID)
}
16 changes: 16 additions & 0 deletions privateid_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package goinsta

import (
"testing"
)

func TestMediaIDFromPrivateID(t *testing.T) {
mediaID, err := MediaIDFromPrivateID("CFPU5jqA7F7gtdLtpBevHl5A6rVwt3fi4zVzs00")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, add more tests here to make sure about the function. For example, test invalid codes.

if err != nil {
t.Fatal(err)
return
}
if mediaID != "2400229042638008699" {
t.Fatal("Invalid mediaID")
}
}