From 54b9c7e14b7d8b48ceae32f94d2cce514a02c525 Mon Sep 17 00:00:00 2001 From: Gleb Sinyavsky Date: Fri, 20 Nov 2015 15:15:34 +0300 Subject: [PATCH] Refactoring --- configs.go | 30 ++++++++++++------------------ helpers.go | 28 ++++++++++++++-------------- 2 files changed, 26 insertions(+), 32 deletions(-) diff --git a/configs.go b/configs.go index 21a13e1..19d8d26 100644 --- a/configs.go +++ b/configs.go @@ -44,6 +44,12 @@ type Chattable struct { ChannelUsername string } +type Fileable struct { + FilePath string + File interface{} + FileID string +} + func (chattable *Chattable) Values() (url.Values, error) { v := url.Values{} if chattable.ChannelUsername != "" { @@ -110,13 +116,11 @@ func (config *ForwardConfig) Values() (url.Values, error) { // PhotoConfig contains information about a SendPhoto request. type PhotoConfig struct { Chattable + Fileable Caption string ReplyToMessageID int ReplyMarkup interface{} UseExistingPhoto bool - FilePath string - File interface{} - FileID string } func (config *PhotoConfig) Values() (url.Values, error) { @@ -144,15 +148,13 @@ func (config *PhotoConfig) Values() (url.Values, error) { // AudioConfig contains information about a SendAudio request. type AudioConfig struct { Chattable + Fileable Duration int Performer string Title string ReplyToMessageID int ReplyMarkup interface{} UseExistingAudio bool - FilePath string - File interface{} - FileID string } func (config *AudioConfig) Values() (url.Values, error) { @@ -186,12 +188,10 @@ func (config *AudioConfig) Values() (url.Values, error) { // DocumentConfig contains information about a SendDocument request. type DocumentConfig struct { Chattable + Fileable ReplyToMessageID int ReplyMarkup interface{} UseExistingDocument bool - FilePath string - File interface{} - FileID string } func (config *DocumentConfig) Values() (url.Values, error) { @@ -216,12 +216,10 @@ func (config *DocumentConfig) Values() (url.Values, error) { // StickerConfig contains information about a SendSticker request. type StickerConfig struct { Chattable + Fileable ReplyToMessageID int ReplyMarkup interface{} UseExistingSticker bool - FilePath string - File interface{} - FileID string } func (config *StickerConfig) Values() (url.Values, error) { @@ -246,14 +244,12 @@ func (config *StickerConfig) Values() (url.Values, error) { // VideoConfig contains information about a SendVideo request. type VideoConfig struct { Chattable + Fileable Duration int Caption string ReplyToMessageID int ReplyMarkup interface{} UseExistingVideo bool - FilePath string - File interface{} - FileID string } func (config *VideoConfig) Values() (url.Values, error) { @@ -284,13 +280,11 @@ func (config *VideoConfig) Values() (url.Values, error) { // VoiceConfig contains information about a SendVoice request. type VoiceConfig struct { Chattable + Fileable Duration int ReplyToMessageID int ReplyMarkup interface{} UseExistingVoice bool - FilePath string - File interface{} - FileID string } func (config *VoiceConfig) Values() (url.Values, error) { diff --git a/helpers.go b/helpers.go index 50e2497..3ae0d3a 100644 --- a/helpers.go +++ b/helpers.go @@ -37,8 +37,8 @@ func NewForward(chatID int, fromChatID int, messageID int) ForwardConfig { func NewPhotoUpload(chatID int, file interface{}) PhotoConfig { return PhotoConfig{ Chattable: Chattable{ChatID: chatID}, + Fileable: Fileable{File: file}, UseExistingPhoto: false, - File: file, } } @@ -49,8 +49,8 @@ func NewPhotoUpload(chatID int, file interface{}) PhotoConfig { func NewPhotoShare(chatID int, fileID string) PhotoConfig { return PhotoConfig{ Chattable: Chattable{ChatID: chatID}, + Fileable: Fileable{FileID: fileID}, UseExistingPhoto: true, - FileID: fileID, } } @@ -62,8 +62,8 @@ func NewPhotoShare(chatID int, fileID string) PhotoConfig { func NewAudioUpload(chatID int, file interface{}) AudioConfig { return AudioConfig{ Chattable: Chattable{ChatID: chatID}, + Fileable: Fileable{File: file}, UseExistingAudio: false, - File: file, } } @@ -73,9 +73,9 @@ func NewAudioUpload(chatID int, file interface{}) AudioConfig { // chatID is where to send it, fileID is the ID of the audio already uploaded. func NewAudioShare(chatID int, fileID string) AudioConfig { return AudioConfig{ - Chattable: Chattable{ChatID: chatID}, + Chattable: Chattable{ChatID: chatID}, + Fileable: Fileable{FileID: fileID}, UseExistingAudio: true, - FileID: fileID, } } @@ -87,8 +87,8 @@ func NewAudioShare(chatID int, fileID string) AudioConfig { func NewDocumentUpload(chatID int, file interface{}) DocumentConfig { return DocumentConfig{ Chattable: Chattable{ChatID: chatID}, + Fileable: Fileable{File: file}, UseExistingDocument: false, - File: file, } } @@ -99,8 +99,8 @@ func NewDocumentUpload(chatID int, file interface{}) DocumentConfig { func NewDocumentShare(chatID int, fileID string) DocumentConfig { return DocumentConfig{ Chattable: Chattable{ChatID: chatID}, + Fileable: Fileable{FileID: fileID}, UseExistingDocument: true, - FileID: fileID, } } @@ -111,8 +111,8 @@ func NewDocumentShare(chatID int, fileID string) DocumentConfig { func NewStickerUpload(chatID int, file interface{}) StickerConfig { return StickerConfig{ Chattable: Chattable{ChatID: chatID}, + Fileable: Fileable{File: file}, UseExistingSticker: false, - File: file, } } @@ -122,9 +122,9 @@ func NewStickerUpload(chatID int, file interface{}) StickerConfig { // chatID is where to send it, fileID is the ID of the sticker already uploaded. func NewStickerShare(chatID int, fileID string) StickerConfig { return StickerConfig{ - Chattable: Chattable{ChatID: chatID}, + Chattable: Chattable{ChatID: chatID}, + Fileable: Fileable{FileID: fileID}, UseExistingSticker: true, - FileID: fileID, } } @@ -136,8 +136,8 @@ func NewStickerShare(chatID int, fileID string) StickerConfig { func NewVideoUpload(chatID int, file interface{}) VideoConfig { return VideoConfig{ Chattable: Chattable{ChatID: chatID}, + Fileable: Fileable{File: file}, UseExistingVideo: false, - File: file, } } @@ -149,7 +149,7 @@ func NewVideoShare(chatID int, fileID string) VideoConfig { return VideoConfig{ Chattable: Chattable{ChatID: chatID}, UseExistingVideo: true, - FileID: fileID, + Fileable: Fileable{FileID: fileID}, } } @@ -161,8 +161,8 @@ func NewVideoShare(chatID int, fileID string) VideoConfig { func NewVoiceUpload(chatID int, file interface{}) VoiceConfig { return VoiceConfig{ Chattable: Chattable{ChatID: chatID}, + Fileable: Fileable{File: file}, UseExistingVoice: false, - File: file, } } @@ -173,8 +173,8 @@ func NewVoiceUpload(chatID int, file interface{}) VoiceConfig { func NewVoiceShare(chatID int, fileID string) VoiceConfig { return VoiceConfig{ Chattable: Chattable{ChatID: chatID}, + Fileable: Fileable{FileID: fileID}, UseExistingVoice: true, - FileID: fileID, } }