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

Add some minor improvements. #271

Merged
merged 1 commit into from
Aug 27, 2019
Merged
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
35 changes: 31 additions & 4 deletions goinsta.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ func (inst *Instagram) SetHTTPClient(client *http.Client) {
inst.c = client
}

// SetHTTPTransport sets http transport. This further allows users to tweak the underlying
// low level transport for adding additional fucntionalities.
func (inst *Instagram) SetHTTPTransport(transport http.RoundTripper) {
inst.c.Transport = transport
}

// SetDeviceID sets device id
func (inst *Instagram) SetDeviceID(id string) {
inst.dID = id
Expand All @@ -92,6 +98,20 @@ func (inst *Instagram) SetPhoneID(id string) {
inst.pid = id
}

// SetCookieJar sets the Cookie Jar. This further allows to use a custom implementation
// of a cookie jar which may be backed by a different data store such as redis.
func (inst *Instagram) SetCookieJar(jar http.CookieJar) error {
url, err := neturl.Parse(goInstaAPIUrl)
if err != nil {
return err
}
// First grab the cookies from the existing jar and we'll put it in the new jar.
cookies := inst.c.Jar.Cookies(url)
inst.c.Jar = jar
inst.c.Jar.SetCookies(url, cookies)
return nil
}

// New creates Instagram structure
func New(username, password string) *Instagram {
// this call never returns error
Expand Down Expand Up @@ -209,21 +229,28 @@ func Export(inst *Instagram, writer io.Writer) error {
//
// This function does not set proxy automatically. Use SetProxy after this call.
func ImportReader(r io.Reader) (*Instagram, error) {
url, err := neturl.Parse(goInstaAPIUrl)
bytes, err := ioutil.ReadAll(r)
if err != nil {
return nil, err
}

bytes, err := ioutil.ReadAll(r)
config := ConfigFile{}
err = json.Unmarshal(bytes, &config)
if err != nil {
return nil, err
}
return ImportConfig(config)
}

config := ConfigFile{}
err = json.Unmarshal(bytes, &config)
// ImportConfig imports instagram configuration from a configuration object.
//
// This function does not set proxy automatically. Use SetProxy after this call.
func ImportConfig(config ConfigFile) (*Instagram, error) {
url, err := neturl.Parse(goInstaAPIUrl)
if err != nil {
return nil, err
}

inst := &Instagram{
user: config.User,
dID: config.DeviceID,
Expand Down