github.com/minamijoyo/terraform@v0.7.8-0.20161029001309-18b3736ba44b/builtin/providers/bitbucket/client.go (about)

     1  package bitbucket
     2  
     3  import (
     4  	"bytes"
     5  	"net/http"
     6  )
     7  
     8  type BitbucketClient struct {
     9  	Username string
    10  	Password string
    11  }
    12  
    13  func (c *BitbucketClient) Get(endpoint string) (*http.Response, error) {
    14  	client := &http.Client{}
    15  	req, err := http.NewRequest("GET", "https://api.bitbucket.org/"+endpoint, nil)
    16  	if err != nil {
    17  		return nil, err
    18  	}
    19  
    20  	req.SetBasicAuth(c.Username, c.Password)
    21  	return client.Do(req)
    22  
    23  }
    24  
    25  func (c *BitbucketClient) Post(endpoint string, jsonpayload *bytes.Buffer) (*http.Response, error) {
    26  	client := &http.Client{}
    27  	req, err := http.NewRequest("POST", "https://api.bitbucket.org/"+endpoint, jsonpayload)
    28  	if err != nil {
    29  		return nil, err
    30  	}
    31  	req.SetBasicAuth(c.Username, c.Password)
    32  	req.Header.Add("content-type", "application/json")
    33  	return client.Do(req)
    34  }
    35  
    36  func (c *BitbucketClient) Put(endpoint string, jsonpayload *bytes.Buffer) (*http.Response, error) {
    37  	client := &http.Client{}
    38  	req, err := http.NewRequest("PUT", "https://api.bitbucket.org/"+endpoint, jsonpayload)
    39  	if err != nil {
    40  		return nil, err
    41  	}
    42  	req.SetBasicAuth(c.Username, c.Password)
    43  	req.Header.Add("content-type", "application/json")
    44  	return client.Do(req)
    45  }
    46  
    47  func (c *BitbucketClient) PutOnly(endpoint string) (*http.Response, error) {
    48  	client := &http.Client{}
    49  	req, err := http.NewRequest("PUT", "https://api.bitbucket.org/"+endpoint, nil)
    50  	if err != nil {
    51  		return nil, err
    52  	}
    53  	req.SetBasicAuth(c.Username, c.Password)
    54  	return client.Do(req)
    55  }
    56  
    57  func (c *BitbucketClient) Delete(endpoint string) (*http.Response, error) {
    58  	client := &http.Client{}
    59  	req, err := http.NewRequest("DELETE", "https://api.bitbucket.org/"+endpoint, nil)
    60  	if err != nil {
    61  		return nil, err
    62  	}
    63  	req.SetBasicAuth(c.Username, c.Password)
    64  	return client.Do(req)
    65  }