From f3b5e3114ac7db2ce58be355ddb0e419559154c0 Mon Sep 17 00:00:00 2001 From: SignalRichard <20459042+SignalRichard@users.noreply.github.com> Date: Wed, 3 May 2023 12:45:19 -0400 Subject: [PATCH] refactor: consolidate http logic into client --- stackoverflow/client/answers.go | 84 ++++++------------------ stackoverflow/client/articles.go | 90 +++++--------------------- stackoverflow/client/client.go | 100 +++++++++++++++++++++++++++++ stackoverflow/client/filters.go | 53 +++++++-------- stackoverflow/client/questions.go | 75 +++++----------------- stackoverflow/resource_answer.go | 3 +- stackoverflow/resource_article.go | 3 +- stackoverflow/resource_question.go | 3 +- 8 files changed, 182 insertions(+), 229 deletions(-) diff --git a/stackoverflow/client/answers.go b/stackoverflow/client/answers.go index ad7deda..d9293db 100644 --- a/stackoverflow/client/answers.go +++ b/stackoverflow/client/answers.go @@ -1,124 +1,82 @@ package client import ( - "encoding/json" "fmt" - "io" "log" - "net/http" "net/url" - "strconv" - "strings" ) func (c *Client) GetAnswers(answerIDs *[]int, filter *string) (*[]Answer, error) { - ids := make([]string, len(*answerIDs)) - for i, answerID := range *answerIDs { - ids[i] = strconv.Itoa(answerID) - } - log.Printf("%s/%s?team=%s&order=desc&sort=creation&filter=%s", "answers", strings.Join(ids, ";"), c.TeamName, *filter) - route := fmt.Sprintf("%s/%s?team=%s&order=desc&sort=creation&filter=%s", "answers", strings.Join(ids, ";"), c.TeamName, *filter) - req, err := http.NewRequest("GET", fmt.Sprintf("%s%s", c.BaseURL, route), nil) - if err != nil { - return nil, err - } - - body, err := c.doRequest(req) + response, err := c.get("answers", answerIDs, filter) if err != nil { return nil, err } - responseWrapper := Wrapper[Answer]{} - err = json.Unmarshal(body, &responseWrapper) + answers, err := UnwrapResponseItems[Answer](response) if err != nil { return nil, err } - answers := responseWrapper.Items - - return &answers, nil + return answers, nil } func (c *Client) CreateAnswer(answer *Answer) (*Answer, error) { - formData := GenerateAnswerFormData(answer, true) - req, err := http.NewRequest("POST", fmt.Sprintf("%s%s%s%s?team=%s", c.BaseURL, "questions/", strconv.Itoa(answer.QuestionID), "/answers/add", c.TeamName), strings.NewReader(formData)) - if err != nil { - return nil, err - } - - body, err := c.doRequest(req) + response, err := c.create(fmt.Sprintf("%s%d%s", "questions/", answer.QuestionID, "/answers/add"), GenerateAnswerFormData(answer, true)) if err != nil { return nil, err } - buf := new(strings.Builder) - io.Copy(buf, strings.NewReader((string(body)))) - log.Printf("Response body: %s", buf.String()) - - responseWrapper := Wrapper[Answer]{} - err = json.Unmarshal(body, &responseWrapper) + answers, err := UnwrapResponseItems[Answer](response) if err != nil { return nil, err } - if len(responseWrapper.Items) != 1 { - return nil, fmt.Errorf("response wrapper does not contain expected number of items (1); item length is %d", len(responseWrapper.Items)) + if len(*answers) != 1 { + return nil, fmt.Errorf("response wrapper does not contain expected number of items (1); item length is %d", len(*answers)) } - newAnswer := responseWrapper.Items[0] + newAnswer := (*answers)[0] return &newAnswer, nil } func (c *Client) UpdateAnswer(answer *Answer) (*Answer, error) { - formData := GenerateAnswerFormData(answer, false) - req, err := http.NewRequest("POST", fmt.Sprintf("%s%s%s%s?team=%s", c.BaseURL, "answers/", strconv.Itoa(answer.ID), "/edit", c.TeamName), strings.NewReader(formData)) + response, err := c.update(fmt.Sprintf("%s%d%s", "answers/", answer.ID, "/edit"), GenerateAnswerFormData(answer, false)) if err != nil { return nil, err } - body, err := c.doRequest(req) + answers, err := UnwrapResponseItems[Answer](response) if err != nil { return nil, err } - responseWrapper := Wrapper[Answer]{} - err = json.Unmarshal(body, &responseWrapper) - if err != nil { - return nil, err + if len(*answers) != 1 { + return nil, fmt.Errorf("response wrapper does not contain expected number of items (1); item length is %d", len(*answers)) } - if len(responseWrapper.Items) != 1 { - return nil, fmt.Errorf("response wrapper does not contain expected number of items (1); item length is %d", len(responseWrapper.Items)) - } - - newAnswer := responseWrapper.Items[0] + newAnswer := (*answers)[0] return &newAnswer, nil } -func (c *Client) DeleteAnswer(answerId int, filter *string) error { - req, err := http.NewRequest("POST", fmt.Sprintf("%s%s%s%s?team=%s&filter=%s", c.BaseURL, "answers/", strconv.Itoa(answerId), "/delete", c.TeamName, *filter), nil) +func (c *Client) DeleteAnswer(answerId int) error { + err := c.delete(fmt.Sprintf("%s%d%s", "answers/", answerId, "/delete")) if err != nil { return err } - _, err2 := c.doRequest(req) - if err2 != nil { - return err - } - return nil } -func GenerateAnswerFormData(answer *Answer, isCreate bool) string { +func GenerateAnswerFormData(answer *Answer, isCreate bool) *string { + formData := "" if isCreate { - formData := fmt.Sprintf("id=%d&body=%s&preview=%t&filter=%s", answer.QuestionID, url.QueryEscape(answer.BodyMarkdown), answer.Preview, answer.Filter) - log.Printf("Form data: %s", formData) - return formData + formData = fmt.Sprintf("id=%d&body=%s&preview=%t&filter=%s", answer.QuestionID, url.QueryEscape(answer.BodyMarkdown), answer.Preview, answer.Filter) + } else { + formData = fmt.Sprintf("id=%d&body=%s&preview=%t&filter=%s", answer.ID, url.QueryEscape(answer.BodyMarkdown), answer.Preview, answer.Filter) } - formData := fmt.Sprintf("id=%d&body=%s&preview=%t&filter=%s", answer.ID, url.QueryEscape(answer.BodyMarkdown), answer.Preview, answer.Filter) log.Printf("Form data: %s", formData) - return formData + return &formData } diff --git a/stackoverflow/client/articles.go b/stackoverflow/client/articles.go index 1afa353..f70e3ee 100644 --- a/stackoverflow/client/articles.go +++ b/stackoverflow/client/articles.go @@ -1,133 +1,77 @@ package client import ( - "encoding/json" "fmt" - "io" "log" - "net/http" "net/url" - "strconv" "strings" ) func (c *Client) GetArticles(articleIDs *[]int, filter *string) (*[]Article, error) { - ids := make([]string, len(*articleIDs)) - for i, articleID := range *articleIDs { - ids[i] = strconv.Itoa(articleID) - } - log.Printf("%s/%s?team=%s&order=desc&sort=creation&filter=%s", "articles", strings.Join(ids, ";"), c.TeamName, *filter) - route := fmt.Sprintf("%s/%s?team=%s&order=desc&sort=creation&filter=%s", "articles", strings.Join(ids, ";"), c.TeamName, *filter) - req, err := http.NewRequest("GET", fmt.Sprintf("%s%s", c.BaseURL, route), nil) - if err != nil { - return nil, err - } - - body, err := c.doRequest(req) + response, err := c.get("articles", articleIDs, filter) if err != nil { return nil, err } - responseWrapper := Wrapper[Article]{} - err = json.Unmarshal(body, &responseWrapper) + articles, err := UnwrapResponseItems[Article](response) if err != nil { return nil, err } - articles := responseWrapper.Items - - return &articles, nil + return articles, nil } func (c *Client) CreateArticle(article *Article) (*Article, error) { - //rb, err := json.Marshal(&article) - //if err != nil { - // return nil, err - //} - //buf := new(strings.Builder) - //io.Copy(buf, strings.NewReader((string(rb)))) - //log.Printf("Deserialized JSON bytes: %s", buf.String()) - //req, err := http.NewRequest("POST", fmt.Sprintf("%s%s?team=%s", c.BaseURL, "articles/add", c.TeamName), bytes.NewReader(rb)) - - formData := GenerateArticleFormData(article) - req, err := http.NewRequest("POST", fmt.Sprintf("%s%s?team=%s", c.BaseURL, "articles/add", c.TeamName), strings.NewReader(formData)) - if err != nil { - return nil, err - } - - body, err := c.doRequest(req) + response, err := c.create("articles/add", GenerateArticleFormData(article)) if err != nil { return nil, err } - buf := new(strings.Builder) - io.Copy(buf, strings.NewReader((string(body)))) - log.Printf("Response body: %s", buf.String()) - - responseWrapper := Wrapper[Article]{} - err = json.Unmarshal(body, &responseWrapper) + articles, err := UnwrapResponseItems[Article](response) if err != nil { return nil, err } - if len(responseWrapper.Items) != 1 { - return nil, fmt.Errorf("response wrapper does not contain expected number of items (1); item length is %d", len(responseWrapper.Items)) + if len(*articles) != 1 { + return nil, fmt.Errorf("response wrapper does not contain expected number of items (1); item length is %d", len(*articles)) } - newArticle := responseWrapper.Items[0] + newArticle := (*articles)[0] return &newArticle, nil } func (c *Client) UpdateArticle(article *Article) (*Article, error) { - //rb, err := json.Marshal(&article) - //if err != nil { - // return nil, err - //} - //req, err := http.NewRequest("POST", fmt.Sprintf("%s%s%s%s?team=%s", c.BaseURL, "articles/", strconv.Itoa(article.ID), "/edit", c.TeamName), strings.NewReader(string(rb))) - - formData := GenerateArticleFormData(article) - req, err := http.NewRequest("POST", fmt.Sprintf("%s%s%s%s?team=%s", c.BaseURL, "articles/", strconv.Itoa(article.ID), "/edit", c.TeamName), strings.NewReader(formData)) + response, err := c.update(fmt.Sprintf("%s%d%s", "articles/", article.ID, "/edit"), GenerateArticleFormData(article)) if err != nil { return nil, err } - body, err := c.doRequest(req) + articles, err := UnwrapResponseItems[Article](response) if err != nil { return nil, err } - responseWrapper := Wrapper[Article]{} - err = json.Unmarshal(body, &responseWrapper) - if err != nil { - return nil, err + if len(*articles) != 1 { + return nil, fmt.Errorf("response wrapper does not contain expected number of items (1); item length is %d", len(*articles)) } - if len(responseWrapper.Items) != 1 { - return nil, fmt.Errorf("response wrapper does not contain expected number of items (1); item length is %d", len(responseWrapper.Items)) - } - - newArticle := responseWrapper.Items[0] + newArticle := (*articles)[0] return &newArticle, nil } -func (c *Client) DeleteArticle(articleId int, filter *string) error { - req, err := http.NewRequest("POST", fmt.Sprintf("%s%s%s%s?team=%s&filter=%s", c.BaseURL, "articles/", strconv.Itoa(articleId), "/delete", c.TeamName, *filter), nil) +func (c *Client) DeleteArticle(articleId int) error { + err := c.delete(fmt.Sprintf("%s%d%s", "articles/", articleId, "/delete")) if err != nil { return err } - _, err2 := c.doRequest(req) - if err2 != nil { - return err - } - return nil } -func GenerateArticleFormData(article *Article) string { +func GenerateArticleFormData(article *Article) *string { formData := fmt.Sprintf("title=%s&body=%s&tags=%s&article_type=%s&filter=%s", url.QueryEscape(article.Title), url.QueryEscape(article.BodyMarkdown), strings.Join(article.Tags, ","), article.ArticleType, article.Filter) log.Printf("Form data: %s", formData) - return formData + return &formData } diff --git a/stackoverflow/client/client.go b/stackoverflow/client/client.go index e09ca37..559027a 100644 --- a/stackoverflow/client/client.go +++ b/stackoverflow/client/client.go @@ -1,9 +1,13 @@ package client import ( + "encoding/json" "fmt" "io" + "log" "net/http" + "strconv" + "strings" "time" ) @@ -68,3 +72,99 @@ func (c *Client) doRequest(req *http.Request) ([]byte, error) { return body, err } + +func (c *Client) get(route string, identifiers *[]int, filter *string) (*[]byte, error) { + ids := make([]string, len(*identifiers)) + for i, id := range *identifiers { + ids[i] = strconv.Itoa(id) + } + url := fmt.Sprintf("%s%s/%s?team=%s&filter=%s", c.BaseURL, route, strings.Join(ids, ";"), c.TeamName, *filter) + log.Print(url) + req, err := http.NewRequest("GET", url, nil) + if err != nil { + return nil, err + } + + body, err := c.doRequest(req) + if err != nil { + return nil, err + } + + buf := new(strings.Builder) + io.Copy(buf, strings.NewReader((string(body)))) + log.Printf("Response body: %s", buf.String()) + + return &body, nil +} + +func (c *Client) create(route string, formData *string) (*[]byte, error) { + url := fmt.Sprintf("%s%s?team=%s", c.BaseURL, route, c.TeamName) + log.Print(url) + req, err := http.NewRequest("POST", url, strings.NewReader(*formData)) + if err != nil { + return nil, err + } + + body, err := c.doRequest(req) + if err != nil { + return nil, err + } + + buf := new(strings.Builder) + io.Copy(buf, strings.NewReader((string(body)))) + log.Printf("Response body: %s", buf.String()) + + return &body, nil +} + +func (c *Client) update(route string, formData *string) (*[]byte, error) { + url := fmt.Sprintf("%s%s?team=%s", c.BaseURL, route, c.TeamName) + log.Print(url) + req, err := http.NewRequest("POST", url, strings.NewReader(*formData)) + if err != nil { + return nil, err + } + + body, err := c.doRequest(req) + if err != nil { + return nil, err + } + + buf := new(strings.Builder) + io.Copy(buf, strings.NewReader((string(body)))) + log.Printf("Response body: %s", buf.String()) + + return &body, nil +} + +func (c *Client) delete(route string) error { + url := fmt.Sprintf("%s%s?team=%s", c.BaseURL, route, c.TeamName) + log.Print(url) + req, err := http.NewRequest("POST", url, nil) + if err != nil { + return err + } + + body, err2 := c.doRequest(req) + if err2 != nil { + return err2 + } + + buf := new(strings.Builder) + io.Copy(buf, strings.NewReader((string(body)))) + log.Printf("Response body: %s", buf.String()) + + return nil +} + +func UnwrapResponseItems[T Answer | Article | Filter | Question](response *[]byte) (*[]T, error) { + responseWrapper := Wrapper[T]{} + err := json.Unmarshal(*response, &responseWrapper) + if err != nil { + return nil, err + } + + items := responseWrapper.Items + + return &items, nil +} diff --git a/stackoverflow/client/filters.go b/stackoverflow/client/filters.go index 198af7e..1eee48a 100644 --- a/stackoverflow/client/filters.go +++ b/stackoverflow/client/filters.go @@ -1,9 +1,7 @@ package client import ( - "encoding/json" "fmt" - "io" "log" "net/http" "net/url" @@ -11,9 +9,9 @@ import ( ) func (c *Client) GetFilters(filterIDs *[]string) (*[]Filter, error) { - log.Printf("%s/%s", "filters", strings.Join(*filterIDs, ";")) - route := fmt.Sprintf("%s/%s?key=", "filters", strings.Join(*filterIDs, ";")) - req, err := http.NewRequest("GET", fmt.Sprintf("%s%s", c.BaseURL, route), nil) + url := fmt.Sprintf("%s%s/%s?key=", c.BaseURL, "filters", strings.Join(*filterIDs, ";")) + log.Print(url) + req, err := http.NewRequest("GET", url, nil) if err != nil { return nil, err } @@ -23,20 +21,19 @@ func (c *Client) GetFilters(filterIDs *[]string) (*[]Filter, error) { return nil, err } - responseWrapper := Wrapper[Filter]{} - err = json.Unmarshal(body, &responseWrapper) + filters, err := UnwrapResponseItems[Filter](&body) if err != nil { return nil, err } - filters := responseWrapper.Items - - return &filters, nil + return filters, nil } func (c *Client) CreateFilter(filter *Filter) (*Filter, error) { + url := fmt.Sprintf("%s%s", c.BaseURL, "filters/create?key=") + log.Print(url) formData := GenerateFilterFormData(filter) - req, err := http.NewRequest("POST", fmt.Sprintf("%s%s", c.BaseURL, "filters/create?key="), strings.NewReader(formData)) + req, err := http.NewRequest("POST", url, strings.NewReader(*formData)) if err != nil { return nil, err } @@ -46,28 +43,25 @@ func (c *Client) CreateFilter(filter *Filter) (*Filter, error) { return nil, err } - buf := new(strings.Builder) - io.Copy(buf, strings.NewReader((string(body)))) - log.Printf("Response body: %s", buf.String()) - - responseWrapper := Wrapper[Filter]{} - err = json.Unmarshal(body, &responseWrapper) + filters, err := UnwrapResponseItems[Filter](&body) if err != nil { return nil, err } - if len(responseWrapper.Items) != 1 { - return nil, fmt.Errorf("response wrapper does not contain expected number of items (1); item length is %d", len(responseWrapper.Items)) + if len(*filters) != 1 { + return nil, fmt.Errorf("response wrapper does not contain expected number of items (1); item length is %d", len(*filters)) } - newFilter := responseWrapper.Items[0] + newFilter := (*filters)[0] return &newFilter, nil } func (c *Client) UpdateFilter(filter *Filter) (*Filter, error) { + url := fmt.Sprintf("%s%s%s%s", c.BaseURL, "filters/", filter.ID, "/edit") + log.Print(url) formData := GenerateFilterFormData(filter) - req, err := http.NewRequest("POST", fmt.Sprintf("%s%s%s%s", c.BaseURL, "filters/", filter.ID, "/edit"), strings.NewReader(formData)) + req, err := http.NewRequest("POST", url, strings.NewReader(*formData)) if err != nil { return nil, err } @@ -77,23 +71,24 @@ func (c *Client) UpdateFilter(filter *Filter) (*Filter, error) { return nil, err } - responseWrapper := Wrapper[Filter]{} - err = json.Unmarshal(body, &responseWrapper) + filters, err := UnwrapResponseItems[Filter](&body) if err != nil { return nil, err } - if len(responseWrapper.Items) != 1 { - return nil, fmt.Errorf("response wrapper does not contain expected number of items (1); item length is %d", len(responseWrapper.Items)) + if len(*filters) != 1 { + return nil, fmt.Errorf("response wrapper does not contain expected number of items (1); item length is %d", len(*filters)) } - newFilter := responseWrapper.Items[0] + newFilter := (*filters)[0] return &newFilter, nil } func (c *Client) DeleteFilter(filterId string) error { - req, err := http.NewRequest("POST", fmt.Sprintf("%s%s%s%s", c.BaseURL, "filters/", filterId, "/delete"), nil) + url := fmt.Sprintf("%s%s%s%s", c.BaseURL, "filters/", filterId, "/delete") + log.Print(url) + req, err := http.NewRequest("POST", url, nil) if err != nil { return err } @@ -106,8 +101,8 @@ func (c *Client) DeleteFilter(filterId string) error { return nil } -func GenerateFilterFormData(filter *Filter) string { +func GenerateFilterFormData(filter *Filter) *string { formData := fmt.Sprintf("include=%s&exclude=%s&unsafe=%t", url.QueryEscape(strings.Join(filter.Include, ";")), url.QueryEscape(strings.Join(filter.Exclude, ";")), filter.Unsafe) log.Printf("Form data: %s", formData) - return formData + return &formData } diff --git a/stackoverflow/client/questions.go b/stackoverflow/client/questions.go index a7702f6..594262a 100644 --- a/stackoverflow/client/questions.go +++ b/stackoverflow/client/questions.go @@ -1,118 +1,77 @@ package client import ( - "encoding/json" "fmt" - "io" "log" - "net/http" "net/url" - "strconv" "strings" ) func (c *Client) GetQuestions(questionIDs *[]int, filter *string) (*[]Question, error) { - ids := make([]string, len(*questionIDs)) - for i, questionID := range *questionIDs { - ids[i] = strconv.Itoa(questionID) - } - log.Printf("%s/%s?team=%s&order=desc&sort=creation&filter=%s", "questions", strings.Join(ids, ";"), c.TeamName, *filter) - route := fmt.Sprintf("%s/%s?team=%s&order=desc&sort=creation&filter=%s", "questions", strings.Join(ids, ";"), c.TeamName, *filter) - req, err := http.NewRequest("GET", fmt.Sprintf("%s%s", c.BaseURL, route), nil) - if err != nil { - return nil, err - } - - body, err := c.doRequest(req) + response, err := c.get("questions", questionIDs, filter) if err != nil { return nil, err } - responseWrapper := Wrapper[Question]{} - err = json.Unmarshal(body, &responseWrapper) + questions, err := UnwrapResponseItems[Question](response) if err != nil { return nil, err } - questions := responseWrapper.Items - - return &questions, nil + return questions, nil } func (c *Client) CreateQuestion(question *Question) (*Question, error) { - formData := GenerateQuestionFormData(question) - req, err := http.NewRequest("POST", fmt.Sprintf("%s%s?team=%s", c.BaseURL, "questions/add", c.TeamName), strings.NewReader(formData)) - if err != nil { - return nil, err - } - - body, err := c.doRequest(req) + response, err := c.create("questions/add", GenerateQuestionFormData(question)) if err != nil { return nil, err } - buf := new(strings.Builder) - io.Copy(buf, strings.NewReader((string(body)))) - log.Printf("Response body: %s", buf.String()) - - responseWrapper := Wrapper[Question]{} - err = json.Unmarshal(body, &responseWrapper) + questions, err := UnwrapResponseItems[Question](response) if err != nil { return nil, err } - if len(responseWrapper.Items) != 1 { - return nil, fmt.Errorf("response wrapper does not contain expected number of items (1); item length is %d", len(responseWrapper.Items)) + if len(*questions) != 1 { + return nil, fmt.Errorf("response wrapper does not contain expected number of items (1); item length is %d", len(*questions)) } - newQuestion := responseWrapper.Items[0] + newQuestion := (*questions)[0] return &newQuestion, nil } func (c *Client) UpdateQuestion(question *Question) (*Question, error) { - formData := GenerateQuestionFormData(question) - req, err := http.NewRequest("POST", fmt.Sprintf("%s%s%s%s?team=%s", c.BaseURL, "questions/", strconv.Itoa(question.ID), "/edit", c.TeamName), strings.NewReader(formData)) + response, err := c.update(fmt.Sprintf("%s%d%s", "questions/", question.ID, "/edit"), GenerateQuestionFormData(question)) if err != nil { return nil, err } - body, err := c.doRequest(req) + questions, err := UnwrapResponseItems[Question](response) if err != nil { return nil, err } - responseWrapper := Wrapper[Question]{} - err = json.Unmarshal(body, &responseWrapper) - if err != nil { - return nil, err + if len(*questions) != 1 { + return nil, fmt.Errorf("response wrapper does not contain expected number of items (1); item length is %d", len(*questions)) } - if len(responseWrapper.Items) != 1 { - return nil, fmt.Errorf("response wrapper does not contain expected number of items (1); item length is %d", len(responseWrapper.Items)) - } - - newQuestion := responseWrapper.Items[0] + newQuestion := (*questions)[0] return &newQuestion, nil } -func (c *Client) DeleteQuestion(questionId int, filter *string) error { - req, err := http.NewRequest("POST", fmt.Sprintf("%s%s%s%s?team=%s&filter=%s", c.BaseURL, "questions/", strconv.Itoa(questionId), "/delete", c.TeamName, *filter), nil) +func (c *Client) DeleteQuestion(questionId int) error { + err := c.delete(fmt.Sprintf("%s%d%s", "questions/", questionId, "/delete")) if err != nil { return err } - _, err2 := c.doRequest(req) - if err2 != nil { - return err - } - return nil } -func GenerateQuestionFormData(question *Question) string { +func GenerateQuestionFormData(question *Question) *string { formData := fmt.Sprintf("title=%s&body=%s&tags=%s&preview=%t&filter=%s", url.QueryEscape(question.Title), url.QueryEscape(question.BodyMarkdown), strings.Join(question.Tags, ","), question.Preview, question.Filter) log.Printf("Form data: %s", formData) - return formData + return &formData } diff --git a/stackoverflow/resource_answer.go b/stackoverflow/resource_answer.go index 908d017..2f120db 100644 --- a/stackoverflow/resource_answer.go +++ b/stackoverflow/resource_answer.go @@ -122,13 +122,12 @@ func resourceAnswerDelete(ctx context.Context, d *schema.ResourceData, meta inte var diags diag.Diagnostics answerID, err := strconv.Atoi(d.Id()) - filter := d.Get("filter").(string) if err != nil { return diag.FromErr(err) } - err2 := client.DeleteAnswer(answerID, &filter) + err2 := client.DeleteAnswer(answerID) if err2 != nil { return diag.FromErr(err2) diff --git a/stackoverflow/resource_article.go b/stackoverflow/resource_article.go index 5b03556..338f16f 100644 --- a/stackoverflow/resource_article.go +++ b/stackoverflow/resource_article.go @@ -143,9 +143,8 @@ func resourceArticleDelete(ctx context.Context, d *schema.ResourceData, meta int if err != nil { return diag.FromErr(err) } - filter := d.Get("filter").(string) - err2 := client.DeleteArticle(articleID, &filter) + err2 := client.DeleteArticle(articleID) if err2 != nil { return diag.FromErr(err2) diff --git a/stackoverflow/resource_question.go b/stackoverflow/resource_question.go index 7d378f3..be5f5a2 100644 --- a/stackoverflow/resource_question.go +++ b/stackoverflow/resource_question.go @@ -136,9 +136,8 @@ func resourceQuestionDelete(ctx context.Context, d *schema.ResourceData, meta in if err != nil { return diag.FromErr(err) } - filter := d.Get("filter").(string) - err2 := client.DeleteQuestion(questionID, &filter) + err2 := client.DeleteQuestion(questionID) if err2 != nil { return diag.FromErr(err2)