open_weather_map_api 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/open_weather_map_api.rb +60 -0
- metadata +43 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 96ecd13414e8a16ca63fa2ee5bf4f0a191d1290420f9bfb0be80e02f4612290c
|
4
|
+
data.tar.gz: 0acc84ea9119e80596b9ea3704fd221f125cf1d5dd862ae3a36578b409d30d2e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 52d4d2bfc4b32e892e6dd387538655918a969a6a687cb80541321c7c0328ef578e9154ff4019656ca9684740649122aacc57343afaaa97fcd04aed8624037270
|
7
|
+
data.tar.gz: b1e12c74565edfec757c174f5c938bd5fb0c1f1baa4df7b7f98995e8815064ee11db39198d55478f4616df1a87e2cf0870f0e3b7d7221f24d66cf17b3c10ace6
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/http'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
class OpenWeatherMapApi
|
6
|
+
class << self
|
7
|
+
def get_forecast(options = {})
|
8
|
+
@path = "forecast"
|
9
|
+
@query = build_query(options)
|
10
|
+
begin
|
11
|
+
if response.is_a?(Net::HTTPSuccess)
|
12
|
+
return JSON.parse(response.body)
|
13
|
+
end
|
14
|
+
rescue
|
15
|
+
return nil
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_weather(options = {})
|
20
|
+
@path = "weather"
|
21
|
+
@query = build_query(options)
|
22
|
+
begin
|
23
|
+
if response.is_a?(Net::HTTPSuccess)
|
24
|
+
return JSON.parse(response.body)
|
25
|
+
end
|
26
|
+
rescue => err
|
27
|
+
puts err
|
28
|
+
return nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def build_query(options)
|
35
|
+
query = ""
|
36
|
+
options.each do |key, value|
|
37
|
+
query += "#{key}=#{value}&"
|
38
|
+
end
|
39
|
+
query
|
40
|
+
end
|
41
|
+
|
42
|
+
def uri
|
43
|
+
URI::HTTPS.build(
|
44
|
+
host: "api.openweathermap.org",
|
45
|
+
path: "/data/2.5/#{@path}",
|
46
|
+
query: @query
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
50
|
+
def response
|
51
|
+
response = Net::HTTP.start(uri.host, use_ssl: true) do |http|
|
52
|
+
http.request(request)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def request
|
57
|
+
Net::HTTP::Get.new(uri)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
metadata
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: open_weather_map_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Wellington Gomes Graciani
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-02-24 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Get Weather and Forecast for the city you want easily
|
14
|
+
email: wellingtongg12@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/open_weather_map_api.rb
|
20
|
+
homepage: https://github.com/Wellingtongg/open_weather_map_api
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubygems_version: 3.0.3
|
40
|
+
signing_key:
|
41
|
+
specification_version: 4
|
42
|
+
summary: Implementation of OpenWeatherMap API
|
43
|
+
test_files: []
|