feat: Add Diyanet API provider
feat: Add UI
This commit is contained in:
@@ -15,10 +15,14 @@ type Fetcher interface {
|
||||
FetchParsed(ctx context.Context, url string) (*goquery.Document, error)
|
||||
}
|
||||
|
||||
type Diyanet struct {
|
||||
type Provider struct {
|
||||
FetcherFunc func(ctx context.Context, url string) (*goquery.Document, error)
|
||||
}
|
||||
|
||||
func New(fetcherFunc func(ctx context.Context, url string) (*goquery.Document, error)) *Provider {
|
||||
return &Provider{FetcherFunc: fetcherFunc}
|
||||
}
|
||||
|
||||
var reNumeric = regexp.MustCompile(`\d+`)
|
||||
|
||||
func validateLocation(location string) error {
|
||||
@@ -28,7 +32,7 @@ func validateLocation(location string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d Diyanet) Get(ctx context.Context, location string) ([]prayer.Times, error) {
|
||||
func (d Provider) Get(ctx context.Context, location string) ([]prayer.Times, error) {
|
||||
if err := validateLocation(location); err != nil {
|
||||
return nil, fmt.Errorf("%w: %v", prayer.ErrInvalidLocation, err)
|
||||
}
|
||||
@@ -63,6 +67,6 @@ func (d Diyanet) Get(ctx context.Context, location string) ([]prayer.Times, erro
|
||||
return times, err
|
||||
}
|
||||
|
||||
func (d Diyanet) Name() string {
|
||||
func (d Provider) Name() string {
|
||||
return "diyanet"
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"prayertimes/internal/scrapeutils"
|
||||
"prayertimes/internal/net"
|
||||
"prayertimes/pkg/prayer"
|
||||
)
|
||||
|
||||
@@ -62,13 +62,13 @@ const mockHtml = `
|
||||
|
||||
func TestDiyanet_Get(t *testing.T) {
|
||||
t.Run("validates location", func(t *testing.T) {
|
||||
d := Diyanet{}
|
||||
d := Provider{}
|
||||
_, err := d.Get(context.Background(), " not numeric ")
|
||||
assert.ErrorIs(t, err, prayer.ErrInvalidLocation)
|
||||
})
|
||||
|
||||
t.Run("extracts prayer times", func(t *testing.T) {
|
||||
d := Diyanet{
|
||||
d := Provider{
|
||||
FetcherFunc: mockFetcher(mockHtml).Fetch,
|
||||
}
|
||||
actual, err := d.Get(context.Background(), "1234")
|
||||
@@ -102,8 +102,8 @@ func TestDiyanet_Get(t *testing.T) {
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
d := Diyanet{
|
||||
FetcherFunc: scrapeutils.GetParsed,
|
||||
d := Provider{
|
||||
FetcherFunc: net.GetParsed,
|
||||
}
|
||||
times, err := d.Get(context.Background(), "9205")
|
||||
assert.NoError(t, err)
|
||||
|
||||
Reference in New Issue
Block a user