@@ -27,7 +27,7 @@ const (
2727 xErrorHeader = "X-Error"
2828 xErrorCodeHeader = "X-Error-Code"
2929
30- defaultTimeout = time .Second * 10
30+ defaultTimeout = time .Second * 5
3131)
3232
3333// Client is a getpocket API client
@@ -74,45 +74,21 @@ func (c *Client) Modify(ctx context.Context, input ModifyInput) error {
7474
7575// Retrieving retrieves user data (items) Pocket, such as the item id, which is needed to modify items in the Modify function
7676func (c * Client ) Retrieving (ctx context.Context , input RetrievingInput ) ([]Item , error ) {
77- var items []Item
78-
7977 req , err := input .generateRequest (c .consumerKey )
8078 if err != nil {
81- return items , err
79+ return nil , err
8280 }
8381
8482 values , err := c .doHTTP (ctx , endpointRetrieving , req )
8583 if err != nil {
86- return items , err
84+ return nil , err
8785 }
8886
8987 if values .GetObject ("list" ) == nil {
90- return items , nil
91- }
92-
93- var itemId string
94- var index int
95- newJsonStr := values .GetObject ("list" ).String ()
96- for index != - 1 {
97- index = strings .Index (newJsonStr , "{\" item_id\" :\" " )
98- if index != - 1 {
99- for i := index + 12 ; string (newJsonStr [i ]) != "\" " ; i ++ {
100- itemId += string (newJsonStr [i ])
101- }
102-
103- items = append (items , createItem (itemId , values ))
104-
105- itemId = ""
106- oldJsonStr := newJsonStr
107- newJsonStr = ``
108-
109- for i := index + 12 ; i != len (oldJsonStr ); i ++ {
110- newJsonStr += string (oldJsonStr [i ])
111- }
112- }
88+ return nil , nil
11389 }
11490
115- return items , nil
91+ return c . parseItems ( values ) , nil
11692}
11793
11894// Authorize returns the Authorization structure with the access token, user name and state obtained from the authorization request
@@ -185,6 +161,36 @@ func (c *Client) GetRequestToken(ctx context.Context, redirectURL string, state
185161 return string (token ), nil
186162}
187163
164+ func (c * Client ) parseItems (values * fastjson.Value ) []Item {
165+ var (
166+ items []Item
167+ itemId string
168+ index int
169+ )
170+
171+ newJsonStr := values .GetObject ("list" ).String ()
172+ for index != - 1 {
173+ index = strings .Index (newJsonStr , "{\" item_id\" :\" " )
174+ if index != - 1 {
175+ for i := index + 12 ; string (newJsonStr [i ]) != "\" " ; i ++ {
176+ itemId += string (newJsonStr [i ])
177+ }
178+
179+ items = append (items , createItem (itemId , values ))
180+
181+ itemId = ""
182+ oldJsonStr := newJsonStr
183+ newJsonStr = ``
184+
185+ for i := index + 12 ; i != len (oldJsonStr ); i ++ {
186+ newJsonStr += string (oldJsonStr [i ])
187+ }
188+ }
189+ }
190+
191+ return items
192+ }
193+
188194func (c * Client ) doHTTP (ctx context.Context , endpoint string , body interface {}) (* fastjson.Value , error ) {
189195 b , err := json .Marshal (body )
190196 if err != nil {
0 commit comments