wor-weather 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.rspec +2 -0
- data/.rubocop.yml +45 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/README.md +35 -0
- data/Rakefile +6 -0
- data/bin/wor-weather +73 -0
- data/lib/wor/weather.rb +34 -0
- data/lib/wor/weather/version.rb +5 -0
- data/wor-weather.gemspec +35 -0
- metadata +182 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8ea163206ee399f874e9ecb19af63b70f73f7d85
|
4
|
+
data.tar.gz: d0ca90195c034ad38e7ea21c8788a96b11f8540c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d56effd8879c291addb0548f21f63036f6e5384ad968e57b0f1c32a178819146cfd26a486753052d7437b6d25e25762a8b3a1757d2cabb62476c04d6322bb375
|
7
|
+
data.tar.gz: 579dfa1132786f32ad0bfb3efe83e006c1ba6d1c688f1368f05aec1b8b502a96e4576d6b6dfbe61871f803f17934b6f7446b945aa068fe9e97d672e517eee27e
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
Rails:
|
2
|
+
Enabled: true
|
3
|
+
|
4
|
+
AllCops:
|
5
|
+
TargetRubyVersion: 2.3
|
6
|
+
|
7
|
+
Documentation:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
LineLength:
|
11
|
+
Max: 99
|
12
|
+
|
13
|
+
HasAndBelongsToMany:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Style/FrozenStringLiteralComment:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
BlockLength:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
# rubocop-rspec custom configurations
|
23
|
+
|
24
|
+
require: rubocop-rspec
|
25
|
+
|
26
|
+
Style/VariableNumber:
|
27
|
+
EnforcedStyle: snake_case
|
28
|
+
|
29
|
+
RSpec/ExampleLength:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
RSpec/AnyInstance:
|
33
|
+
Enabled: false
|
34
|
+
|
35
|
+
RSpec/MultipleExpectations:
|
36
|
+
Enabled: false
|
37
|
+
|
38
|
+
RSpec/NestedGroups:
|
39
|
+
Max: 5
|
40
|
+
|
41
|
+
Lint/AmbiguousBlockAssociation:
|
42
|
+
Enabled: false
|
43
|
+
|
44
|
+
RSpec/LetSetup:
|
45
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Wor::Weather
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/wor/weather`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'wor-weather'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install wor-weather
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/wor-weather.
|
data/Rakefile
ADDED
data/bin/wor-weather
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'wor/weather'
|
4
|
+
require 'wor/weather/version'
|
5
|
+
require 'colorize'
|
6
|
+
require 'optparse'
|
7
|
+
|
8
|
+
VALID_UNITS = %i[metric imperial].freeze
|
9
|
+
|
10
|
+
options = {
|
11
|
+
temp: false,
|
12
|
+
unit: :metric,
|
13
|
+
city: nil,
|
14
|
+
api_key: nil
|
15
|
+
}
|
16
|
+
|
17
|
+
parser = OptionParser.new do |opts|
|
18
|
+
opts.banner = 'Usage: wor-weather -k API_KEY -c CITY [-t] [-u imperial|metric]'
|
19
|
+
|
20
|
+
opts.on('-t', '--temp', 'Returns the temperature of the city') do
|
21
|
+
options[:temp] = true
|
22
|
+
end
|
23
|
+
|
24
|
+
opts.on('-c CITY', '--city CITY', 'City to be used') do |city|
|
25
|
+
options[:city] = city
|
26
|
+
end
|
27
|
+
|
28
|
+
opts.on('-k KEY', '--key KEY', 'API key to be used') do |key|
|
29
|
+
options[:api_key] = key
|
30
|
+
end
|
31
|
+
|
32
|
+
opts.on(
|
33
|
+
'-u UNIT',
|
34
|
+
'--unit UNIT',
|
35
|
+
'Unit type to display. Valid options: imperial, metric. Default: metric'
|
36
|
+
) do |unit|
|
37
|
+
|
38
|
+
unless VALID_UNITS.include? unit.to_sym
|
39
|
+
puts "Invalid unit. Valid units are: #{VALID_UNITS.map(&:to_s)}".colorize(:red)
|
40
|
+
exit
|
41
|
+
end
|
42
|
+
|
43
|
+
options[:unit] = unit.to_sym
|
44
|
+
end
|
45
|
+
|
46
|
+
opts.on('-v', '--version', 'Displays version') do
|
47
|
+
puts "Wor-Weather Version: #{Wor::Weather::VERSION}".colorize(:blue)
|
48
|
+
exit
|
49
|
+
end
|
50
|
+
|
51
|
+
opts.on('-h', '--help', 'Displays help') do
|
52
|
+
puts opts
|
53
|
+
exit
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
parser.parse!
|
58
|
+
|
59
|
+
unless options[:city] && options[:api_key]
|
60
|
+
puts 'City and API key are mandatory'.colorize(:red)
|
61
|
+
exit
|
62
|
+
end
|
63
|
+
|
64
|
+
Wor::Weather.configure do |c|
|
65
|
+
c.api_key = options[:api_key]
|
66
|
+
c.unit_type = options[:unit]
|
67
|
+
end
|
68
|
+
|
69
|
+
if options[:temp]
|
70
|
+
puts Wor::Weather.temp(options[:city])
|
71
|
+
else
|
72
|
+
puts 'Invalid option'.colorize(:red)
|
73
|
+
end
|
data/lib/wor/weather.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'wor/weather/version'
|
2
|
+
require 'httparty'
|
3
|
+
|
4
|
+
module Wor
|
5
|
+
module Weather
|
6
|
+
API_URL = 'http://api.openweathermap.org/data/2.5'.freeze
|
7
|
+
|
8
|
+
@config = {
|
9
|
+
api_key: '',
|
10
|
+
unit_type: :metric
|
11
|
+
}
|
12
|
+
|
13
|
+
def self.configure
|
14
|
+
yield self
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.api_key=(api_key)
|
18
|
+
@config[:api_key] = api_key
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.unit_type=(unit_type)
|
22
|
+
@config[:unit_type] = unit_type
|
23
|
+
end
|
24
|
+
|
25
|
+
class << self
|
26
|
+
def temp(city)
|
27
|
+
response = HTTParty.get(
|
28
|
+
API_URL + "/weather?q=#{city}&appid=#{@config[:api_key]}&units=#{@config[:unit_type]}"
|
29
|
+
)
|
30
|
+
response['main']['temp']
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/wor-weather.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'wor/weather/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'wor-weather'
|
8
|
+
spec.version = Wor::Weather::VERSION
|
9
|
+
spec.authors = ['alebian']
|
10
|
+
spec.email = ['alebezdjian@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Simple weather library'
|
13
|
+
spec.description = 'Simple weather library'
|
14
|
+
spec.homepage = 'https://github.com/wolox/wor-weather'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = 'bin'
|
20
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
|
+
spec.test_files = spec.files.grep(%r{^(test|spec)/})
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
spec.license = 'MIT'
|
24
|
+
|
25
|
+
spec.add_dependency 'httparty', '~> 0.15'
|
26
|
+
spec.add_dependency 'colorize', '~> 0.8'
|
27
|
+
|
28
|
+
spec.add_development_dependency 'bundler', '~> 1.15'
|
29
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
30
|
+
spec.add_development_dependency 'rspec', '~> 3.6'
|
31
|
+
spec.add_development_dependency 'byebug', '~> 9.0'
|
32
|
+
spec.add_development_dependency 'rubocop', '~> 0.49'
|
33
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 1.15'
|
34
|
+
spec.add_development_dependency 'webmock', '~> 3.0'
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,182 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wor-weather
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- alebian
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-07-25 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.15'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: colorize
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.8'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.8'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.15'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.15'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.6'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.6'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: byebug
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '9.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '9.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.49'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.49'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop-rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.15'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1.15'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: webmock
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '3.0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '3.0'
|
139
|
+
description: Simple weather library
|
140
|
+
email:
|
141
|
+
- alebezdjian@gmail.com
|
142
|
+
executables:
|
143
|
+
- wor-weather
|
144
|
+
extensions: []
|
145
|
+
extra_rdoc_files: []
|
146
|
+
files:
|
147
|
+
- ".gitignore"
|
148
|
+
- ".rspec"
|
149
|
+
- ".rubocop.yml"
|
150
|
+
- ".travis.yml"
|
151
|
+
- Gemfile
|
152
|
+
- README.md
|
153
|
+
- Rakefile
|
154
|
+
- bin/wor-weather
|
155
|
+
- lib/wor/weather.rb
|
156
|
+
- lib/wor/weather/version.rb
|
157
|
+
- wor-weather.gemspec
|
158
|
+
homepage: https://github.com/wolox/wor-weather
|
159
|
+
licenses:
|
160
|
+
- MIT
|
161
|
+
metadata: {}
|
162
|
+
post_install_message:
|
163
|
+
rdoc_options: []
|
164
|
+
require_paths:
|
165
|
+
- lib
|
166
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
167
|
+
requirements:
|
168
|
+
- - ">="
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
version: '0'
|
171
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
172
|
+
requirements:
|
173
|
+
- - ">="
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
version: '0'
|
176
|
+
requirements: []
|
177
|
+
rubyforge_project:
|
178
|
+
rubygems_version: 2.6.8
|
179
|
+
signing_key:
|
180
|
+
specification_version: 4
|
181
|
+
summary: Simple weather library
|
182
|
+
test_files: []
|