Extracted dict to Fetcher
This commit is contained in:
parent
1f69282c73
commit
4da8e94bcc
7 changed files with 22 additions and 19 deletions
|
|
@ -1,3 +1,7 @@
|
|||
package cardsinfo
|
||||
|
||||
type Fetcher struct{}
|
||||
import "io"
|
||||
|
||||
type Fetcher struct {
|
||||
Dict io.Reader
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package cardsinfo
|
|||
import (
|
||||
"encoding/json"
|
||||
"gitlab.com/flygrounder/go-mtg-vk/internal/dicttranslate"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
|
@ -20,11 +19,11 @@ func (f *Fetcher) GetNameByCardId(set string, number string) string {
|
|||
return GetCardByUrl(path)
|
||||
}
|
||||
|
||||
func (f *Fetcher) GetOriginalName(name string, dict io.Reader) string {
|
||||
func (f *Fetcher) GetOriginalName(name string) string {
|
||||
path := ScryfallUrl + "/cards/named?fuzzy=" + ApplyFilters(name)
|
||||
result := GetCardByUrl(path)
|
||||
if result == "" && dict != nil {
|
||||
result, _ = dicttranslate.FindFromReader(name, dict, 5)
|
||||
if result == "" && f.Dict != nil {
|
||||
result, _ = dicttranslate.FindFromReader(name, f.Dict, 5)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ func TestGetOriginalName_Scryfall(t *testing.T) {
|
|||
Name: "Result Card",
|
||||
})
|
||||
f := &Fetcher{}
|
||||
name := f.GetOriginalName("card", nil)
|
||||
name := f.GetOriginalName("card")
|
||||
assert.Equal(t, "Result Card", name)
|
||||
}
|
||||
|
||||
|
|
@ -39,8 +39,10 @@ func TestGetOriginalName_Dict(t *testing.T) {
|
|||
"card": "Card",
|
||||
})
|
||||
dict := strings.NewReader(string(serialized))
|
||||
f := &Fetcher{}
|
||||
name := f.GetOriginalName("card", dict)
|
||||
f := &Fetcher{
|
||||
Dict: dict,
|
||||
}
|
||||
name := f.GetOriginalName("card")
|
||||
assert.Equal(t, "Card", name)
|
||||
}
|
||||
|
||||
|
|
@ -49,7 +51,7 @@ func TestGetOriginalName_BadJson(t *testing.T) {
|
|||
|
||||
gock.New(ScryfallUrl + "/cards/named?fuzzy=card").Reply(http.StatusOK).BodyString("}")
|
||||
f := &Fetcher{}
|
||||
name := f.GetOriginalName("card", nil)
|
||||
name := f.GetOriginalName("card")
|
||||
assert.Equal(t, "", name)
|
||||
}
|
||||
|
||||
|
|
@ -61,6 +63,6 @@ func TestGetOriginalName_DoubleSide(t *testing.T) {
|
|||
Layout: "transform",
|
||||
})
|
||||
f := &Fetcher{}
|
||||
name := f.GetOriginalName("card", nil)
|
||||
name := f.GetOriginalName("card")
|
||||
assert.Equal(t, "Legion's Landing | Adanto, the First Fort", name)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue