Skip to content

Commit

Permalink
RequestService refactored
Browse files Browse the repository at this point in the history
Removed the redundant "Request" suffix from function names
  • Loading branch information
theriverman committed May 19, 2020
1 parent 95d1aca commit db02b2d
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 72 deletions.
4 changes: 2 additions & 2 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (s *AuthService) PublicRegistry(credentials *Credentials) (*UserAuthenticat

credentials.Type = "public"
credentials.AcceptedTerms = true // Hardcoded for simplicity; otherwise this func would be useless
err := s.client.Request.PostRequest(url, &credentials, &response)
err := s.client.Request.Post(url, &credentials, &response)
if err != nil {
return nil, err
}
Expand All @@ -35,7 +35,7 @@ func (s *AuthService) login(credentials *Credentials) (*UserAuthenticationDetail
url := s.client.APIURL + endpointAuth
response := UserAuthenticationDetail{}

err := s.client.Request.PostRequest(url, &credentials, &response)
err := s.client.Request.Post(url, &credentials, &response)
if err != nil {
log.Println("Failed to authenticate to Taiga.")
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions common.functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func listAttachmentsForEndpoint(c *Client, queryParams *attachmentsQueryParams)
url := c.APIURL + queryParams.endpointURI + "/attachments?" + paramValues.Encode()
var attachmentsList []Attachment

err := c.Request.GetRequest(url, &attachmentsList)
err := c.Request.Get(url, &attachmentsList)
if err != nil {
return nil, err
}
Expand All @@ -31,7 +31,7 @@ func getAttachmentForEndpoint(c *Client, attachment *Attachment, endpointURI str
url := c.APIURL + endpointURI + fmt.Sprintf("/attachments/%d", attachment.ID)
var a Attachment

err := c.Request.GetRequest(url, &a)
err := c.Request.Get(url, &a)
if err != nil {
return nil, err
}
Expand Down
16 changes: 8 additions & 8 deletions epics.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (s *EpicService) List(queryParams *EpicsQueryParams) ([]Epic, error) {
url = url + s.client.GetDefaultProjectAsQueryParam()
}
var epics EpicDetailLIST
err := s.client.Request.GetRequest(url, &epics)
err := s.client.Request.Get(url, &epics)
if err != nil {
return nil, err
}
Expand All @@ -49,7 +49,7 @@ func (s *EpicService) Create(epic *Epic) (*Epic, error) {
return nil, errors.New("A mandatory field(Project, Subject) is missing. See API documentataion")
}

err := s.client.Request.PostRequest(url, &epic, &responseEpic)
err := s.client.Request.Post(url, &epic, &responseEpic)
if err != nil {
return nil, err
}
Expand All @@ -63,7 +63,7 @@ func (s *EpicService) Create(epic *Epic) (*Epic, error) {
func (s *EpicService) Get(epicID int) (*Epic, error) {
url := s.client.APIURL + fmt.Sprintf("%s/%d", endpointEpics, epicID)
var e EpicDetailGET
err := s.client.Request.GetRequest(url, &e)
err := s.client.Request.Get(url, &e)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -95,7 +95,7 @@ func (s *EpicService) GetByRef(epicRef int, project *Project) (*Epic, error) {
return nil, errors.New("No ID or Ref defined in passed project struct")
}

err := s.client.Request.GetRequest(url, &e)
err := s.client.Request.Get(url, &e)
if err != nil {
return nil, err
}
Expand All @@ -118,7 +118,7 @@ func (s *EpicService) Edit(epic *Epic) (*Epic, error) {
return nil, err
}
epic.Version = remoteEpic.Version
err = s.client.Request.PatchRequest(url, &epic, &responseEpic)
err = s.client.Request.Patch(url, &epic, &responseEpic)
if err != nil {
return nil, err
}
Expand All @@ -128,7 +128,7 @@ func (s *EpicService) Edit(epic *Epic) (*Epic, error) {
// Delete => https://taigaio.github.io/taiga-doc/dist/api.html#epics-delete
func (s *EpicService) Delete(epicID int) error {
url := s.client.APIURL + fmt.Sprintf("%s/%d", endpointEpics, epicID)
return s.client.Request.DeleteRequest(url)
return s.client.Request.Delete(url)
}

// BulkCreation => https://taigaio.github.io/taiga-doc/dist/api.html#epics-bulk-create
Expand All @@ -149,7 +149,7 @@ It seems to be pointless to implement this operation here. A for loop around `Cr
func (s *EpicService) ListRelatedUserStories(epicID int) ([]EpicRelatedUserStoryDetail, error) {
url := s.client.APIURL + fmt.Sprintf("%s/%d/related_userstories", endpointEpics, epicID)
var responseEpic []EpicRelatedUserStoryDetail
err := s.client.Request.GetRequest(url, &responseEpic)
err := s.client.Request.Get(url, &responseEpic)
if err != nil {
return nil, err
}
Expand All @@ -165,7 +165,7 @@ func (s *EpicService) CreateRelatedUserStory(EpicID int, UserStoryID int) (*Epic

e := EpicRelatedUserStoryDetail{EpicID: EpicID, UserStoryID: UserStoryID}

err := s.client.Request.PostRequest(url, &e, &e)
err := s.client.Request.Post(url, &e, &e)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (s *IssueService) List(queryParams *IssueQueryParams) ([]Issue, error) {
}
// execute requests
var issues IssueDetailLIST
err := s.client.Request.GetRequest(url, &issues)
err := s.client.Request.Get(url, &issues)
if err != nil {
return nil, err
}
Expand Down
10 changes: 5 additions & 5 deletions milestones.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (s *MilestoneService) List(queryParams *MilestonesQueryParams) ([]Milestone
}
// execute requests
var Milestones []Milestone
err := s.client.Request.GetRequest(url, &Milestones)
err := s.client.Request.Get(url, &Milestones)
if err != nil {
return nil, err
}
Expand All @@ -52,7 +52,7 @@ func (s *MilestoneService) Create(milestone *Milestone) (*Milestone, error) {
return nil, errors.New("A mandatory field is missing. See API documentataion")
}

err := s.client.Request.PostRequest(url, &milestone, &respMilestone)
err := s.client.Request.Post(url, &milestone, &respMilestone)
if err != nil {
return nil, err
}
Expand All @@ -64,7 +64,7 @@ func (s *MilestoneService) Create(milestone *Milestone) (*Milestone, error) {
func (s *MilestoneService) Get(milestoneID int) (*Milestone, error) {
url := s.client.APIURL + fmt.Sprintf("%s/%d", endpointMilestones, milestoneID)
var m Milestone
err := s.client.Request.GetRequest(url, &m)
err := s.client.Request.Get(url, &m)
if err != nil {
return nil, err
}
Expand All @@ -81,7 +81,7 @@ func (s *MilestoneService) Edit(milestone *Milestone) (*Milestone, error) {
return nil, errors.New("Passed Milestone does not have an ID yet. Does it exist?")
}

err := s.client.Request.PatchRequest(url, &milestone, &M)
err := s.client.Request.Patch(url, &milestone, &M)
if err != nil {
return nil, err
}
Expand All @@ -91,7 +91,7 @@ func (s *MilestoneService) Edit(milestone *Milestone) (*Milestone, error) {
// Delete => https://taigaio.github.io/taiga-doc/dist/api.html#milestones-delete
func (s *MilestoneService) Delete(milestoneID int) error {
url := s.client.APIURL + fmt.Sprintf("%s/%d", endpointMilestones, milestoneID)
return s.client.Request.DeleteRequest(url)
return s.client.Request.Delete(url)
}

// Stats
Expand Down
12 changes: 6 additions & 6 deletions projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (s *ProjectService) List(queryParameters *ProjectsQueryParameters) (*Projec
}
var projects ProjectsList

err := s.client.Request.GetRequest(url, &projects)
err := s.client.Request.Get(url, &projects)
if err != nil {
return nil, err
}
Expand All @@ -66,7 +66,7 @@ func (s *ProjectService) Create(project *Project) (*Project, error) {
return nil, errors.New("A mandatory field is missing. See API documentataion")
}

err := s.client.Request.PostRequest(url, &project, &responseProject)
err := s.client.Request.Post(url, &project, &responseProject)
if err != nil {
return nil, err
}
Expand All @@ -78,7 +78,7 @@ func (s *ProjectService) Get(projectID int) (*Project, error) {
url := s.client.APIURL + fmt.Sprintf("/%s/%d", endpointProjects, projectID)
var responseProject ProjectDetail

err := s.client.Request.GetRequest(url, &responseProject)
err := s.client.Request.Get(url, &responseProject)
if err != nil {
return nil, err
}
Expand All @@ -90,7 +90,7 @@ func (s *ProjectService) GetBySlug(slug string) (*Project, error) {
url := s.client.APIURL + fmt.Sprintf("/%s/by_slug?slug=%s", endpointProjects, slug)
var p ProjectDetail

err := s.client.Request.GetRequest(url, &p)
err := s.client.Request.Get(url, &p)
if err != nil {
return nil, err
}
Expand All @@ -107,7 +107,7 @@ func (s *ProjectService) Edit(project *Project) (*Project, error) {
return nil, errors.New("Passed Project does not have an ID yet. Does it exist?")
}

err := s.client.Request.PatchRequest(url, &project, &projectDetail)
err := s.client.Request.Patch(url, &project, &projectDetail)
if err != nil {
return nil, err
}
Expand All @@ -117,5 +117,5 @@ func (s *ProjectService) Edit(project *Project) (*Project, error) {
// Delete => https://taigaio.github.io/taiga-doc/dist/api.html#projects-delete
func (s *ProjectService) Delete(projectID int) error {
url := s.client.APIURL + fmt.Sprintf("%s/%d", endpointProjects, projectID)
return s.client.Request.DeleteRequest(url)
return s.client.Request.Delete(url)
}
36 changes: 18 additions & 18 deletions requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,47 +47,47 @@ func SuccessfulHTTPRequest(Response *http.Response) bool {
return false
}

// GetRequest a handler for composing a new HTTP GET request
// Get a handler for composing a new HTTP GET request
//
// * URL must be an absolute (full) URL to the desired endpoint
// * ResponseBody must be a pointer to a struct representing the fields returned by Taiga
func (s *RequestService) GetRequest(URL string, ResponseBody interface{}) error {
func (s *RequestService) Get(URL string, ResponseBody interface{}) error {
return newRawRequest("GET", s.client, ResponseBody, URL, nil)
}

// HeadRequest a handler for composing a new HTTP HEAD request
func (s *RequestService) HeadRequest() {
// Head a handler for composing a new HTTP HEAD request
func (s *RequestService) Head() {
panic("HEAD requests are not implemented")
}

// PostRequest a handler for composing a new HTTP POST request
// Post a handler for composing a new HTTP POST request
//
// * URL must be an absolute (full) URL to the desired endpoint
// * Payload must be a pointer to a complete struct which will be sent to Taiga
// * ResponseBody must be a pointer to a struct representing the fields returned by Taiga
func (s *RequestService) PostRequest(URL string, Payload interface{}, ResponseBody interface{}) error {
func (s *RequestService) Post(URL string, Payload interface{}, ResponseBody interface{}) error {
// NOTE: responseBody must always be a pointer otherwise we lose the response data!
// New POST request
return newRawRequest("POST", s.client, ResponseBody, URL, Payload)
}

// PutRequest a handler for composing a new HTTP PUT request
// Put a handler for composing a new HTTP PUT request
//
// * URL must be an absolute (full) URL to the desired endpoint
// * Payload must be a pointer to a complete struct which will be sent to Taiga
// * ResponseBody must be a pointer to a struct representing the fields returned by Taiga
func (s *RequestService) PutRequest(URL string, Payload interface{}, ResponseBody interface{}) error {
func (s *RequestService) Put(URL string, Payload interface{}, ResponseBody interface{}) error {
// NOTE: responseBody must always be a pointer otherwise we lose the response data!
// New PUT request
return newRawRequest("PUT", s.client, ResponseBody, URL, Payload)
}

// PatchRequest a handler for composing a new HTTP PATCH request
// Patch a handler for composing a new HTTP PATCH request
//
// * URL must be an absolute (full) URL to the desired endpoint
// * Payload must be a pointer to a complete struct which will be sent to Taiga
// * ResponseBody must be a pointer to a struct representing the fields returned by Taiga
func (s *RequestService) PatchRequest(URL string, Payload interface{}, ResponseBody interface{}) error {
func (s *RequestService) Patch(URL string, Payload interface{}, ResponseBody interface{}) error {
/*
patchRequest is proto-function to keep the code DRY and write things only once
patchRequest takes the following arguments:
Expand All @@ -100,26 +100,26 @@ func (s *RequestService) PatchRequest(URL string, Payload interface{}, ResponseB
return newRawRequest("PATCH", s.client, ResponseBody, URL, Payload)
}

// DeleteRequest a handler for composing a new HTTP DELETE request
// Delete a handler for composing a new HTTP DELETE request
//
// * URL must be an absolute (full) URL to the desired endpoint
func (s *RequestService) DeleteRequest(URL string) error {
func (s *RequestService) Delete(URL string) error {
// New DELETE request
return newRawRequest("DELETE", s.client, nil, URL, nil)
}

// ConnectRequest a handler for composing a new HTTP CONNECT request
func (s *RequestService) ConnectRequest() {
// Connect a handler for composing a new HTTP CONNECT request
func (s *RequestService) Connect() {
panic("CONNECT requests are not implemented")
}

// OptionsRequest a handler for composing a new HTTP OPTIONS request
func (s *RequestService) OptionsRequest() {
// Options a handler for composing a new HTTP OPTIONS request
func (s *RequestService) Options() {
panic("OPTIONS requests are not implemented")
}

// TraceRequest a handler for composing a new HTTP TRACE request
func (s *RequestService) TraceRequest() {
// Trace a handler for composing a new HTTP TRACE request
func (s *RequestService) Trace() {
panic("TRACE requests are not implemented")
}

Expand Down
2 changes: 1 addition & 1 deletion resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func genericResolver(c *Client, queryParameters *ResolverQueryParams) (*Resolver
paramValues, _ := query.Values(queryParameters)
url := c.APIURL + resolverURI + "?" + paramValues.Encode()
var respResolver Resolver
err := c.Request.GetRequest(url, &respResolver)
err := c.Request.Get(url, &respResolver)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type StatsService struct {
func (s *StatsService) GetDiscoverStats() (*DiscoverStats, error) {
url := s.client.Request.MakeURL(statsURI, "discover")
var respDiscoverStats DiscoverStats
err := s.client.Request.GetRequest(url, &respDiscoverStats)
err := s.client.Request.Get(url, &respDiscoverStats)
if err != nil {
return nil, err
}
Expand All @@ -23,7 +23,7 @@ func (s *StatsService) GetDiscoverStats() (*DiscoverStats, error) {
func (s *StatsService) GetSystemStats() (*SystemStats, error) {
url := s.client.Request.MakeURL(statsURI, "system")
var respSystemStats SystemStats
err := s.client.Request.GetRequest(url, &respSystemStats)
err := s.client.Request.Get(url, &respSystemStats)
if err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (s *TaskService) List(queryParameters *TasksQueryParams) ([]Task, error) {

var taskDetailList TaskDetailLIST

err := s.client.Request.GetRequest(url, &taskDetailList)
err := s.client.Request.Get(url, &taskDetailList)
if err != nil {
return nil, err
}
Expand All @@ -47,7 +47,7 @@ func (s *TaskService) Create(task *Task) (*Task, error) {
return nil, errors.New("A mandatory field is missing. See API documentataion")
}

err := s.client.Request.PostRequest(url, &task, &responseTask)
err := s.client.Request.Post(url, &task, &responseTask)
if err != nil {
return nil, err
}
Expand All @@ -58,7 +58,7 @@ func (s *TaskService) Create(task *Task) (*Task, error) {
func (s *TaskService) Get(task *Task) (*Task, error) {
url := s.client.APIURL + fmt.Sprintf("%s/%d", endpointTasks, task.ID)
var responseTask TaskDetailGET
err := s.client.Request.GetRequest(url, &responseTask)
err := s.client.Request.Get(url, &responseTask)
if err != nil {
return nil, err
}
Expand All @@ -77,7 +77,7 @@ func (s *TaskService) GetByRef(task *Task, project *Project) (*Task, error) {
return nil, errors.New("No ID or Ref defined in passed project struct")
}

err := s.client.Request.GetRequest(url, &respTask)
err := s.client.Request.Get(url, &respTask)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit db02b2d

Please sign in to comment.