@@ -155,6 +155,7 @@ func (owm *OpenWeatherMap) CurrentWeatherFromCoordinates(lat, long float64) (*Cu
155155 return & cwr , nil
156156}
157157
158+
158159func (owm * OpenWeatherMap ) CurrentWeatherFromZip (zip int ) (* CurrentWeatherResponse , error ) {
159160 if owm .API_KEY == "" {
160161 // No API keys present, return error
@@ -167,6 +168,29 @@ func (owm *OpenWeatherMap) CurrentWeatherFromZip(zip int) (*CurrentWeatherRespon
167168 return nil , err
168169 }
169170 var cwr CurrentWeatherResponse
171+
172+ // unmarshal the byte stream into a Go data type
173+ jsonErr := json .Unmarshal (body , & cwr )
174+ if jsonErr != nil {
175+ return nil , jsonErr
176+ }
177+
178+ return & cwr , nil
179+ }
180+
181+
182+ func (owm * OpenWeatherMap ) CurrentWeatherFromCityId (id int ) (* CurrentWeatherResponse , error ) {
183+ if (owm .API_KEY == "" ) {
184+ // No API keys present, return error
185+ return nil , errors .New ("No API keys present" )
186+ }
187+ url := fmt .Sprintf ("http://%s/data/2.5/weather?id=%d&units=imperial&APPID=%s" , API_URL , id , owm .API_KEY )
188+
189+ body , err := makeApiRequest (url )
190+ if (err != nil ) {
191+ return nil , err
192+ }
193+ var cwr CurrentWeatherResponse
170194
171195 // unmarshal the byte stream into a Go data type
172196 jsonErr := json .Unmarshal (body , & cwr )
@@ -177,3 +201,4 @@ func (owm *OpenWeatherMap) CurrentWeatherFromZip(zip int) (*CurrentWeatherRespon
177201 return & cwr , nil
178202}
179203
204+
0 commit comments