-
Notifications
You must be signed in to change notification settings - Fork 9
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
1 parent
8e31b83
commit ab510ef
Showing
5 changed files
with
140 additions
and
38 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
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,48 @@ | ||
package goingecko | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/JulianToledano/goingecko/categories" | ||
"net/url" | ||
) | ||
|
||
// CategoriesList List all categories | ||
// Cache / Update Frequency: every 5 minutes | ||
func (c *Client) CategoriesList() (*categories.CategoriesList, error) { | ||
rUrl := fmt.Sprintf("%s/%s", categoriesURL, "list") | ||
resp, err := c.MakeReq(rUrl) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var data *categories.CategoriesList | ||
err = json.Unmarshal(resp, &data) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return data, nil | ||
} | ||
|
||
// Categories List all categories with market data | ||
// Cache / Update Frequency: every 5 minutes | ||
// Parameters: | ||
// order: valid values: market_cap_desc (default), market_cap_asc, name_desc, name_asc, market_cap_change_24h_desc and market_cap_change_24h_asc | ||
func (c *Client) Categories(order string) (*categories.CategoriesWithMarketDataList, error) { | ||
params := url.Values{} | ||
|
||
if order != "" { | ||
params.Add("order", order) | ||
} | ||
|
||
rUrl := fmt.Sprintf("%s?%s", categoriesURL, params.Encode()) | ||
resp, err := c.MakeReq(rUrl) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var data *categories.CategoriesWithMarketDataList | ||
err = json.Unmarshal(resp, &data) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return data, nil | ||
} |
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,21 @@ | ||
package categories | ||
|
||
type CategoriesList []Category | ||
|
||
type Category struct { | ||
CategoryId string `json:"category_id"` | ||
Name string `json:"name"` | ||
} | ||
|
||
type CategoriesWithMarketDataList []CategoryWithMarketData | ||
|
||
type CategoryWithMarketData struct { | ||
ID string `json:"id"` | ||
Name string `json:"name"` | ||
MarketCap float64 `json:"market_cap"` | ||
MarketCapChange24h float64 `json:"market_cap_change_24h"` | ||
Content string `json:"content"` | ||
Top3Coins []string `json:"top_3_coins"` | ||
Volume24h float64 `json:"volume_24h"` | ||
UpdatedAt string `json:"updated_at"` | ||
} |
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
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 test | ||
|
||
import ( | ||
"github.com/JulianToledano/goingecko" | ||
"testing" | ||
) | ||
|
||
func TestCategoriesList(t *testing.T) { | ||
|
||
cgClient := goingecko.NewClient(nil) | ||
|
||
categoriesList, err := cgClient.CategoriesList() | ||
if categoriesList == nil { | ||
t.Errorf("Error") | ||
} | ||
if err != nil { | ||
t.Errorf("Error: %s", err) | ||
} | ||
} | ||
|
||
func TestCategories(t *testing.T) { | ||
|
||
cgClient := goingecko.NewClient(nil) | ||
|
||
categoriesList, err := cgClient.Categories("market_cap_desc") | ||
if categoriesList == nil { | ||
t.Errorf("Error") | ||
} | ||
if err != nil { | ||
t.Errorf("Error: %s", err) | ||
} | ||
} |