open_weather_client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7e71860d474b67b88ec968c56ca18bfcd98029b9078bbd73fef481bd1dcf8736
4
+ data.tar.gz: 8eb818af6393f4cbbac4dddea37800911ebe58a0dd10bc323f337251596cd088
5
+ SHA512:
6
+ metadata.gz: 85a0e87c06cfa1753b6c3b2baaa251fd864fc03e50af861b86d015dc5a37739f043361c82fafea26794877b0652821a65b27f04efaab905ffb903bca22fedba5
7
+ data.tar.gz: 31ad8150d112bfcfd0b7b5e0b62830d3d5336968a76754dad1dc16e255ff0916901fd176fe8557688492101e2ed147392210cda1e4c6dd1920166d3c1bff477b
data/.gemrc ADDED
@@ -0,0 +1,8 @@
1
+ ---
2
+ :backtrace: false
3
+ :bulk_threshold: 1000
4
+ :sources:
5
+ - https://rubygems.org/
6
+ - https://USERNAME:TOKEN@rubygems.pkg.github.com/qurasoft/
7
+ :update_sources: true
8
+ :verbose: true
@@ -0,0 +1,70 @@
1
+ # For most projects, this workflow file will not need changing; you simply need
2
+ # to commit it to your repository.
3
+ #
4
+ # You may wish to alter this file to override the set of languages analyzed,
5
+ # or to provide custom queries or build logic.
6
+ #
7
+ # ******** NOTE ********
8
+ # We have attempted to detect the languages in your repository. Please check
9
+ # the `language` matrix defined below to confirm you have the correct set of
10
+ # supported CodeQL languages.
11
+ #
12
+ name: "CodeQL"
13
+
14
+ on:
15
+ push:
16
+ branches: [ main ]
17
+ pull_request:
18
+ # The branches below must be a subset of the branches above
19
+ branches: [ main ]
20
+ schedule:
21
+ - cron: '20 21 * * 1'
22
+
23
+ jobs:
24
+ analyze:
25
+ name: Analyze
26
+ runs-on: ubuntu-latest
27
+ permissions:
28
+ actions: read
29
+ contents: read
30
+ security-events: write
31
+
32
+ strategy:
33
+ fail-fast: false
34
+ matrix:
35
+ language: [ 'ruby' ]
36
+ # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
37
+ # Learn more about CodeQL language support at https://git.io/codeql-language-support
38
+
39
+ steps:
40
+ - name: Checkout repository
41
+ uses: actions/checkout@v2
42
+
43
+ # Initializes the CodeQL tools for scanning.
44
+ - name: Initialize CodeQL
45
+ uses: github/codeql-action/init@v2
46
+ with:
47
+ languages: ${{ matrix.language }}
48
+ # If you wish to specify custom queries, you can do so here or in a config file.
49
+ # By default, queries listed here will override any specified in a config file.
50
+ # Prefix the list here with "+" to use these queries and those in the config file.
51
+ # queries: ./path/to/local/query, your-org/your-repo/queries@main
52
+
53
+ # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
54
+ # If this step fails, then you should remove it and run the build manually (see below)
55
+ - name: Autobuild
56
+ uses: github/codeql-action/autobuild@v2
57
+
58
+ # ℹ️ Command-line programs to run using the OS shell.
59
+ # 📚 https://git.io/JvXDl
60
+
61
+ # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
62
+ # and modify them (or add more) to build your code if your project
63
+ # uses a compiled language
64
+
65
+ #- run: |
66
+ # make bootstrap
67
+ # make release
68
+
69
+ - name: Perform CodeQL Analysis
70
+ uses: github/codeql-action/analyze@v2
@@ -0,0 +1,35 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ main ]
13
+ pull_request:
14
+ branches: [ main ]
15
+
16
+ jobs:
17
+ test:
18
+
19
+ runs-on: ubuntu-latest
20
+ strategy:
21
+ matrix:
22
+ ruby-version: ['3.0']
23
+
24
+ steps:
25
+ - uses: actions/checkout@v2
26
+ - name: Set up Ruby
27
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
28
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
29
+ # uses: ruby/setup-ruby@v1
30
+ uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
31
+ with:
32
+ ruby-version: ${{ matrix.ruby-version }}
33
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
34
+ - name: Run tests
35
+ run: bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ /.idea/
11
+
12
+ Gemfile.lock
13
+
14
+ # rspec failure tracking
15
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 3.2.0
7
+ before_install: gem install bundler -v 1.17.3
data/CHANGES.md ADDED
@@ -0,0 +1,6 @@
1
+ # Open Weather Client Changelog
2
+
3
+ ## 0.1.0
4
+ - Initial commit of the Open Weather Client gem
5
+ - Configuration of OpenWeatherClient
6
+ - Request current weather with `OpenWeatherClient.current(lat:, lon:)`
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in open_weather_client.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Qurasoft GmbH
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,70 @@
1
+ # Open Weather Client
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/open_weather_client.svg)](https://badge.fury.io/rb/open_weather_client)
4
+ ![RSpec](https://github.com/qurasoft/open_weather_client/actions/workflows/ruby.yml/badge.svg)
5
+
6
+ Welcome to Open Weather Client. This gem allows you to easily send messages from your ruby project to Microsoft Teams channels.
7
+ It integrates in your rails project, when you are using bundler or even in plain ruby projects.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'open_weather_client'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install open_weather_client
24
+
25
+ ## Usage
26
+ During configuration the OpenWeatherMap API key must be set. Afterwards it is as simple as calling `OpenWeatherClient.current(lat:, lon:)` to get the current weather at a location.
27
+
28
+ ```ruby
29
+ # OpenWeatherClient initializer
30
+ OpenWeatherClient.configure do |config|
31
+ config.appid = "1234567890"
32
+ end
33
+
34
+ # Receive the current weather in Koblenz
35
+ OpenWeatherClient::Weather.current(lat: 50.3569, lon: 7.5890)
36
+ ```
37
+
38
+ ### Secure Configuration
39
+ In Rails provides the credentials functionality for [environmental security](https://edgeguides.rubyonrails.org/security.html#environmental-security). This mechanism can be used by OpenWeatherClient to load the API key from an encrypted file. This also allows easy separation of production and development channel configuration.
40
+ All settings are defined under the top-level entry `open_weather_client`.
41
+ ```yaml
42
+ # $ bin/rails credentials:edit
43
+ open_weather_client:
44
+ appid: "<INSERT OPENWEATHERMAP API KEY HERE>"
45
+ ```
46
+
47
+ After configuration of the credentials you can load the settings in your initializer with `#load_from_rails_configuration`.
48
+
49
+ ```ruby
50
+ # OpenWeatherClient initializer
51
+ OpenWeatherClient.configure do |config|
52
+ config.load_from_rails_credentials
53
+ end
54
+ ```
55
+
56
+ ## Development
57
+
58
+ 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.
59
+
60
+ You can define the client settings you use for testing in the file `bin/config.yml` or directly in the `bin/console` script.
61
+
62
+ 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).
63
+
64
+ ## Contributing
65
+
66
+ Bug reports and pull requests are welcome on GitHub at https://github.com/qurasoft/open_weather_client. 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.
67
+
68
+ ## License
69
+
70
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/.gitignore ADDED
@@ -0,0 +1 @@
1
+ config.yml
data/bin/console ADDED
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'open_weather_client'
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
+ OpenWeatherClient.configure do |config|
14
+ if File.exist?('config.yml')
15
+ # NOTE(Keune): The channels available in the console can be set in the file channels.yml. It contains a simple
16
+ # mapping of channel identifiers to webhook URLs. The channel identifier is loaded as a symbol.
17
+ #
18
+ # Example: APPID: "<INSERT YOUR WEBHOOK URL HERE>"
19
+ puts 'Load channels specified by file'
20
+
21
+ require 'yaml'
22
+ settings = YAML.load_file 'config.yml'
23
+ config.appid = settings['APPID']
24
+ end
25
+ end
26
+
27
+ require 'irb'
28
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,21 @@
1
+ module OpenWeatherClient
2
+ class Configuration
3
+ attr_accessor :appid, :lang, :units, :url, :user_agent
4
+
5
+ def initialize
6
+ @lang = 'de'
7
+ @units = 'metric'
8
+ @url = 'https://api.openweathermap.org/data'
9
+ @user_agent = "Open Weather Client/#{OpenWeatherClient::VERSION}"
10
+ end
11
+
12
+ def load_from_rails_credentials
13
+ unless defined? Rails
14
+ raise RuntimeError, 'This method is only available in Ruby on Rails.'
15
+ end
16
+
17
+ settings = Rails.application.credentials.open_weather_client!
18
+ self.appid = settings[:appid]
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module OpenWeatherClient
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,27 @@
1
+ require 'faraday'
2
+
3
+ module OpenWeatherClient
4
+ class Weather
5
+ def self.current(lat:, lon:)
6
+ connection = Faraday.new(
7
+ url: OpenWeatherClient.configuration.url,
8
+ params: {
9
+ appid: OpenWeatherClient.configuration.appid,
10
+ lat: lat,
11
+ lon: lon,
12
+ lang: OpenWeatherClient.configuration.lang,
13
+ units: OpenWeatherClient.configuration.units
14
+ },
15
+ headers: {
16
+ 'User-Agent': OpenWeatherClient.configuration.user_agent
17
+ }
18
+ ) do |f|
19
+ f.response :json
20
+ end
21
+
22
+ response = connection.get('2.5/weather')
23
+
24
+ response.body
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,38 @@
1
+ require 'open_weather_client/configuration'
2
+ require 'open_weather_client/version'
3
+ require 'open_weather_client/weather'
4
+
5
+ module OpenWeatherClient
6
+ class << self
7
+ attr_accessor :configuration, :testing
8
+ end
9
+
10
+ def self.configuration
11
+ @configuration ||= Configuration.new
12
+ end
13
+
14
+ def self.reset
15
+ @configuration = Configuration.new
16
+ end
17
+
18
+ def self.configure
19
+ yield configuration
20
+ end
21
+
22
+ def self.project_root
23
+ if defined?(Rails)
24
+ return Rails.root
25
+ end
26
+
27
+ if defined?(Bundler)
28
+ return Bundler.root
29
+ end
30
+
31
+ Dir.pwd
32
+ end
33
+
34
+ def self.gem_root
35
+ spec = Gem::Specification.find_by_name("open_weather_client")
36
+ spec.gem_dir rescue project_root
37
+ end
38
+ end
@@ -0,0 +1,43 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "open_weather_client/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "open_weather_client"
8
+ spec.version = OpenWeatherClient::VERSION
9
+ spec.authors = ["Lucas Keune"]
10
+ spec.email = ["lucas.keune@qurasoft.de"]
11
+
12
+ spec.summary = %q{Access weather data from OpenWeatherMap}
13
+ spec.description = %q{}
14
+ spec.homepage = "https://github.com/Qurasoft/open_weather_client"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["homepage_uri"] = spec.homepage
21
+ spec.metadata["source_code_uri"] = "https://github.com/Qurasoft/open_weather_client"
22
+ spec.metadata["changelog_uri"] = "https://github.com/Qurasoft/open_weather_client/blob/main/CHANGES.md"
23
+ else
24
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
25
+ end
26
+
27
+ # Specify which files should be added to the gem when it is released.
28
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
29
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
30
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
31
+ end
32
+ spec.bindir = "exe"
33
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
+ spec.require_paths = ["lib"]
35
+
36
+ spec.add_dependency "faraday", ">= 2"
37
+
38
+ spec.add_development_dependency "bundler", ">= 1.17"
39
+ spec.add_development_dependency "rake", ">= 10.0"
40
+ spec.add_development_dependency "rspec", ">= 3.0"
41
+ spec.add_development_dependency "webmock"
42
+ spec.add_development_dependency "simplecov"
43
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: open_weather_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Lucas Keune
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-01-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '1.17'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '1.17'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: ''
98
+ email:
99
+ - lucas.keune@qurasoft.de
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gemrc"
105
+ - ".github/workflows/codeql-analysis.yml"
106
+ - ".github/workflows/ruby.yml"
107
+ - ".gitignore"
108
+ - ".rspec"
109
+ - ".travis.yml"
110
+ - CHANGES.md
111
+ - Gemfile
112
+ - LICENSE.txt
113
+ - README.md
114
+ - Rakefile
115
+ - bin/.gitignore
116
+ - bin/console
117
+ - bin/setup
118
+ - lib/open_weather_client.rb
119
+ - lib/open_weather_client/configuration.rb
120
+ - lib/open_weather_client/version.rb
121
+ - lib/open_weather_client/weather.rb
122
+ - open_weather_client.gemspec
123
+ homepage: https://github.com/Qurasoft/open_weather_client
124
+ licenses:
125
+ - MIT
126
+ metadata:
127
+ homepage_uri: https://github.com/Qurasoft/open_weather_client
128
+ source_code_uri: https://github.com/Qurasoft/open_weather_client
129
+ changelog_uri: https://github.com/Qurasoft/open_weather_client/blob/main/CHANGES.md
130
+ post_install_message:
131
+ rdoc_options: []
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ requirements: []
145
+ rubygems_version: 3.4.1
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: Access weather data from OpenWeatherMap
149
+ test_files: []