Skip to content

Commit

Permalink
export redmine.Client
Browse files Browse the repository at this point in the history
closes #1, #22
  • Loading branch information
mattn committed Feb 3, 2017
1 parent 666c4b2 commit 6647fb5
Show file tree
Hide file tree
Showing 15 changed files with 58 additions and 58 deletions.
8 changes: 4 additions & 4 deletions client.go
Expand Up @@ -5,7 +5,7 @@ import (
"net/http"
)

type client struct {
type Client struct {
endpoint string
apikey string
*http.Client
Expand All @@ -16,10 +16,10 @@ type client struct {
var DefaultLimit int = -1 // "-1" means "No setting"
var DefaultOffset int = -1 //"-1" means "No setting"

func NewClient(endpoint, apikey string) *client {
return &client{endpoint, apikey, http.DefaultClient, DefaultLimit, DefaultOffset}
func NewClient(endpoint, apikey string) *Client {
return &Client{endpoint, apikey, http.DefaultClient, DefaultLimit, DefaultOffset}
}
func (c *client) getPaginationClause() string {
func (c *Client) getPaginationClause() string {
clause := ""
if c.Limit > -1 {
clause = clause + fmt.Sprintf("&limit=%v", c.Limit)
Expand Down
20 changes: 10 additions & 10 deletions issue.go
Expand Up @@ -36,8 +36,8 @@ type Issue struct {
Author *IdName `json:"author"`
FixedVersion *IdName `json:"fixed_version"`
AssignedTo *IdName `json:"assigned_to"`
Category *IdName `json:"category"`
CategoryId int `json:"category_id"`
Category *IdName `json:"category"`
CategoryId int `json:"category_id"`
Notes string `json:"notes"`
StatusDate string `json:"status_date"`
CreatedOn string `json:"created_on"`
Expand All @@ -60,7 +60,7 @@ type CustomField struct {
Value interface{} `json:"value"`
}

func (c *client) IssuesOf(projectId int) ([]Issue, error) {
func (c *Client) IssuesOf(projectId int) ([]Issue, error) {
res, err := c.Get(c.endpoint + "/issues.json?project_id=" + strconv.Itoa(projectId) + "&key=" + c.apikey + c.getPaginationClause())
if err != nil {
return nil, err
Expand All @@ -84,7 +84,7 @@ func (c *client) IssuesOf(projectId int) ([]Issue, error) {
return r.Issues, nil
}

func (c *client) Issue(id int) (*Issue, error) {
func (c *Client) Issue(id int) (*Issue, error) {
res, err := c.Get(c.endpoint + "/issues/" + strconv.Itoa(id) + ".json?key=" + c.apikey)
if res.StatusCode == 404 {
return nil, errors.New("Not Found")
Expand All @@ -111,7 +111,7 @@ func (c *client) Issue(id int) (*Issue, error) {
return &r.Issue, nil
}

func (c *client) IssuesByQuery(query_id int) ([]Issue, error) {
func (c *Client) IssuesByQuery(query_id int) ([]Issue, error) {
res, err := http.Get(c.endpoint + "/issues.json?query_id=" + strconv.Itoa(query_id) + "&key=" + c.apikey + c.getPaginationClause())
if err != nil {
return nil, err
Expand All @@ -135,7 +135,7 @@ func (c *client) IssuesByQuery(query_id int) ([]Issue, error) {
return r.Issues, nil
}

func (c *client) IssuesByFilter(f *IssueFilter) ([]Issue, error) {
func (c *Client) IssuesByFilter(f *IssueFilter) ([]Issue, error) {
res, err := http.Get(c.endpoint + "/issues.json?key=" + c.apikey + c.getPaginationClause() + getIssueFilterClause(f))
if err != nil {
return nil, err
Expand All @@ -159,7 +159,7 @@ func (c *client) IssuesByFilter(f *IssueFilter) ([]Issue, error) {
return r.Issues, nil
}

func (c *client) Issues() ([]Issue, error) {
func (c *Client) Issues() ([]Issue, error) {
res, err := c.Get(c.endpoint + "/issues.json?key=" + c.apikey + c.getPaginationClause())
if err != nil {
return nil, err
Expand All @@ -183,7 +183,7 @@ func (c *client) Issues() ([]Issue, error) {
return r.Issues, nil
}

func (c *client) CreateIssue(issue Issue) (*Issue, error) {
func (c *Client) CreateIssue(issue Issue) (*Issue, error) {
var ir issueRequest
ir.Issue = issue
s, err := json.Marshal(ir)
Expand Down Expand Up @@ -218,7 +218,7 @@ func (c *client) CreateIssue(issue Issue) (*Issue, error) {
return &r.Issue, nil
}

func (c *client) UpdateIssue(issue Issue) error {
func (c *Client) UpdateIssue(issue Issue) error {
var ir issueRequest
ir.Issue = issue
s, err := json.Marshal(ir)
Expand Down Expand Up @@ -253,7 +253,7 @@ func (c *client) UpdateIssue(issue Issue) error {
return err
}

func (c *client) DeleteIssue(id int) error {
func (c *Client) DeleteIssue(id int) error {
req, err := http.NewRequest("DELETE", c.endpoint+"/issues/"+strconv.Itoa(id)+".json?key="+c.apikey, strings.NewReader(""))
if err != nil {
return err
Expand Down
18 changes: 9 additions & 9 deletions issue_categories.go
Expand Up @@ -10,7 +10,7 @@ import (

type issueCategoriesResult struct {
IssueCategories []IssueCategory `json:"issue_categories"`
TotalCount int `json:"total_count"`
TotalCount int `json:"total_count"`
}

type issueCategoryResult struct {
Expand All @@ -22,13 +22,13 @@ type issueCategoryRequest struct {
}

type IssueCategory struct {
Id int `json:"id"`
Project IdName `json:"project"`
Name string `json:"name"`
Id int `json:"id"`
Project IdName `json:"project"`
Name string `json:"name"`
AssignedTo IdName `json:"assigned_to"`
}

func (c *client) IssueCategories(projectId int) ([]IssueCategory, error) {
func (c *Client) IssueCategories(projectId int) ([]IssueCategory, error) {
res, err := c.Get(c.endpoint + "/projects/" + strconv.Itoa(projectId) + "/issue_categories.json?key=" + c.apikey + c.getPaginationClause())
if err != nil {
return nil, err
Expand All @@ -55,7 +55,7 @@ func (c *client) IssueCategories(projectId int) ([]IssueCategory, error) {
return r.IssueCategories, nil
}

func (c *client) IssueCategory(id int) (*IssueCategory, error) {
func (c *Client) IssueCategory(id int) (*IssueCategory, error) {
res, err := c.Get(c.endpoint + "/issue_categories/" + strconv.Itoa(id) + ".json?key=" + c.apikey)
if err != nil {
return nil, err
Expand All @@ -82,7 +82,7 @@ func (c *client) IssueCategory(id int) (*IssueCategory, error) {
return &r.IssueCategory, nil
}

func (c *client) CreateIssueCategory(issueCategory IssueCategory) (*IssueCategory, error) {
func (c *Client) CreateIssueCategory(issueCategory IssueCategory) (*IssueCategory, error) {
var ir issueCategoryRequest
ir.IssueCategory = issueCategory
s, err := json.Marshal(ir)
Expand Down Expand Up @@ -117,7 +117,7 @@ func (c *client) CreateIssueCategory(issueCategory IssueCategory) (*IssueCategor
return &r.IssueCategory, nil
}

func (c *client) UpdateIssueCategory(issueCategory IssueCategory) error {
func (c *Client) UpdateIssueCategory(issueCategory IssueCategory) error {
var ir issueCategoryRequest
ir.IssueCategory = issueCategory
s, err := json.Marshal(ir)
Expand Down Expand Up @@ -152,7 +152,7 @@ func (c *client) UpdateIssueCategory(issueCategory IssueCategory) error {
return err
}

func (c *client) DeleteIssueCategory(id int) error {
func (c *Client) DeleteIssueCategory(id int) error {
req, err := http.NewRequest("DELETE", c.endpoint+"/issue_categories/"+strconv.Itoa(id)+".json?key="+c.apikey, strings.NewReader(""))
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion issue_priorities.go
Expand Up @@ -16,7 +16,7 @@ type IssuePriority struct {
IsDefault bool `json:"is_default"`
}

func (c *client) IssuePriorities() ([]IssuePriority, error) {
func (c *Client) IssuePriorities() ([]IssuePriority, error) {
res, err := c.Get(c.endpoint + "/enumerations/issue_priorities.json?key=" + c.apikey + c.getPaginationClause())
if err != nil {
return nil, err
Expand Down
10 changes: 5 additions & 5 deletions issue_relations.go
Expand Up @@ -28,7 +28,7 @@ type IssueRelation struct {
Delay string `json:"delay"`
}

func (c *client) IssueRelations(issueId int) ([]IssueRelation, error) {
func (c *Client) IssueRelations(issueId int) ([]IssueRelation, error) {
res, err := c.Get(c.endpoint + "/issue/" + strconv.Itoa(issueId) + "/relations.json?key=" + c.apikey + c.getPaginationClause())
if err != nil {
return nil, err
Expand All @@ -55,7 +55,7 @@ func (c *client) IssueRelations(issueId int) ([]IssueRelation, error) {
return r.IssueRelations, nil
}

func (c *client) IssueRelation(id int) (*IssueRelation, error) {
func (c *Client) IssueRelation(id int) (*IssueRelation, error) {
res, err := c.Get(c.endpoint + "/relations/" + strconv.Itoa(id) + ".json?key=" + c.apikey)
if err != nil {
return nil, err
Expand All @@ -82,7 +82,7 @@ func (c *client) IssueRelation(id int) (*IssueRelation, error) {
return &r.IssueRelation, nil
}

func (c *client) CreateIssueRelation(issueRelation IssueRelation) (*IssueRelation, error) {
func (c *Client) CreateIssueRelation(issueRelation IssueRelation) (*IssueRelation, error) {
var ir issueRelationRequest
ir.IssueRelation = issueRelation
s, err := json.Marshal(ir)
Expand Down Expand Up @@ -117,7 +117,7 @@ func (c *client) CreateIssueRelation(issueRelation IssueRelation) (*IssueRelatio
return &r.IssueRelation, nil
}

func (c *client) UpdateIssueRelation(issueRelation IssueRelation) error {
func (c *Client) UpdateIssueRelation(issueRelation IssueRelation) error {
var ir issueRelationRequest
ir.IssueRelation = issueRelation
s, err := json.Marshal(ir)
Expand Down Expand Up @@ -152,7 +152,7 @@ func (c *client) UpdateIssueRelation(issueRelation IssueRelation) error {
return err
}

func (c *client) DeleteIssueRelation(id int) error {
func (c *Client) DeleteIssueRelation(id int) error {
req, err := http.NewRequest("DELETE", c.endpoint+"/relations/"+strconv.Itoa(id)+".json?key="+c.apikey, strings.NewReader(""))
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion issue_statuses.go
Expand Up @@ -17,7 +17,7 @@ type IssueStatus struct {
IsClosed bool `json:"is_closed"`
}

func (c *client) IssueStatuses() ([]IssueStatus, error) {
func (c *Client) IssueStatuses() ([]IssueStatus, error) {
res, err := c.Get(c.endpoint + "/issue_statuses.json?key=" + c.apikey + c.getPaginationClause())
if err != nil {
return nil, err
Expand Down
10 changes: 5 additions & 5 deletions membership.go
Expand Up @@ -28,7 +28,7 @@ type Membership struct {
Groups []IdName `json:"groups"`
}

func (c *client) Memberships(projectId int) ([]Membership, error) {
func (c *Client) Memberships(projectId int) ([]Membership, error) {
res, err := c.Get(c.endpoint + "/projects/" + strconv.Itoa(projectId) + "/memberships.json?key=" + c.apikey + c.getPaginationClause())
if err != nil {
return nil, err
Expand All @@ -55,7 +55,7 @@ func (c *client) Memberships(projectId int) ([]Membership, error) {
return r.Memberships, nil
}

func (c *client) Membership(id int) (*Membership, error) {
func (c *Client) Membership(id int) (*Membership, error) {
res, err := c.Get(c.endpoint + "/memberships/" + strconv.Itoa(id) + ".json?key=" + c.apikey)
if err != nil {
return nil, err
Expand All @@ -82,7 +82,7 @@ func (c *client) Membership(id int) (*Membership, error) {
return &r.Membership, nil
}

func (c *client) CreateMembership(membership Membership) (*Membership, error) {
func (c *Client) CreateMembership(membership Membership) (*Membership, error) {
var ir membershipRequest
ir.Membership = membership
s, err := json.Marshal(ir)
Expand Down Expand Up @@ -117,7 +117,7 @@ func (c *client) CreateMembership(membership Membership) (*Membership, error) {
return &r.Membership, nil
}

func (c *client) UpdateMembership(membership Membership) error {
func (c *Client) UpdateMembership(membership Membership) error {
var ir membershipRequest
ir.Membership = membership
s, err := json.Marshal(ir)
Expand Down Expand Up @@ -152,7 +152,7 @@ func (c *client) UpdateMembership(membership Membership) error {
return err
}

func (c *client) DeleteMembership(id int) error {
func (c *Client) DeleteMembership(id int) error {
req, err := http.NewRequest("DELETE", c.endpoint+"/memberships/"+strconv.Itoa(id)+".json?key="+c.apikey, strings.NewReader(""))
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion news.go
Expand Up @@ -20,7 +20,7 @@ type News struct {
CreatedOn string `json:"created_on"`
}

func (c *client) News(projectId int) ([]News, error) {
func (c *Client) News(projectId int) ([]News, error) {
res, err := c.Get(c.endpoint + "/projects/" + strconv.Itoa(projectId) + "/news.json?key=" + c.apikey + c.getPaginationClause())
if err != nil {
return nil, err
Expand Down
10 changes: 5 additions & 5 deletions project.go
Expand Up @@ -29,7 +29,7 @@ type Project struct {
UpdatedOn string `json:updated_on`
}

func (c *client) Project(id int) (*Project, error) {
func (c *Client) Project(id int) (*Project, error) {
res, err := c.Get(c.endpoint + "/projects/" + strconv.Itoa(id) + ".json?key=" + c.apikey)
if err != nil {
return nil, err
Expand All @@ -53,7 +53,7 @@ func (c *client) Project(id int) (*Project, error) {
return &r.Project, nil
}

func (c *client) Projects() ([]Project, error) {
func (c *Client) Projects() ([]Project, error) {
res, err := c.Get(c.endpoint + "/projects.json?key=" + c.apikey + c.getPaginationClause())
if err != nil {
return nil, err
Expand All @@ -77,7 +77,7 @@ func (c *client) Projects() ([]Project, error) {
return r.Projects, nil
}

func (c *client) CreateProject(project Project) (*Project, error) {
func (c *Client) CreateProject(project Project) (*Project, error) {
var ir projectRequest
ir.Project = project
s, err := json.Marshal(ir)
Expand Down Expand Up @@ -112,7 +112,7 @@ func (c *client) CreateProject(project Project) (*Project, error) {
return &r.Project, nil
}

func (c *client) UpdateProject(project Project) error {
func (c *Client) UpdateProject(project Project) error {
var ir projectRequest
ir.Project = project
s, err := json.Marshal(ir)
Expand Down Expand Up @@ -147,7 +147,7 @@ func (c *client) UpdateProject(project Project) error {
return err
}

func (c *client) DeleteProject(id int) error {
func (c *Client) DeleteProject(id int) error {
req, err := http.NewRequest("DELETE", c.endpoint+"/projects/"+strconv.Itoa(id)+".json?key="+c.apikey, strings.NewReader(""))
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion roles.go
Expand Up @@ -10,7 +10,7 @@ type rolesResult struct {
Roles []IdName `json:"roles"`
}

func (c *client) Roles() ([]IdName, error) {
func (c *Client) Roles() ([]IdName, error) {
res, err := c.Get(c.endpoint + "/roles.json?key=" + c.apikey + c.getPaginationClause())
if err != nil {
return nil, err
Expand Down
10 changes: 5 additions & 5 deletions time_entries.go
Expand Up @@ -32,7 +32,7 @@ type TimeEntry struct {
UpdatedOn string `json:"updated_on"`
}

func (c *client) TimeEntries(projectId int) ([]TimeEntry, error) {
func (c *Client) TimeEntries(projectId int) ([]TimeEntry, error) {
res, err := c.Get(c.endpoint + "/projects/" + strconv.Itoa(projectId) + "/time_entries.json?key=" + c.apikey + c.getPaginationClause())
if err != nil {
return nil, err
Expand All @@ -59,7 +59,7 @@ func (c *client) TimeEntries(projectId int) ([]TimeEntry, error) {
return r.TimeEntries, nil
}

func (c *client) TimeEntry(id int) (*TimeEntry, error) {
func (c *Client) TimeEntry(id int) (*TimeEntry, error) {
res, err := c.Get(c.endpoint + "/time_entries/" + strconv.Itoa(id) + ".json?key=" + c.apikey)
if err != nil {
return nil, err
Expand All @@ -86,7 +86,7 @@ func (c *client) TimeEntry(id int) (*TimeEntry, error) {
return &r.TimeEntry, nil
}

func (c *client) CreateTimeEntry(timeEntry TimeEntry) (*TimeEntry, error) {
func (c *Client) CreateTimeEntry(timeEntry TimeEntry) (*TimeEntry, error) {
var ir timeEntryRequest
ir.TimeEntry = timeEntry
s, err := json.Marshal(ir)
Expand Down Expand Up @@ -121,7 +121,7 @@ func (c *client) CreateTimeEntry(timeEntry TimeEntry) (*TimeEntry, error) {
return &r.TimeEntry, nil
}

func (c *client) UpdateTimeEntry(timeEntry TimeEntry) error {
func (c *Client) UpdateTimeEntry(timeEntry TimeEntry) error {
var ir timeEntryRequest
ir.TimeEntry = timeEntry
s, err := json.Marshal(ir)
Expand Down Expand Up @@ -156,7 +156,7 @@ func (c *client) UpdateTimeEntry(timeEntry TimeEntry) error {
return err
}

func (c *client) DeleteTimeEntry(id int) error {
func (c *Client) DeleteTimeEntry(id int) error {
req, err := http.NewRequest("DELETE", c.endpoint+"/time_entries/"+strconv.Itoa(id)+".json?key="+c.apikey, strings.NewReader(""))
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion time_entry_activities.go
Expand Up @@ -16,7 +16,7 @@ type TimeEntryActivity struct {
IsDefault bool `json:"is_default"`
}

func (c *client) TimeEntryActivites() ([]TimeEntryActivity, error) {
func (c *Client) TimeEntryActivites() ([]TimeEntryActivity, error) {
res, err := c.Get(c.endpoint + "/enumerations/time_entry_activities.json?key=" + c.apikey + c.getPaginationClause())
if err != nil {
return nil, err
Expand Down

0 comments on commit 6647fb5

Please sign in to comment.