openweather2 0.1.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ccf1cfba264d2b8ed7b4935947ed17ce06b29479
4
+ data.tar.gz: c74dad24bfb1fde86ca060faca608a5906ec79b0
5
+ SHA512:
6
+ metadata.gz: 739e8faecf663a5d0cdb927f021d935611d07836298156e320ccbe6acf40b6bae032489d4c667200d8b7c554d07a42df86ef389dc1945b30ed9626ece03ff159
7
+ data.tar.gz: 5187f5b69d7992f9c1a9e9e2f33f735804c5be1264514af98d1f2c7bab46a395853c47cdee8b71342d93dac697ada1517831740c9309a1276d10bbd1f632a13c
data/.gitignore ADDED
@@ -0,0 +1,24 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .ruby-gemset
24
+ .ruby-version
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in openweather2.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Lucas Ocon
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # Openweather2
2
+
3
+ This gem is an abstraction to the OpenWeatherMap API.
4
+
5
+ This gem provide the weather from numerous regions around the world.
6
+
7
+ Also you can get some data on the gem response:
8
+ * City name
9
+ * Longitude
10
+ * Latitude
11
+ * Temperature
12
+ * Pressure
13
+ * Humidity
14
+ * Min temperature
15
+ * Max temperature
16
+ * Clouds
17
+ * Wind speed
18
+ * Wind angle
19
+
20
+ You can get your APP ID from the OpenWeatherMap website.
21
+
22
+ http://openweathermap.org/appid#get
23
+
24
+ ## Installation
25
+
26
+ Add this line to your application's Gemfile:
27
+
28
+ ```ruby
29
+ gem 'openweather2'
30
+ ```
31
+
32
+ And then execute:
33
+
34
+ $ bundle
35
+
36
+ Or install it yourself as:
37
+
38
+ $ gem install openweather2
39
+
40
+ ## Usage
41
+
42
+ Usage:
43
+
44
+ ```ruby
45
+ require "openweather2"
46
+
47
+ Openweather2.configure do |config|
48
+ config.endpoint = 'http://api.openweathermap.org/data/2.5/weather'
49
+ config.apikey = YOUR APP ID
50
+ end
51
+
52
+ Openweather2.weather('london')
53
+
54
+ ```
55
+
56
+ ## Development
57
+
58
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
59
+
60
+ 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).
61
+
62
+ ## Contributing
63
+
64
+ Be free to report and send your pull request.
65
+
66
+ Bug reports and pull requests are welcome on GitHub at https://github.com/lucasocon/openweather.
67
+
68
+ Contributors:
69
+ * Lucas Ocon (lucasocon)
70
+
71
+ ## License
72
+
73
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
74
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "openweather2"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ require "openweather2/version"
2
+ require "openweather2/client"
3
+ require "openweather2/weather"
@@ -0,0 +1,89 @@
1
+ require "uri"
2
+ require "net/http"
3
+ require "json"
4
+
5
+ module Openweather2
6
+
7
+ class << self
8
+ attr_accessor :configuration
9
+ end
10
+
11
+ class Configuration
12
+ attr_accessor :endpoint
13
+ attr_accessor :apikey
14
+ end
15
+
16
+ class UnprocessableError < RuntimeError; end
17
+ class ForbiddenError < RuntimeError; end
18
+ class UnknownResponse < RuntimeError; end
19
+
20
+ extend self
21
+
22
+ def configure
23
+ self.configuration ||= Configuration.new
24
+ yield(configuration)
25
+ end
26
+
27
+ def weather(city)
28
+ configure_required!
29
+
30
+ uri = URI(Openweather2.configuration.endpoint)
31
+ uri.query = URI.encode_www_form(default_params.merge(:q => city))
32
+ req = Net::HTTP::Get.new(uri.request_uri)
33
+
34
+ http_params = [uri.hostname, uri.port, use_ssl: uri.scheme == 'https']
35
+ res = Net::HTTP.start(*http_params) do |http|
36
+ http.request(req)
37
+ end
38
+
39
+ case res
40
+ when Net::HTTPSuccess
41
+ json = JSON.parse(res.body)
42
+ Openweather2::Weather.new(json)
43
+
44
+ when Net::HTTPUnprocessableEntity
45
+ raise UnprocessableError, "Bad URI param!"
46
+ else
47
+ raise UnknownResponse, "Something was wrong!"
48
+ end
49
+ end
50
+
51
+ private
52
+
53
+ def configure_required!
54
+ if Openweather2.configuration.instance_variables.size < 2
55
+ raise ArgumentError, "You must configure Openweather2"
56
+ end
57
+ end
58
+
59
+ def default_params
60
+ {:APPID => Openweather2.configuration.apikey }
61
+ end
62
+
63
+ def do_request(req)
64
+ configure_required!
65
+
66
+ endpoint_uri = URI(Openweather2.configuration.endpoint)
67
+
68
+
69
+ http_params = [
70
+ endpoint_uri.hostname,
71
+ endpoint_uri.port,
72
+ use_ssl: uri.scheme == 'https'
73
+ ]
74
+
75
+ res = Net::HTTP.start(*http_params) do |http|
76
+ http.request(req)
77
+ end
78
+
79
+ case res
80
+ when Net::HTTPSuccess
81
+ JSON.parse(res.body)
82
+ when Net::HTTPUnprocessableEntity
83
+ raise UnprocessableError, "Bad URI param!"
84
+ else
85
+ raise UnknownResponse, "Something was wrong!"
86
+ end
87
+ end
88
+
89
+ end
@@ -0,0 +1,3 @@
1
+ module Openweather2
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,21 @@
1
+ module Openweather2
2
+ class Weather
3
+
4
+ attr_reader :city, :longitude, :latitude, :pressure, :humidity, :clouds,
5
+ :temperature, :min_temperature, :max_temperature, :wind_speed, :wind_angle, :sunrise, :sunset
6
+
7
+ def initialize(json)
8
+ @city = json['name']
9
+ @longitude = json['coord']['lon']
10
+ @latitude = json['coord']['lat']
11
+ @temperature = json['main']['temp']
12
+ @pressure = json['main']['pressure']
13
+ @humidity = json['main']['humidity']
14
+ @min_temperature = json['main']['temp_min']
15
+ @max_temperature = json['main']['temp_max']
16
+ @clouds = json['clouds']['all']
17
+ @wind_speed = json['wind']['speed']
18
+ @wind_angle = json['wind']['deg']
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'openweather2/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "openweather2"
8
+ spec.version = Openweather2::VERSION
9
+ spec.authors = ["Lucas Ocon"]
10
+ spec.email = ["lucas_masterclas@hotmail.com"]
11
+
12
+ spec.summary = %q{Wrapper the OpenWeatherMap API}
13
+ spec.description = %q{A minimal Ruby Gem to wrap the OpenWeatherMap API http://openweathermap.org}
14
+ spec.homepage = "https://github.com/lucasocon/openweather."
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_dependency "json"
25
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: openweather2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Lucas Ocon
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: A minimal Ruby Gem to wrap the OpenWeatherMap API http://openweathermap.org
56
+ email:
57
+ - lucas_masterclas@hotmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - bin/console
68
+ - bin/setup
69
+ - lib/openweather2.rb
70
+ - lib/openweather2/client.rb
71
+ - lib/openweather2/version.rb
72
+ - lib/openweather2/weather.rb
73
+ - openweather.gemspec
74
+ homepage: https://github.com/lucasocon/openweather.
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.4.8
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Wrapper the OpenWeatherMap API
98
+ test_files: []