forked from JulianToledano/goingecko
-
Notifications
You must be signed in to change notification settings - Fork 0
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
bb522f5
commit 7da0bf5
Showing
6 changed files
with
137 additions
and
1 deletion.
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,63 @@ | ||
package goingecko | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/url" | ||
"strconv" | ||
|
||
"github.com/JulianToledano/goingecko/events" | ||
) | ||
|
||
func (c *Client) Events(countryCode, eventType, page, from, to string, onlyUpcoming bool) (*events.Events, error) { | ||
params := url.Values{} | ||
params.Add("country_code", countryCode) | ||
params.Add("type", eventType) | ||
params.Add("page", page) | ||
params.Add("upcoming_events_only", strconv.FormatBool(onlyUpcoming)) | ||
params.Add("from_date", from) | ||
params.Add("to_date", to) | ||
|
||
rUrl := fmt.Sprintf("%s?%s", eventsURL, params.Encode()) | ||
resp, err := c.MakeReq(rUrl) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var data *events.Events | ||
err = json.Unmarshal([]byte(resp), &data) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return data, nil | ||
} | ||
|
||
func (c *Client) EventsCountries() (*events.Country, error) { | ||
rUrl := fmt.Sprintf("%s/%s", eventsURL, "countries") | ||
resp, err := c.MakeReq(rUrl) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var data *events.Country | ||
err = json.Unmarshal([]byte(resp), &data) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return data, nil | ||
} | ||
|
||
func (c *Client) EventsTypes() (*events.Types, error) { | ||
rUrl := fmt.Sprintf("%s/%s", eventsURL, "types") | ||
resp, err := c.MakeReq(rUrl) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var data *events.Types | ||
err = json.Unmarshal([]byte(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,10 @@ | ||
package events | ||
|
||
type Country struct { | ||
Data []CountryData `json:"data"` | ||
} | ||
|
||
type CountryData struct { | ||
Country string `json:"country"` | ||
Code string `json:"code"` | ||
} |
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,23 @@ | ||
package events | ||
|
||
type Events struct { | ||
Data []event `json:"data"` | ||
Count int32 `json:"count"` | ||
Page int32 `json:"page"` | ||
} | ||
|
||
type event struct { | ||
Type string `json:"type"` | ||
Title string `json:"title"` | ||
Description string `json:"description"` | ||
Organizer string `json:"organizer"` | ||
StartDate string `json:"start_date"` | ||
EndDate string `json:"end_date"` | ||
Website string `json:"website"` | ||
Email string `json:"email"` | ||
Venue string `json:"venue"` | ||
Address string `json:"address"` | ||
City string `json:"city"` | ||
Country string `json:"country"` | ||
Screenshot string `json:"screenshot"` | ||
} |
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,6 @@ | ||
package events | ||
|
||
type Types struct { | ||
Data []string `json:"data"` | ||
Count int16 `json:"count"` | ||
} |
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,34 @@ | ||
package test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/JulianToledano/goingecko" | ||
) | ||
|
||
func TestEvents(t *testing.T) { | ||
cgClient := goingecko.NewClient(nil) | ||
|
||
r, _ := cgClient.Events("DE", "Meetup", "1", "2015-01-01", "2021-12-31", false) | ||
if r == nil { | ||
t.Errorf("Error") | ||
} | ||
} | ||
|
||
func TestEventsCountries(t *testing.T) { | ||
cgClient := goingecko.NewClient(nil) | ||
|
||
r, _ := cgClient.EventsCountries() | ||
if r == nil { | ||
t.Errorf("Error") | ||
} | ||
} | ||
|
||
func TestEventsTypes(t *testing.T) { | ||
cgClient := goingecko.NewClient(nil) | ||
|
||
r, _ := cgClient.EventsTypes() | ||
if r == nil { | ||
t.Errorf("Error") | ||
} | ||
} |