owa 0.1.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.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/README.md +58 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/owa.rb +29 -0
- data/lib/owa/configuration.rb +5 -0
- data/lib/owa/current.rb +17 -0
- data/lib/owa/errors.rb +20 -0
- data/lib/owa/requests/http_client.rb +21 -0
- data/lib/owa/requests/options/city.rb +22 -0
- data/lib/owa/requests/options/geocode.rb +17 -0
- data/lib/owa/requests/parser.rb +19 -0
- data/lib/owa/requests/weather.rb +16 -0
- data/lib/owa/version.rb +3 -0
- data/owa.gemspec +30 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 88d8bef6dd5b6f2fb71e2f3d9612cfa754afb477
|
4
|
+
data.tar.gz: 3b7bc6cf50a4fe6b95fefdfcc34cb898dfdb860e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 91c6ab8e5a44f906e35da676d2fbd96632e5ae19eb51b335f733d4d097b86ad04b917ec8ce6cd827d2d09ac2808ebf7900697b1c795070a0809520eced330702
|
7
|
+
data.tar.gz: 8bb18bbe9e623a7df4e2d69d4c9d8656024ae478075ca9f2f8dd84daa9c9cb7fd4f04686e04ae28cef98597c22a5a31f8a035b2700cb60fa0b3780b9a273b36d
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at sltoussi@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# Owa (OpenWeatherApi)
|
2
|
+
|
3
|
+
This is yet another API client for the https://openweathermap.org. This implimentation aims for simplicity with small objects that are mostly closed for modification and are having one responsibility.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'owa'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install owa
|
19
|
+
|
20
|
+
You will need to initialize it after installation. If you are using this gem in a Rails application you can add the initialization in your `config/initializers/owa.rb`:
|
21
|
+
|
22
|
+
``` ruby
|
23
|
+
Owa.configure do |config|
|
24
|
+
config.api_url="https://api.openweathermap.org/data/2.5"
|
25
|
+
config.appid="your_appid_from_owm_api"
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
At this moment there are only two ways to use this client(more to be implemented soon):
|
32
|
+
|
33
|
+
- To get a weather by a City and Countrycode. CountryCode can be used optionally.
|
34
|
+
|
35
|
+
```
|
36
|
+
Owa::Current.by_city("berlin", "DE")
|
37
|
+
# Or
|
38
|
+
Owa::Current.by_city("berlin")
|
39
|
+
```
|
40
|
+
|
41
|
+
- To get the weather by geocode.
|
42
|
+
|
43
|
+
```
|
44
|
+
Owa::Current.by_geocode("130", "80")
|
45
|
+
```
|
46
|
+
|
47
|
+
Note that on the events that API response is not a desired weather report this client raises errors with some messages which can be used to handle the error events and lets users know what went wrong.
|
48
|
+
|
49
|
+
## Development
|
50
|
+
|
51
|
+
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.
|
52
|
+
|
53
|
+
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).
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/hosseintoussi/owa. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
58
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "owa"
|
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(__FILE__)
|
data/bin/setup
ADDED
data/lib/owa.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require "faraday"
|
2
|
+
require_relative "owa/version"
|
3
|
+
require_relative "owa/current"
|
4
|
+
require_relative "owa/errors"
|
5
|
+
require_relative "owa/configuration"
|
6
|
+
require_relative "owa/requests/http_client"
|
7
|
+
require_relative "owa/requests/parser"
|
8
|
+
require_relative "owa/requests/weather"
|
9
|
+
require_relative "owa/requests/options/city"
|
10
|
+
require_relative "owa/requests/options/geocode"
|
11
|
+
|
12
|
+
|
13
|
+
module Owa
|
14
|
+
class << self
|
15
|
+
attr_writer :configuration
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.configuration
|
19
|
+
@configuration ||= Configuration.new
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.reset
|
23
|
+
@configuration = Configuration.new
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.configure
|
27
|
+
yield(configuration)
|
28
|
+
end
|
29
|
+
end
|
data/lib/owa/current.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module Owa
|
2
|
+
class Current
|
3
|
+
def self.by_city(city, country_code=nil)
|
4
|
+
get_weather_with(Requests::Options::City.new(city, country_code))
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.by_geocode(lon, lat)
|
8
|
+
get_weather_with(Requests::Options::Geocode.new(lon, lat))
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def self.get_weather_with(options)
|
14
|
+
Requests::Weather.new(options).call
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/owa/errors.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Owa
|
2
|
+
class OwaErrors < StandardError; end
|
3
|
+
class BadRequest < OwaErrors
|
4
|
+
def message
|
5
|
+
"That was a bad request"
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class Unauthorized < OwaErrors
|
10
|
+
def message
|
11
|
+
"Looks like you are not authorized"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class NotFound < OwaErrors
|
16
|
+
def message
|
17
|
+
"I couldn't find that"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Owa
|
2
|
+
module Requests
|
3
|
+
class HttpClient
|
4
|
+
attr_reader :conn
|
5
|
+
|
6
|
+
def initialize(conn: nil)
|
7
|
+
@conn = conn || Faraday.new(url: Owa::configuration.api_url)
|
8
|
+
end
|
9
|
+
|
10
|
+
def get(endpoint, params = {})
|
11
|
+
conn.get(endpoint, default_params.merge(params))
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def default_params
|
17
|
+
{ appid: Owa::configuration.appid }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Owa
|
2
|
+
module Requests
|
3
|
+
module Options
|
4
|
+
class City
|
5
|
+
def initialize(city, country_code=nil)
|
6
|
+
@city = city
|
7
|
+
@country_code = country_code
|
8
|
+
end
|
9
|
+
|
10
|
+
def call
|
11
|
+
{ q: query }
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def query
|
17
|
+
[@city, @country_code].compact.join(",")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "json"
|
2
|
+
module Owa
|
3
|
+
module Requests
|
4
|
+
class Parser
|
5
|
+
def call(response)
|
6
|
+
case response.status
|
7
|
+
when 400
|
8
|
+
raise BadRequest.new
|
9
|
+
when 401
|
10
|
+
raise Unauthorized.new
|
11
|
+
when 404
|
12
|
+
raise NotFound.new
|
13
|
+
else
|
14
|
+
JSON.parse(response.body, object_class: OpenStruct)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Owa
|
2
|
+
module Requests
|
3
|
+
class Weather
|
4
|
+
def initialize(options, parser: Parser.new, http_client: HttpClient.new)
|
5
|
+
@parser = parser
|
6
|
+
@http_client = http_client
|
7
|
+
@options = options.call
|
8
|
+
end
|
9
|
+
|
10
|
+
def call
|
11
|
+
response = @http_client.get("weather/", @options)
|
12
|
+
@parser.call(response)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/owa/version.rb
ADDED
data/owa.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "owa/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "owa"
|
8
|
+
spec.version = Owa::VERSION
|
9
|
+
spec.authors = ["hosseintoussi"]
|
10
|
+
spec.email = ["sltoussi@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{OWM API client}
|
13
|
+
spec.description = %q{This gem is a simple client for OWM}
|
14
|
+
spec.homepage = ""
|
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 = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.6"
|
26
|
+
spec.add_development_dependency "pry"
|
27
|
+
|
28
|
+
|
29
|
+
spec.add_runtime_dependency "faraday"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: owa
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- hosseintoussi
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-15 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.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: faraday
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: This gem is a simple client for OWM
|
84
|
+
email:
|
85
|
+
- sltoussi@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".travis.yml"
|
92
|
+
- CODE_OF_CONDUCT.md
|
93
|
+
- Gemfile
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- bin/console
|
97
|
+
- bin/setup
|
98
|
+
- lib/owa.rb
|
99
|
+
- lib/owa/configuration.rb
|
100
|
+
- lib/owa/current.rb
|
101
|
+
- lib/owa/errors.rb
|
102
|
+
- lib/owa/requests/http_client.rb
|
103
|
+
- lib/owa/requests/options/city.rb
|
104
|
+
- lib/owa/requests/options/geocode.rb
|
105
|
+
- lib/owa/requests/parser.rb
|
106
|
+
- lib/owa/requests/weather.rb
|
107
|
+
- lib/owa/version.rb
|
108
|
+
- owa.gemspec
|
109
|
+
homepage: ''
|
110
|
+
licenses: []
|
111
|
+
metadata: {}
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 2.6.11
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: OWM API client
|
132
|
+
test_files: []
|