city_detail 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +48 -0
- data/Rakefile +1 -0
- data/city_detail.gemspec +27 -0
- data/lib/city_detail.rb +2 -0
- data/lib/city_detail/info.rb +33 -0
- data/lib/city_detail/version.rb +3 -0
- data/spec/city_detail_spec.rb +24 -0
- metadata +137 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Manish Puri
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# CityDetail
|
2
|
+
|
3
|
+
A wrapper for openweathermap.org api.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'city_detail'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install city_detail
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
This is a wrapper for openweathermap.org api. With this gem, You can get details like weather, longitude, latitude, country it belongs to, etc for any given city.
|
22
|
+
|
23
|
+
|
24
|
+
This gem provides u access to following methods..
|
25
|
+
|
26
|
+
|
27
|
+
CityDetail::Info.coord("New York") # => {"lon"=>-74.01, "lat"=>40.71}
|
28
|
+
|
29
|
+
|
30
|
+
CityDetail::Info.weather("New York") # => {"id"=>741, "main"=>"Fog", "description"=>"fog", "icon"=>"50n", "temp"=>272.71, "pressure"=>1014, "humidity"=>92, "temp_min"=>268.15, "temp_max"=>278.15}
|
31
|
+
|
32
|
+
CityDetail::Info.country("New York") # => "United States of America"
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
CityDetail::Info.all("New York")
|
37
|
+
# => {"coord"=>{"lon"=>-74.01, "lat"=>40.71}, "sys"=>{"message"=>0.0513, "country"=>"United States of America", "sunrise"=>1393069152, "sunset"=>1393108777}, "weather"=>[{"id"=>741, "main"=>"Fog", "description"=>"fog", "icon"=>"50n"}, {"id"=>701, "main"=>"Mist", "description"=>"mist", "icon"=>"50n"}], "base"=>"cmc stations", "main"=>{"temp"=>272.71, "pressure"=>1014, "humidity"=>92, "temp_min"=>268.15, "temp_max"=>278.15}, "wind"=>{"speed"=>2.8, "deg"=>258.503}, "clouds"=>{"all"=>1}, "dt"=>1393058100, "id"=>5128581, "name"=>"New York", "cod"=>200}
|
38
|
+
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
1. Fork it ( http://github.com/Manik-Ratnas/city_detail/fork )
|
43
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
44
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
45
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
46
|
+
5. Create new Pull Request
|
47
|
+
|
48
|
+
:collision: :collision: :collision:
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/city_detail.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'city_detail/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "city_detail"
|
8
|
+
spec.version = CityDetail::VERSION
|
9
|
+
spec.authors = ["Manish Puri"]
|
10
|
+
spec.email = ["manishspuri@gmail.com"]
|
11
|
+
spec.summary = %q{Find any city details like coordinates, temperature country. }
|
12
|
+
spec.description = %q{A wrapper for opemweathermap.org api. }
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "open_uri"
|
24
|
+
spec.add_development_dependency "json"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
|
27
|
+
end
|
data/lib/city_detail.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module CityDetail
|
5
|
+
class Info
|
6
|
+
class << self
|
7
|
+
def all(city_name)
|
8
|
+
city=city_name.gsub(' ', '_')
|
9
|
+
request = "http://api.openweathermap.org/data/2.5/weather?q=#{city}"
|
10
|
+
response = open(request).readlines.join
|
11
|
+
details = JSON.parse(response)
|
12
|
+
raise ArgumentError, "Invalid City Passed" if details["message"]
|
13
|
+
details
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
def country(city_name)
|
18
|
+
all(city_name)["sys"]["country"]
|
19
|
+
end
|
20
|
+
|
21
|
+
def weather(city_name)
|
22
|
+
all(city_name)["weather"][0].merge(all(city_name)["main"])
|
23
|
+
end
|
24
|
+
|
25
|
+
def coord(city_name)
|
26
|
+
all(city_name)["coord"]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'city_detail'
|
3
|
+
describe "StringMatchables" do
|
4
|
+
it "should return proper country name" do
|
5
|
+
CityDetail::Info.country("New York").should eq("United States of America")
|
6
|
+
lambda{CityDetail::Info.country("Invalid city")}.should raise_error(ArgumentError)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should return proper coordinate types" do
|
10
|
+
CityDetail::Info.coord("New York")["lon"].should eq(-74.01)
|
11
|
+
CityDetail::Info.coord("New York")["lat"].should eq(40.71)
|
12
|
+
lambda{CityDetail::Info.coord("Invalid city")}.should raise_error(ArgumentError)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return proper weather details" do
|
16
|
+
CityDetail::Info.weather("New York")["temp"].should_not be_nil
|
17
|
+
CityDetail::Info.weather("New York")["temp_min"].should_not be_nil
|
18
|
+
CityDetail::Info.weather("New York")["temp_max"].should_not be_nil
|
19
|
+
CityDetail::Info.weather("New York")["description"].should_not be_nil
|
20
|
+
|
21
|
+
lambda{CityDetail::Info.coord("Invalid city")}.should raise_error(ArgumentError)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: city_detail
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Manish Puri
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-02-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.5'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.5'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: open_uri
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: json
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rspec
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: ! 'A wrapper for opemweathermap.org api. '
|
95
|
+
email:
|
96
|
+
- manishspuri@gmail.com
|
97
|
+
executables: []
|
98
|
+
extensions: []
|
99
|
+
extra_rdoc_files: []
|
100
|
+
files:
|
101
|
+
- .gitignore
|
102
|
+
- Gemfile
|
103
|
+
- LICENSE.txt
|
104
|
+
- README.md
|
105
|
+
- Rakefile
|
106
|
+
- city_detail.gemspec
|
107
|
+
- lib/city_detail.rb
|
108
|
+
- lib/city_detail/info.rb
|
109
|
+
- lib/city_detail/version.rb
|
110
|
+
- spec/city_detail_spec.rb
|
111
|
+
homepage: ''
|
112
|
+
licenses:
|
113
|
+
- MIT
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
none: false
|
120
|
+
requirements:
|
121
|
+
- - ! '>='
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
none: false
|
126
|
+
requirements:
|
127
|
+
- - ! '>='
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
requirements: []
|
131
|
+
rubyforge_project:
|
132
|
+
rubygems_version: 1.8.23
|
133
|
+
signing_key:
|
134
|
+
specification_version: 3
|
135
|
+
summary: Find any city details like coordinates, temperature country.
|
136
|
+
test_files:
|
137
|
+
- spec/city_detail_spec.rb
|