fillmore_test_1 1.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.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/bin/fillmore +9 -0
  3. data/lib/fillmore.rb +45 -0
  4. metadata +59 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6fa7e029c01ed39433df5eeff026edd0b1e6c728
4
+ data.tar.gz: b3e24ad61a6b67181de49f005877e300fefe12dc
5
+ SHA512:
6
+ metadata.gz: 50c554d05d02a5d14ea908a508f29c7c38052edab4b3a9aaf81c8d2e679abec8c3fcb558ffc268aa162089c479bbe72f062a365dd4a6cc1f3da7dbe073821d97
7
+ data.tar.gz: 125297123d636689015a31f18aa8cf2d7ec7b928fb4d345bdd94185216dbe8ff7befd874441682f7311ad1b3de53f14d66bd21e1062732a91431c3bf75b369dd
data/bin/fillmore ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'fillmore'
4
+
5
+ if ARGV.size < 1
6
+ puts "You need to provide a location"
7
+ else
8
+ Fillmore.new.run ARGV.join(" ")
9
+ end
data/lib/fillmore.rb ADDED
@@ -0,0 +1,45 @@
1
+ require 'httparty'
2
+ require 'uri'
3
+ require 'pry'
4
+
5
+ class Fillmore
6
+ API_URL = 'http://api.openweathermap.org/data/2.5/weather'
7
+
8
+ def fetch(location)
9
+ response = HTTParty.get "#{API_URL}?q=#{URI.escape(location)}"
10
+ # binding.pry
11
+ JSON.parse response.body
12
+ end
13
+
14
+ def format(obj)
15
+ outcome = "#{obj['name']}"
16
+
17
+ # binding.pry
18
+
19
+ if !obj['sys'].nil?
20
+ country = obj['sys']['country']
21
+ if !country.nil?
22
+ outcome += " (#{country})"
23
+ end
24
+
25
+ outcome += "\n #{obj['weather'].first['main']}"
26
+
27
+ description = obj['weather'].first['description']
28
+ if !description.nil?
29
+ outcome += " - #{description}"
30
+ end
31
+
32
+ temp = obj['main']['temp']
33
+ celsius = temp.to_f - 273.15
34
+ fahrenheit = celsius * 1.8 + 32
35
+ outcome += "\n #{celsius.to_i}°C / #{fahrenheit.to_i}°F"
36
+
37
+ outcome
38
+ end
39
+ end
40
+
41
+ def run(location)
42
+ puts format(fetch(location))
43
+ end
44
+
45
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fillmore_test_1
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Al Pacino
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description:
28
+ email:
29
+ executables:
30
+ - fillmore
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - bin/fillmore
35
+ - lib/fillmore.rb
36
+ homepage:
37
+ licenses: []
38
+ metadata: {}
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 2.2.2
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: Fetches weather forecast.
59
+ test_files: []