fillmore 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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: b68a3bad5e6bb50d46d10d6c080c1316e67a7ec0
4
+ data.tar.gz: bee39eafed3499c7db87ffd68b18bd029a903ba2
5
+ SHA512:
6
+ metadata.gz: 42bf28d44a985b97cc603d5179373febe0ac8312f7595e09a8237d8f0376c4743368c8ae1eb58c9764a119758b7a5d2abec3d8e9bc21490985d20928c199b129
7
+ data.tar.gz: a35216d7a6453871c7d643e43f7db6767f672e19741417473e3b26238e35f2c3eb4fa6bfe7e8c7dea89116fc54970b28371c9a25424ba49962eda31414b8769d
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
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: []