-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e548c83
Showing
22 changed files
with
778 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, build with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# nfeio | ||
|
||
### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package nfeio | ||
|
||
func (c *Client) SearchAddressByPostalCode(postalCode string) (response Address, err error) { | ||
response.State = &State{} | ||
err = c.Get("addresses/"+postalCode, nil, nil, &response) | ||
return | ||
} | ||
|
||
type Address struct { | ||
StreetSuffix string `json:"streetSuffix,omitempty"` | ||
Street string `json:"street,omitempty"` | ||
Number string `json:"number,omitempty"` | ||
NumberMin string `json:"numberMin,omitempty"` | ||
NumberMax string `json:"numberMax,omitempty"` | ||
AdditionalInformation string `json:"additionalInformation,omitempty"` | ||
District string `json:"district,omitempty"` | ||
State interface{} `json:"state,omitempty"` | ||
City *City `json:"city,omitempty"` | ||
PostalCode string `json:"postalCode,omitempty"` | ||
Country string `json:"country,omitempty"` | ||
} | ||
|
||
type City struct { | ||
Code string `json:"code,omitempty"` | ||
Name string `json:"name,omitempty"` | ||
} | ||
|
||
type State struct { | ||
Code string `json:"code,omitempty"` | ||
Name string `json:"name,omitempty"` | ||
Abbreviation string `json:"abbreviation"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package nfeio | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestSearchAddressByPostalCode(t *testing.T) { | ||
address, err := client.SearchAddressByPostalCode("03181010") | ||
assert.NoError(t, err) | ||
assert.Equal(t, address.PostalCode, "03181010") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package nfeio | ||
|
||
import "strings" | ||
|
||
type Client struct { | ||
ApiKey string | ||
OpenKey string | ||
} | ||
|
||
func NewClient(apiKey string, openKey string) *Client { | ||
return &Client{ApiKey: apiKey, OpenKey: openKey} | ||
} | ||
|
||
func (c *Client) GetAuthorization(path string) string { | ||
|
||
if strings.Contains(path, "addresses") { | ||
return c.OpenKey | ||
} | ||
|
||
return c.ApiKey | ||
|
||
} | ||
|
||
func (c *Client) GetEndpoint(path string) string { | ||
|
||
if strings.Contains(path, "addresses") { | ||
return addressUrl | ||
} | ||
|
||
return baseUrl | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package nfeio | ||
|
||
var client *Client | ||
|
||
func init() { | ||
client = NewClient( | ||
"", | ||
"", | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
package nfeio | ||
|
||
import ( | ||
"encoding/json" | ||
"time" | ||
) | ||
|
||
func (c *Client) GetCompany(idOrTaxNumber string) (response CompanyResponse, err error) { | ||
err = c.Get("companies/"+idOrTaxNumber, nil, nil, &response) | ||
return | ||
} | ||
|
||
func (c *Client) GetCompanies(pageCount, pageIndex int64) (response CompaniesResponse, err error) { | ||
err = c.Get("companies", Params{"pageCount": pageCount, "pageIndex": pageIndex}, nil, &response) | ||
return | ||
} | ||
|
||
func (c *Client) AddCompany(company *Company) (response CompanyResponse, err error) { | ||
err = c.Post("companies", company, nil, &response) | ||
return | ||
} | ||
|
||
func (c *Client) SetCompany(company *Company) (response CompanyResponse, err error) { | ||
err = c.Put("companies/"+company.Id, company, nil, &response) | ||
return | ||
} | ||
|
||
func (c *Client) DeleteCompany(id string) (err error) { | ||
err = c.Delete("companies/"+id, nil, nil, nil) | ||
return | ||
} | ||
|
||
//func (c *Client) UploadCertificate(id, file, password string) error { | ||
// | ||
// var ( | ||
// header []string | ||
// body bytes.Buffer | ||
// erm ErrMessage | ||
// ) | ||
// | ||
// // init curl | ||
// easy := curl.EasyInit() | ||
// | ||
// // close curl | ||
// defer easy.Cleanup() | ||
// | ||
// // set curl opt | ||
// _ = easy.Setopt(curl.OPT_URL, fmt.Sprintf("%scompanies/%s/certificate", baseUrl, id)) | ||
// _ = easy.Setopt(curl.OPT_SSL_VERIFYPEER, false) | ||
// | ||
// // enable on debug mode | ||
// if os.Getenv("debug") == "true" { | ||
// _ = easy.Setopt(curl.OPT_VERBOSE, true) | ||
// } | ||
// | ||
// // set header | ||
// _ = easy.Setopt(curl.OPT_HTTPHEADER, []string{ | ||
// "Authorization: " + c.ApiKey, | ||
// "Content-Type: multipart/form-data", | ||
// "Accept: application/json", | ||
// }) | ||
// | ||
// // init form | ||
// form := curl.NewForm() | ||
// | ||
// // add form fields | ||
// _ = form.AddFile("file", file) | ||
// _ = form.Add("password", password) | ||
// | ||
// // define http method | ||
// _ = easy.Setopt(curl.OPT_HTTPPOST, form) | ||
// | ||
// // print upload progress | ||
// //_ = easy.Setopt(curl.OPT_NOPROGRESS, false) | ||
// //_ = easy.Setopt(curl.OPT_PROGRESSFUNCTION, func(dltotal, dlnow, ultotal, ulnow float64, _ interface{}) bool { | ||
// // fmt.Printf("Download %3.2f%%, Uploading %3.2f%%\r", dlnow/dltotal*100, ulnow/ultotal*100) | ||
// // return true | ||
// //}) | ||
// | ||
// // get response body (callback) | ||
// _ = easy.Setopt(curl.OPT_WRITEFUNCTION, func(buf []byte, data interface{}) bool { | ||
// body.Write(buf) | ||
// return true | ||
// }) | ||
// | ||
// // get response header (callback) | ||
// _ = easy.Setopt(curl.OPT_HEADERFUNCTION, func(buf []byte, data interface{}) bool { | ||
// header = append(header, strings.Replace(string(buf), "\r\n", "", -1)) | ||
// return true | ||
// }) | ||
// | ||
// // post certificate | ||
// if err := easy.Perform(); err != nil { | ||
// return err | ||
// } | ||
// | ||
// // check error message | ||
// if err := json.NewDecoder(&body).Decode(&erm); err == nil && erm.Message != "" { | ||
// return erm | ||
// } | ||
// | ||
// // check response status code | ||
// if len(header) < 1 || !strings.Contains(header[0], "200") { | ||
// | ||
// // get status code | ||
// data := strings.Split(strings.Trim(header[0], " "), " ") | ||
// | ||
// // parse to int | ||
// code, _ := strconv.Atoi(data[1]) | ||
// | ||
// // return error code | ||
// return errors.New(http.StatusText(code)) | ||
// | ||
// } | ||
// | ||
// return nil | ||
// | ||
//} | ||
|
||
type CompanyResponse struct { | ||
Data Company `json:"companies"` | ||
} | ||
|
||
type CompaniesResponse struct { | ||
Data []Company `json:"companies"` | ||
pagination | ||
} | ||
|
||
type Company struct { | ||
Id string `json:"id,omitempty"` | ||
Name string `json:"name,omitempty"` | ||
TradeName string `json:"tradeName,omitempty"` | ||
Email string `json:"email,omitempty"` | ||
FederalTaxNumber json.Number `json:"federalTaxNumber,omitempty"` | ||
RegionalTaxNumber json.Number `json:"regionalTaxNumber,omitempty"` | ||
MunicipalTaxNumber json.Number `json:"municipalTaxNumber,omitempty"` | ||
CompanyRegistryNumber json.Number `json:"companyRegistryNumber,omitempty"` | ||
TaxRegime interface{} `json:"taxRegime,omitempty"` | ||
SpecialTaxRegime interface{} `json:"specialTaxRegime,omitempty"` | ||
LegalNature interface{} `json:"legalNature,omitempty"` | ||
RpsSerialNumber interface{} `json:"rpsSerialNumber,omitempty"` | ||
RpsNumber interface{} `json:"rpsNumber,omitempty"` | ||
IssRate float64 `json:"issRate,omitempty"` | ||
Environment string `json:"environment,omitempty"` | ||
FiscalStatus string `json:"fiscalStatus,omitempty"` | ||
Address *Address `json:"address,omitempty"` | ||
Certificate *Certificate `json:"certificate,omitempty"` | ||
EconomicActivities []EconomicActivity `json:"economicActivities,omitempty"` | ||
OpenningDate *time.Time `json:"openningDate,omitempty"` | ||
CreatedOn *time.Time `json:"createdOn,omitempty"` | ||
ModifiedOn *time.Time `json:"modifiedOn,omitempty"` | ||
} | ||
|
||
type EconomicActivity struct { | ||
Type string `json:"type,omitempty"` | ||
Code json.Number `json:"code,omitempty"` | ||
} | ||
|
||
type Certificate struct { | ||
Thumbprint string `json:"thumbprint,omitempty"` | ||
Status string `json:"status,omitempty"` | ||
ModifiedOn time.Time `json:"modifiedOn,omitempty"` | ||
ExpiresOn time.Time `json:"expiresOn,omitempty"` | ||
} |
Oops, something went wrong.