@@ -3,25 +3,33 @@ package social
33import (
44 "encoding/json"
55 "fmt"
6-
76 "net/http"
87
8+ "github.com/loginradius/lr-cli/api"
99 "github.com/loginradius/lr-cli/config"
1010 "github.com/loginradius/lr-cli/request"
1111 "github.com/spf13/cobra"
1212)
1313
14- var fileName string
14+ var temp string
1515
1616type socialProvider struct {
17- Provider string `json:"Provider"`
17+ HtmlFileName string `json:"HtmlFileName"`
18+ Provider string `json:"Provider"`
19+ ProviderId int `json:"ProviderId"`
20+ ProviderKey string `json:"ProviderKey"`
21+ ProviderSecret string `json:"ProviderSecret"`
22+ Scope []string `json:"Scope"`
23+ Status bool `json:"Status"`
1824}
1925
2026type socialProviderList struct {
2127 Data []socialProvider `json:"Data"`
2228}
2329
24- var url string
30+ var Url string
31+
32+ var arr = [5 ]string {"Facebook" , "Google" , "Twitter" , "LinkedIn" , "GitHub" }
2533
2634func NewsocialCmd () * cobra.Command {
2735
@@ -31,32 +39,96 @@ func NewsocialCmd() *cobra.Command {
3139 Long : `This commmand lists social providers` ,
3240 Example : `$ lr get social` ,
3341 RunE : func (cmd * cobra.Command , args []string ) error {
34-
42+ fstatus , _ := cmd .Flags ().GetBool ("all" )
43+ if fstatus {
44+ temp = "all"
45+ }
46+ fstatus1 , _ := cmd .Flags ().GetBool ("active" )
47+ if fstatus1 {
48+ temp = "active"
49+ }
50+ if ! fstatus && ! fstatus1 {
51+ fmt .Println ("Please use atleast one of the flags 'lr get social --all' or 'lr get social --active'" )
52+ return nil
53+ }
3554 return get ()
3655
3756 },
3857 }
58+ fl := cmd .Flags ()
59+ fl .BoolP ("all" , "a" , false , "option to get all providers" )
60+ fl .BoolP ("active" , "c" , false , "option to get active providers" )
3961
4062 return cmd
4163}
4264
4365func get () error {
66+ if temp == "all" {
67+ res , err := api .GetSites ()
68+ if err != nil {
69+ return err
70+ }
71+ if res .Productplan .Name == "free" {
72+ for i := 0 ; i < 3 ; i ++ {
73+ fmt .Println (i + 1 , arr [i ])
74+ }
75+ return nil
76+ }
77+ if res .Productplan .Name == "developer" {
78+ for i := 0 ; i < len (arr ); i ++ {
79+ fmt .Println (i + 1 , arr [i ])
80+ }
81+ return nil
82+ }
83+ }
84+ if temp == "active" {
85+ resultResp , err := GetActiveProviders ()
86+ if err != nil {
87+ return err
88+ }
89+ if len (resultResp .Data ) == 0 {
90+ fmt .Println ("There is no social configuration" )
91+ return nil
92+ }
93+ var num int
94+ for i := 0 ; i < len (resultResp .Data ); i ++ {
95+ fmt .Print (fmt .Sprint (i + 1 ) + "." )
96+ fmt .Println (resultResp .Data [i ].Provider )
97+ }
98+ // Taking input from user
99+ fmt .Print ("Please select a number from 1 to " + fmt .Sprint (len (resultResp .Data )) + " :" )
100+ fmt .Scanln (& num )
101+ for 1 > num || num > len (resultResp .Data ) {
102+ fmt .Print ("Please select a number from 1 to " + fmt .Sprint (len (resultResp .Data )) + " :" )
103+
104+ fmt .Scanln (& num )
105+ }
106+ fmt .Println ("HtmlFileName: " + resultResp .Data [num - 1 ].HtmlFileName )
107+ fmt .Println ("Provider: " , resultResp .Data [num - 1 ].Provider )
108+ fmt .Println ("ProviderId: " , resultResp .Data [num - 1 ].ProviderId )
109+ fmt .Println ("ProviderKey: " , resultResp .Data [num - 1 ].ProviderKey )
110+ fmt .Println ("ProviderSecret: " , resultResp .Data [num - 1 ].ProviderSecret )
111+ fmt .Println ("Scope: " , resultResp .Data [num - 1 ].Scope )
112+ fmt .Println ("Status: " , resultResp .Data [num - 1 ].Status )
113+ }
114+
115+ return nil
116+ }
117+
118+ func GetActiveProviders () (* socialProviderList , error ) {
44119 conf := config .GetInstance ()
120+ Url = conf .AdminConsoleAPIDomain + "/platform-configuration/social-providers/options?"
45121
46- url = conf .AdminConsoleAPIDomain + "/platform-configuration/social-providers/options?"
122+ var R1 socialProviderList
123+ resp , err := request .Rest (http .MethodGet , Url , nil , "" )
47124
48- var resultResp socialProviderList
49- resp , err := request .Rest (http .MethodGet , url , nil , "" )
50125 if err != nil {
51- return err
126+ return nil , err
52127 }
53- err = json .Unmarshal ([]byte (resp ), & resultResp )
128+
129+ err = json .Unmarshal (resp , & R1 )
54130 if err != nil {
55- return err
56- }
57- for i := 0 ; i < len (resultResp .Data ); i ++ {
58- fmt .Print (fmt .Sprint (i + 1 ) + "." )
59- fmt .Println (resultResp .Data [i ].Provider )
131+ return nil , err
60132 }
61- return nil
133+ return & R1 , nil
62134}
0 commit comments