quranc

package module
v0.0.0-...-a7a0f71 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 18, 2019 License: GPL-3.0 Imports: 12 Imported by: 0

README

quranc - quran.com API client

As of this writing, the full api is supported. Even some of the api endpoints that are documented incorrectly are supported. All comments, issues, and PRs are welcome.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chapter

type Chapter struct {
	ID              int    `json:"id"`
	ChapterNumber   int    `json:"chapter_number"`
	BismillahPre    bool   `json:"bismillah_pre"`
	RevelationOrder int    `json:"revelation_order"`
	RevelationPlace string `json:"revelation_place"`
	NameComplex     string `json:"name_complex"`
	NameArabic      string `json:"name_arabic"`
	NameSimple      string `json:"name_simple"`
	VersesCount     int    `json:"verses_count"`
	Pages           struct {
		Start int `json:"start"`
		End   int `json:"end"`
	} `json:"pages"`
	TranslatedName TranslatedName `json:"translated_name"`
}

Chapter or surah along with its relevant metadata combine to detail the summary of the chatper as a whole.

type ChapterInfo

type ChapterInfo struct {
	ChapterID    int    `json:"chapter_id"`
	Text         string `json:"text"`
	Source       string `json:"source"`
	ShortText    string `json:"short_text"`
	LanguageName string `json:"language_name"`
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the API client that translates the quran.com api into familiar go types.

func New

func New(opts ...ClientOptFn) *Client

New Constructs a new Client. All default options will be used if no options are provided to overwrite them. The defaults are:

host: https://quran.com/api

func (*Client) Chapter

func (c *Client) Chapter(ctx context.Context, id int, reqOpts ...ReqOptFn) (Chapter, error)

Chapters returns the the given chapter by id from quran.com.

func (*Client) ChapterInfo

func (c *Client) ChapterInfo(ctx context.Context, id int, reqOpts ...ReqOptFn) (ChapterInfo, error)

func (*Client) Chapters

func (c *Client) Chapters(ctx context.Context, reqOpts ...ReqOptFn) ([]Chapter, error)

Chapters returns the available chapters from quran.com.

func (*Client) Juzzah

func (c *Client) Juzzah(ctx context.Context) ([]Juz, error)

func (*Client) Languages

func (c *Client) Languages(ctx context.Context, reqOpts ...ReqOptFn) ([]Language, error)

Languages returns all the available quran.com languages.

func (*Client) Recitations

func (c *Client) Recitations(ctx context.Context, reqOpts ...ReqOptFn) ([]Recitation, error)

Recitations returns all the available quran.com recitations.

func (*Client) Search

func (c *Client) Search(ctx context.Context, query SearchRequest) (SearchResponse, error)

func (*Client) Tafsiraat

func (c *Client) Tafsiraat(ctx context.Context, reqOpts ...ReqOptFn) ([]Tafsir, error)

Tafsiraat returns all the available quran.com tafsiraat.

func (*Client) Translations

func (c *Client) Translations(ctx context.Context, reqOpts ...ReqOptFn) ([]Translation, error)

Translations returns all the available quran.com translations.

func (*Client) Verse

func (c *Client) Verse(ctx context.Context, chapterID, verseID int) (Verse, error)

TODO: make github issue to fix the route in api docs for this route is routed incorrectly

func (*Client) VerseTafsir

func (c *Client) VerseTafsir(ctx context.Context, chapterID, verseID int, reqOpts ...VerseTafsirReqOptFn) ([]VerseTafsir, error)

func (*Client) Verses

func (c *Client) Verses(ctx context.Context, chapterID int, reqOpts ...VersesReqOptFn) ([]Verse, error)

type ClientOptFn

type ClientOptFn func(opt clientOpt) clientOpt

ClientOptFn is an option to set the options of the client constructor.

func WithHTTPClient

func WithHTTPClient(doer Doer) ClientOptFn

WithHTTPClient sets the http client on the quran api client.

func WithHost

func WithHost(host string) ClientOptFn

WithHost sets the host for the client url.

type Doer

type Doer interface {
	Do(*http.Request) (*http.Response, error)
}

Doer is an interface to abstract the http client out to its basic functionality.

type Juz

type Juz struct {
	ID           int          `json:"id"`
	JuzNumber    int          `json:"juz_number"`
	VerseMapping []JuzMapping `json:"verse_mapping"`
}

type JuzMapping

type JuzMapping struct {
	ChapterID  int `json:"chapter_id"`
	StartVerse int `json:"start_verse"`
	EndVerse   int `json:"end_verse"`
}

type Language

type Language struct {
	ID              int              `json:"id"`
	Name            string           `json:"name"`
	IsoCode         string           `json:"iso_code"`
	NativeName      string           `json:"native_name"`
	Direction       string           `json:"direction"`
	TranslatedNames []TranslatedName `json:"translated_names"`
}

Language is the a language with associated quran.com identifiers. The language ID is useful in filtering other api calls to the language provided. The iso code is useful in other contexts like search and verses calls.

type QuranAPI

type QuranAPI interface {
	Recitations(ctx context.Context, reqOpts ...ReqOptFn) ([]Recitation, error)
	Translations(ctx context.Context, reqOpts ...ReqOptFn) ([]Translation, error)
	Languages(ctx context.Context, reqOpts ...ReqOptFn) ([]Language, error)
	Tafsiraat(ctx context.Context, reqOpts ...ReqOptFn) ([]Tafsir, error)
	Chapters(ctx context.Context, reqOpts ...ReqOptFn) ([]Chapter, error)
	Chapter(ctx context.Context, id int, reqOpts ...ReqOptFn) (Chapter, error)
	ChapterInfo(ctx context.Context, id int, reqOpts ...ReqOptFn) (ChapterInfo, error)
	Verses(ctx context.Context, chapterID int, reqOpts ...VersesReqOptFn) ([]Verse, error)
	Verse(ctx context.Context, chapterID, verseID int) (Verse, error)
	Juzzah(ctx context.Context) ([]Juz, error)
	VerseTafsir(ctx context.Context, chapterID, verseID int, reqOpts ...VerseTafsirReqOptFn) ([]VerseTafsir, error)
	Search(ctx context.Context, query SearchRequest) (SearchResponse, error)
}

func BoltCache

func BoltCache(client QuranAPI, db *bbolt.DB) (QuranAPI, error)

type Recitation

type Recitation struct {
	ID                    int    `json:"id"`
	Style                 string `json:"style"`
	ReciterNameEng        string `json:"reciter_name_eng"`
	ReciterNameTranslated string `json:"reciter_name_translated"`
}

Recitation is a recitation provided from quran.com.

type ReqOptFn

type ReqOptFn func(opt reqOpt) reqOpt

func LanguageID

func LanguageID(id int) ReqOptFn

type Resource

type Resource struct {
	ID           int    `json:"id"`
	LanguageName string `json:"language_name"`
	Text         string `json:"text"`
	ResourceName string `json:"resource_name"`
	ResourceID   int    `json:"resource_id"`
}

type SearchRequest

type SearchRequest struct {
	Query    string
	Language string
	Page     int
	Size     int
}

type SearchResponse

type SearchResponse struct {
	Query       string        `json:"query"`
	TotalCount  int           `json:"total_count"`
	Took        int           `json:"took"`
	CurrentPage int           `json:"current_page"`
	TotalPages  int           `json:"total_pages"`
	PerPage     int           `json:"per_page"`
	Results     []SearchVerse `json:"results"`
}

type SearchVerse

type SearchVerse struct {
	ID           int        `json:"id"`
	VerseNumber  int        `json:"verse_number"`
	ChapterID    int        `json:"chapter_id"`
	VerseKey     string     `json:"verse_key"`
	TextMadani   string     `json:"text_madani"`
	Words        []Word     `json:"words"`
	Translations []Resource `json:"translations"`
}

type Tafsir

type Tafsir struct {
	ID           int    `json:"id"`
	AuthorName   string `json:"author_name"`
	Slug         string `json:"slug"`
	Name         string `json:"name"`
	LanguageName string `json:"language_name"`
}

Tafsir is a tafsir overview available from quran.com. Food for thought, the slug is never populated but is "supported" through the docs, but not in reality.

type TranslatedName

type TranslatedName struct {
	LanguageName string `json:"language_name"`
	Name         string `json:"name"`
}

TranslatedName is a name and the language is is translated from.

type Translation

type Translation struct {
	ID           int    `json:"id"`
	AuthorName   string `json:"author_name"`
	LanguageName string `json:"language_name"`
	Name         string `json:"name"`
	Slug         string `json:"slug"`
}

Translation is a translation available via the quran.com api. The translation's ID maybe used in other api calls to add translations to the response.

type Verse

type Verse struct {
	ID           int    `json:"id"`
	VerseNumber  int    `json:"verse_number"`
	ChapterID    int    `json:"chapter_id"`
	VerseKey     string `json:"verse_key"`
	TextMadani   string `json:"text_madani"`
	TextIndopak  string `json:"text_indopak"`
	TextSimple   string `json:"text_simple"`
	JuzNumber    int    `json:"juz_number"`
	HizbNumber   int    `json:"hizb_number"`
	RubNumber    int    `json:"rub_number"`
	Sajdah       string `json:"sajdah"`
	SajdahNumber int    `json:"sajdah_number"`
	PageNumber   int    `json:"page_number"`
	Audio        struct {
		URL      string     `json:"url"`
		Duration int        `json:"duration"`
		Segments [][]string `json:"segments"`
		Format   string     `json:"format"`
	} `json:"audio"`
	Translations  []Resource `json:"translations"`
	MediaContents []struct {
		URL        string `json:"url"`
		EmbedText  string `json:"embed_text"`
		Provider   string `json:"provider"`
		AuthorName string `json:"author_name"`
	} `json:"media_contents"`
	Words []Word `json:"words"`
}

type VerseTafsir

type VerseTafsir struct {
	ID           int    `json:"id"`
	Text         string `json:"text"`
	VerseID      int    `json:"verse_id"`
	LanguageName string `json:"language_name"`
	ResourceName string `json:"resource_name"`

	// VerseKey  outlined int he api response, but there is nothing that speaks
	// to it in the api documentation... hopefully someone can fill in the gap here
	VerseKey interface{} `json:"verse_key"`
}

type VerseTafsirReqOptFn

type VerseTafsirReqOptFn func(opts verseTafsirReqOpts) verseTafsirReqOpts

func TafsirID

func TafsirID(id int) VerseTafsirReqOptFn

type VersesReqOptFn

type VersesReqOptFn func(opts versesReqOpt) versesReqOpt

func VersesLanguage

func VersesLanguage(isoCode string) VersesReqOptFn

func VersesLimit

func VersesLimit(i int) VersesReqOptFn

func VersesMedia

func VersesMedia(media []int) VersesReqOptFn

func VersesOffset

func VersesOffset(i int) VersesReqOptFn

func VersesPage

func VersesPage(i int) VersesReqOptFn

func VersesRecitation

func VersesRecitation(recitation int) VersesReqOptFn

func VersesTextType

func VersesTextType(textType string) VersesReqOptFn

func VersesTranslations

func VersesTranslations(translations []int) VersesReqOptFn

type Word

type Word struct {
	ID          int    `json:"id"`
	Position    int    `json:"position"`
	TextMadani  string `json:"text_madani"`
	TextIndopak string `json:"text_indopak"`
	TextSimple  string `json:"text_simple"`
	VerseKey    string `json:"verse_key"`
	ClassName   string `json:"class_name"`
	LineNumber  int    `json:"line_number"`
	PageNumber  int    `json:"page_number"`
	Code        string `json:"code"`
	CodeV3      string `json:"code_v3"`
	CharType    string `json:"char_type"`
	Audio       struct {
		URL string `json:"url"`
	} `json:"audio"`
	Translation     Resource `json:"translation"`
	Transliteration Resource `json:"transliteration"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL