|
2 | 2 | <img src="https://openweathermap.org/themes/openweathermap/assets/vendor/owm/img/logo_OpenWeatherMap_orange.svg" height="50"/> |
3 | 3 | <h1>OpenWeatherMap - The Ruby implementation</h1> |
4 | 4 | <p>With this gem, you can easily fetch the API to receive informations about weather.</p> |
5 | | - <a href="LICENSE">License</a> - <a href="https://www.rubydoc.info/gems/openweathermap">Documentation</a> |
| 5 | + <a href="LICENSE">License</a> - <a href="http://rubydoc.info/gems/openweathermap">RubyDoc</a> |
6 | 6 | </div> |
| 7 | + |
| 8 | +- [📌 Requirements](#-requirements) |
| 9 | +- [🔧 Setup](#-setup) |
| 10 | + - [Quick installation](#quick-installation) |
| 11 | + - [Gemfile](#gemfile) |
| 12 | + - [Build](#build) |
| 13 | +- [⌨ Basic interactions](#-basic-interactions) |
| 14 | + - [Setup the API](#setup-the-api) |
| 15 | + - [Get current weather](#get-current-weather) |
| 16 | + - [Get forecast](#get-forecast) |
| 17 | + - [Possible exceptions](#possible-exceptions) |
| 18 | +- [📜 Credits](#-credits) |
| 19 | +- [🔐 License](#-license) |
| 20 | + |
| 21 | +## 📌 Requirements |
| 22 | + |
| 23 | +This library requires an updated version of Ruby. |
| 24 | + |
| 25 | +## 🔧 Setup |
| 26 | + |
| 27 | +### Quick installation |
| 28 | + |
| 29 | +If you want to quickly test the library, you can install it using the `install` command of Ruby Gem. |
| 30 | + |
| 31 | +```bash |
| 32 | +gem install openweathermap |
| 33 | +``` |
| 34 | + |
| 35 | +### Gemfile |
| 36 | + |
| 37 | +If you setup the library for medium or big projects, it's recommended to write it in your Gemfile. |
| 38 | + |
| 39 | +```gemfile |
| 40 | +gem 'openweathermap', '~> 0.2.2' |
| 41 | +``` |
| 42 | + |
| 43 | +After, use again the `install` command, but without the package name. |
| 44 | + |
| 45 | +```bash |
| 46 | +gem install |
| 47 | +``` |
| 48 | + |
| 49 | +### Build |
| 50 | + |
| 51 | +You can also compile it by yourself. First, clone the repository. |
| 52 | + |
| 53 | +```bash |
| 54 | +git clone https://github.com/BecauseOfProg/openweathermap-ruby.git # HTTP |
| 55 | + [email protected]:BecauseOfProg/openweathermap-ruby.git # SSH |
| 56 | +``` |
| 57 | + |
| 58 | +Then, build the gemspec file to create the gem. |
| 59 | + |
| 60 | +```bash |
| 61 | +gem build ./openweathermap.gemspec |
| 62 | +``` |
| 63 | + |
| 64 | +Finally, install it on your system. |
| 65 | + |
| 66 | +```bash |
| 67 | +gem install ./openweathermap-0.2.2.gem |
| 68 | +``` |
| 69 | + |
| 70 | +## ⌨ Basic interactions |
| 71 | + |
| 72 | +Once you finished installing the library, you're ready to play around. |
| 73 | + |
| 74 | +### Setup the API |
| 75 | + |
| 76 | +First of all, include the `openweathermap` library in your project : |
| 77 | + |
| 78 | +```ruby |
| 79 | +include 'openweathermap' |
| 80 | +``` |
| 81 | + |
| 82 | +Then, we must initialize an `API` object in the `OpenWeatherMap` module, that we'll use to get our weather data. |
| 83 | + |
| 84 | +```ruby |
| 85 | +api = OpenWeatherMap::API.new(API_KEY, 'en', 'metric') |
| 86 | +``` |
| 87 | + |
| 88 | +The constructor takes three parameters : |
| 89 | + |
| 90 | +- The first is an API key, that can be generated on the [OpenWeatherMap website](https://openweathermap.org/appid) |
| 91 | +- The second is the language of the data. It can be one of these : Arabic - ar, Bulgarian - bg, Catalan - ca, Czech - cz, German - de, Greek - el, English - en, Persian (Farsi) - fa, Finnish - fi, French - fr, Galician - gl, Croatian - hr, Hungarian - hu, Italian - it, Japanese - ja, Korean - kr, Latvian - la, Lithuanian - lt, Macedonian - mk, Dutch - nl, Polish - pl, Portuguese - pt, Romanian - ro, Russian - ru, Swedish - se, Slovak - sk, Slovenian - sl, Spanish - es, Turkish - tr, Ukrainian - ua, Vietnamese - vi, Chinese Simplified - zh_cn, Chinese Traditional - zh_tw. |
| 92 | +- The third is the unit system. It can be one of these : |
| 93 | + - none (temperatures in Kelvin) |
| 94 | + - metric (temperatures in Celsius) |
| 95 | + - imperial (temperatures in Fahrenheit) |
| 96 | + |
| 97 | +### Get current weather |
| 98 | + |
| 99 | +To get the current weather at a certain city anywhere in the world, use the `current` method of the API object : |
| 100 | + |
| 101 | +```ruby |
| 102 | +api.current('Lyon,FR') |
| 103 | +``` |
| 104 | + |
| 105 | +It only takes one parameter : the location. It can be one of this type : |
| 106 | + |
| 107 | +- A simple string : search by city name. To have more precision, it can be completed with the country code separated by a comma |
| 108 | +- An integer : search by city ID (refer to [OpenWeatherMap](http://bulk.openweathermap.org/sample/city.list.json.gz)) |
| 109 | +- An array : search by coordinates (format : [longitude, latitude]) |
| 110 | + |
| 111 | +The method will return a `OpenWeatherMap::CurrentWeather` object that you can explore [on RubyDoc](http://rubydoc.info/gems/openweathermap/0.2.2/OpenWeatherMap/CurrentWeather). |
| 112 | + |
| 113 | +### Get forecast |
| 114 | + |
| 115 | +To get the forecast for a certain city anywhere in the world, use the `forecast` method of the API object : |
| 116 | + |
| 117 | +```ruby |
| 118 | +api.forecast('Paris,FR') |
| 119 | +``` |
| 120 | + |
| 121 | +Its parameter is the same as the `current` method. It will return a `OpenWeatherMap::Forecast` object that you can explore [on RubyDoc](http://rubydoc.info/gems/openweathermap/0.2.2/OpenWeatherMap/Forecast). |
| 122 | + |
| 123 | +### Possible exceptions |
| 124 | + |
| 125 | +Your requests may return exceptions that are in the `OpenWeatherMap::Exceptions` module : |
| 126 | + |
| 127 | +- An `Unauthorized` exception, caused when your API key is wrong |
| 128 | +- An `UnknownLocation` exception, caused if the location you wrote is wrong |
| 129 | + |
| 130 | +These exceptions will have in their body the message sent by the OpenWeatherMap API, so you can easily debug them. |
| 131 | + |
| 132 | +## 📜 Credits |
| 133 | + |
| 134 | +- Used service : [OpenWeatherMap](https://openweathermap.org) |
| 135 | +- Maintainer : [Exybore](https://github.com/exybore) |
| 136 | + |
| 137 | +## 🔐 License |
| 138 | + |
| 139 | +MIT License |
| 140 | + |
| 141 | +Copyright (c) 2019 BecauseOfProg |
| 142 | + |
| 143 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 144 | +of this software and associated documentation files (the "Software"), to deal |
| 145 | +in the Software without restriction, including without limitation the rights |
| 146 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 147 | +copies of the Software, and to permit persons to whom the Software is |
| 148 | +furnished to do so, subject to the following conditions: |
| 149 | + |
| 150 | +The above copyright notice and this permission notice shall be included in all |
| 151 | +copies or substantial portions of the Software. |
| 152 | + |
| 153 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 154 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 155 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 156 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 157 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 158 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 159 | +SOFTWARE. |
0 commit comments