From fc932b0184ff36147ceba0a319159a085e4cbda5 Mon Sep 17 00:00:00 2001 From: alexunit42 Date: Mon, 7 May 2018 16:39:30 +0300 Subject: [PATCH 1/6] add rate limits to error wrapper --- models/pinterest_error.go | 2 ++ models/rate_limit.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 models/rate_limit.go diff --git a/models/pinterest_error.go b/models/pinterest_error.go index 2f7b35d..dc472f5 100644 --- a/models/pinterest_error.go +++ b/models/pinterest_error.go @@ -12,6 +12,7 @@ import ( type PinterestError struct { StatusCode int `json:"status_code"` Message string `json:"message"` + Limit TypeRatelimit } func (e *PinterestError) Error() string { @@ -32,6 +33,7 @@ func WrapPinterestError(httpResponse *http.Response, bodyResponse *Response, err return &PinterestError{ StatusCode: httpResponse.StatusCode, Message: bodyResponse.Message, + Limit: GetRatelimit(httpResponse), } } diff --git a/models/rate_limit.go b/models/rate_limit.go new file mode 100644 index 0000000..d35f4e6 --- /dev/null +++ b/models/rate_limit.go @@ -0,0 +1,33 @@ +package models + +import ( + "net/http" + "strconv" + "fmt" +) + +type TypeRatelimit struct { + Remaining int + Limit int + Refresh int +} + +func GetLimit(httpResp *http.Response, key string) int { + if val, ok := httpResp.Header[key]; ok { + rateLimit, err := strconv.Atoi(val[0]) + if err == nil { + fmt.Println(err) + return 0 + } + return rateLimit + } + return 0 +} + +func GetRatelimit(httpResp *http.Response) TypeRatelimit { + return TypeRatelimit { + Remaining: GetLimit(httpResp, "X-Ratelimit-Refresh"), + Limit: GetLimit(httpResp, "X-Ratelimit-Limit"), + Refresh: GetLimit(httpResp, "X-Ratelimit-Remaining"), + } +} \ No newline at end of file From 3d2ac8a90f633e89f078b8b35cbf33c5dee9203d Mon Sep 17 00:00:00 2001 From: Rizhiy Olexandr Date: Fri, 11 May 2018 15:47:53 +0300 Subject: [PATCH 2/6] Update rate_limit.go --- models/rate_limit.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/rate_limit.go b/models/rate_limit.go index d35f4e6..2c36119 100644 --- a/models/rate_limit.go +++ b/models/rate_limit.go @@ -15,7 +15,7 @@ type TypeRatelimit struct { func GetLimit(httpResp *http.Response, key string) int { if val, ok := httpResp.Header[key]; ok { rateLimit, err := strconv.Atoi(val[0]) - if err == nil { + if err != nil { fmt.Println(err) return 0 } @@ -30,4 +30,4 @@ func GetRatelimit(httpResp *http.Response) TypeRatelimit { Limit: GetLimit(httpResp, "X-Ratelimit-Limit"), Refresh: GetLimit(httpResp, "X-Ratelimit-Remaining"), } -} \ No newline at end of file +} From 0d921c1b490835f0d653ffe7ce3d011369df219d Mon Sep 17 00:00:00 2001 From: Rizhiy Olexandr Date: Fri, 11 May 2018 16:05:17 +0300 Subject: [PATCH 3/6] Replace Refresh <--->Remaining Replace Refresh <--->Remaining --- models/rate_limit.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/rate_limit.go b/models/rate_limit.go index 2c36119..80b3716 100644 --- a/models/rate_limit.go +++ b/models/rate_limit.go @@ -26,8 +26,8 @@ func GetLimit(httpResp *http.Response, key string) int { func GetRatelimit(httpResp *http.Response) TypeRatelimit { return TypeRatelimit { - Remaining: GetLimit(httpResp, "X-Ratelimit-Refresh"), + Remaining: GetLimit(httpResp, "X-Ratelimit-Remaining"), Limit: GetLimit(httpResp, "X-Ratelimit-Limit"), - Refresh: GetLimit(httpResp, "X-Ratelimit-Remaining"), + Refresh: GetLimit(httpResp, "X-Ratelimit-Refresh"), } } From e1fdb18006aa3078505a29b43e87752e25c7d4a7 Mon Sep 17 00:00:00 2001 From: Rizhiy Olexandr Date: Fri, 11 May 2018 16:20:17 +0300 Subject: [PATCH 4/6] Update rate_limit.go --- models/rate_limit.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/models/rate_limit.go b/models/rate_limit.go index 80b3716..ceec3e9 100644 --- a/models/rate_limit.go +++ b/models/rate_limit.go @@ -15,7 +15,7 @@ type TypeRatelimit struct { func GetLimit(httpResp *http.Response, key string) int { if val, ok := httpResp.Header[key]; ok { rateLimit, err := strconv.Atoi(val[0]) - if err != nil { + if err == nil { fmt.Println(err) return 0 } @@ -26,8 +26,8 @@ func GetLimit(httpResp *http.Response, key string) int { func GetRatelimit(httpResp *http.Response) TypeRatelimit { return TypeRatelimit { - Remaining: GetLimit(httpResp, "X-Ratelimit-Remaining"), + Remaining: GetLimit(httpResp, "X-Ratelimit-Refresh"), Limit: GetLimit(httpResp, "X-Ratelimit-Limit"), - Refresh: GetLimit(httpResp, "X-Ratelimit-Refresh"), + Refresh: GetLimit(httpResp, "X-Ratelimit-Remaining"), } } From 24ac5ec64032eaed4c7f2afdc72fea9ac52547f4 Mon Sep 17 00:00:00 2001 From: alexunit42 Date: Tue, 15 May 2018 10:32:32 +0300 Subject: [PATCH 5/6] fix model/rate_linit.go --- models/rate_limit.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 models/rate_limit.go diff --git a/models/rate_limit.go b/models/rate_limit.go new file mode 100644 index 0000000..7d7d24c --- /dev/null +++ b/models/rate_limit.go @@ -0,0 +1,34 @@ +package models + +import ( + "net/http" + "strconv" + "fmt" +) + +type TypeRatelimit struct { + Remaining int + Limit int + Refresh int +} + +func GetLimit(httpResp *http.Response, key string) int { + if val, ok := httpResp.Header[key]; ok { + rateLimit, err := strconv.Atoi(val[0]) + if err != nil { + fmt.Println(err) + return 0 + } + return rateLimit + } + return 0 +} + +func GetRatelimit(httpResp *http.Response) TypeRatelimit { + return TypeRatelimit { + Remaining: GetLimit(httpResp, "X-Ratelimit-Remaining"), + Limit: GetLimit(httpResp, "X-Ratelimit-Limit"), + Refresh: GetLimit(httpResp, "X-Ratelimit-Refresh"), + } +} + From db4af509d28142e6cc68ac2caa65eae0a420a17d Mon Sep 17 00:00:00 2001 From: Rizhiy Olexandr Date: Tue, 24 Dec 2019 13:21:29 +0200 Subject: [PATCH 6/6] Creator param - Deprecated as of October 25 2019 --- models/pin.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/models/pin.go b/models/pin.go index 7df452a..8d5c311 100644 --- a/models/pin.go +++ b/models/pin.go @@ -2,7 +2,7 @@ package models import "github.com/BrandonRomano/iso8601" -const PIN_FIELDS = "id,link,note,url,attribution,color,board,counts,created_at,creator,image,media,metadata,original_link" +const PIN_FIELDS = "id,link,note,url,attribution,color,board,counts,created_at,image,media,metadata,original_link" type Pin struct { Id string `json:"id"` @@ -10,7 +10,6 @@ type Pin struct { Url string `json:"url"` Creator Creator `json:"creator"` Board Board `json:"board"` - CreatedAt iso8601.Time `json:"created_at"` Note string `json:"note"` Color string `json:"color"` Counts PinCounts `json:"counts"`