mirror of
https://github.com/imjasonh/go-marvel
synced 2026-07-16 12:31:57 +00:00
Add Get methods to fetch given a ResourceID
This commit is contained in:
parent
9662ed358c
commit
2f2111d24e
1 changed files with 37 additions and 3 deletions
40
marvel.go
40
marvel.go
|
|
@ -13,6 +13,10 @@ import (
|
|||
"github.com/google/go-querystring/query"
|
||||
)
|
||||
|
||||
const (
|
||||
basePath = "http://gateway.marvel.com/v1/public"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
PublicKey, PrivateKey string
|
||||
Client *http.Client
|
||||
|
|
@ -55,7 +59,7 @@ func (c Client) baseURL(path string, params interface{}) url.URL {
|
|||
u := url.URL{
|
||||
Scheme: "https",
|
||||
Host: "gateway.marvel.com",
|
||||
Path: "/v1/public/" + path,
|
||||
Path: "/v1/public" + path,
|
||||
}
|
||||
if params != nil {
|
||||
q, _ := query.Values(params)
|
||||
|
|
@ -214,7 +218,7 @@ type CharactersResponse struct {
|
|||
}
|
||||
|
||||
type Character struct {
|
||||
ResourceURI string `json:"resourceURI,omitempty"`
|
||||
ResourceURI *string `json:"resourceURI,omitempty"`
|
||||
ID *int `json:"id,omitempty"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
Description *string `json:"description,omitempty"`
|
||||
|
|
@ -227,6 +231,11 @@ type Character struct {
|
|||
Series *SeriesList `json:"series,omitempty"`
|
||||
}
|
||||
|
||||
func (c Character) Get(cl Client) (resp *CharactersResponse, err error) {
|
||||
err = cl.fetch((*c.ResourceURI)[len(basePath):], nil, &resp)
|
||||
return
|
||||
}
|
||||
|
||||
type CharactersList struct {
|
||||
ResourceList
|
||||
Items []Character `json:"items,omitempty"`
|
||||
|
|
@ -306,7 +315,7 @@ type ComicsResponse struct {
|
|||
}
|
||||
|
||||
type Comic struct {
|
||||
ResourceURI string `json:"resourceURI,omitempty"`
|
||||
ResourceURI *string `json:"resourceURI,omitempty"`
|
||||
ID *int `json:"id,omitempty"`
|
||||
Name *string `json:"id,omitempty"`
|
||||
DigitalID *int `json:"digitalId,omitempty"`
|
||||
|
|
@ -338,6 +347,11 @@ type Comic struct {
|
|||
Events *EventsList `json:"events,omitempty"`
|
||||
}
|
||||
|
||||
func (c Comic) Get(cl Client) (resp *ComicsResponse, err error) {
|
||||
err = cl.fetch((*c.ResourceURI)[len(basePath):], nil, &resp)
|
||||
return
|
||||
}
|
||||
|
||||
type TextObject struct {
|
||||
Type string `json:"text,omitempty"`
|
||||
Language string `json:"language,omitempty"`
|
||||
|
|
@ -443,6 +457,11 @@ type Creator struct {
|
|||
Events *EventsList `json:"events,omitempty"`
|
||||
}
|
||||
|
||||
func (c Creator) Get(cl Client) (resp *CreatorsResponse, err error) {
|
||||
err = cl.fetch((*c.ResourceURI)[len(basePath):], nil, &resp)
|
||||
return
|
||||
}
|
||||
|
||||
type CreatorsList struct {
|
||||
ResourceList
|
||||
Items []Creator
|
||||
|
|
@ -533,6 +552,11 @@ type Event struct {
|
|||
Previous *Event `json:"next,omitempty"`
|
||||
}
|
||||
|
||||
func (e Event) Get(cl Client) (resp *EventsResponse, err error) {
|
||||
err = cl.fetch((*e.ResourceURI)[len(basePath):], nil, &resp)
|
||||
return
|
||||
}
|
||||
|
||||
type EventsList struct {
|
||||
ResourceList
|
||||
Items []Event `json:"items,omitempty"`
|
||||
|
|
@ -629,6 +653,11 @@ type Series struct {
|
|||
Previous *Series `json:"next,omitempty"`
|
||||
}
|
||||
|
||||
func (s Series) Get(cl Client) (resp *SeriesResponse, err error) {
|
||||
err = cl.fetch((*s.ResourceURI)[len(basePath):], nil, &resp)
|
||||
return
|
||||
}
|
||||
|
||||
type SeriesList struct {
|
||||
ResourceList
|
||||
Items []Series
|
||||
|
|
@ -715,6 +744,11 @@ type Story struct {
|
|||
OriginalIssue Comic
|
||||
}
|
||||
|
||||
func (s Story) Get(cl Client) (resp *StoriesResponse, err error) {
|
||||
err = cl.fetch((*s.ResourceURI)[len(basePath):], nil, &resp)
|
||||
return
|
||||
}
|
||||
|
||||
type StoriesList struct {
|
||||
ResourceList
|
||||
Items []Story `json:"items,omitempty"`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue