-
Notifications
You must be signed in to change notification settings - Fork 14
/
instagram.go
65 lines (53 loc) · 1.27 KB
/
instagram.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package instagram
import (
"github.com/coretrix/hitrix/service/component/config"
)
type NewProviderFunc func(configService config.IConfig) (IProvider, error)
type Account struct {
AccountID int64
FullName string
Bio string
Posts int64
Followers int64
Following int64
Picture string
IsPrivate bool
Website string
}
type Post struct {
ID string
Title string
Images []string
CreatedAt int64
}
type IProvider interface {
GetName() string
GetAccount(account string) (*Account, error)
GetFeed(accountID int64, nextPageToken string) ([]*Post, string, error)
}
type IAPIManager interface {
GetRandomProvider() IProvider
GetProvider() IProvider
}
type APIManager struct {
Providers map[uint64]IProvider
}
func NewAPIManager(configService config.IConfig, newProviderFunctions ...NewProviderFunc) (IAPIManager, error) {
providers := map[uint64]IProvider{}
for i, newProviderFunc := range newProviderFunctions {
provider, err := newProviderFunc(configService)
if err != nil {
return nil, err
}
providers[uint64(i)] = provider
}
return &APIManager{
Providers: providers,
}, nil
}
func (a *APIManager) GetRandomProvider() IProvider {
return a.Providers[0]
}
func (a *APIManager) GetProvider() IProvider {
return a.Providers[0]
}