From 2dceeb4d61d8aed7dd97cbbda31585a627c9ac20 Mon Sep 17 00:00:00 2001 From: Aaro Koivukangas Date: Wed, 6 Dec 2023 15:45:40 +0200 Subject: [PATCH] rubocop fixes --- app/controllers/styles_controller.rb | 4 ++-- app/models/place.rb | 19 +++++++++---------- lib/beermapping_api.rb | 4 +++- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/app/controllers/styles_controller.rb b/app/controllers/styles_controller.rb index a61689c..9217854 100644 --- a/app/controllers/styles_controller.rb +++ b/app/controllers/styles_controller.rb @@ -51,8 +51,8 @@ class StylesController < ApplicationController format.json { head :no_content } end end - - private + + private def style_params params.require(:style).permit(:name, :description) diff --git a/app/models/place.rb b/app/models/place.rb index b6c1cd4..dc5a6d5 100644 --- a/app/models/place.rb +++ b/app/models/place.rb @@ -3,13 +3,12 @@ class Place < OpenStruct [:id, :name, :status, :street, :city, :zip, :country, :overall] end - def self.weather location - weather_api_key = self.api_key + def self.weather(location) + weather_api_key = api_key weather_api_url = "http://api.weatherstack.com/current" response = HTTParty.get "#{weather_api_url}?access_key=#{weather_api_key}&query=#{location}" - #if response["success"] puts "#{weather_api_url}?access_key=#{weather_api_key}&query=#{location}" puts response.parsed_response data = response.parsed_response["current"] @@ -17,26 +16,26 @@ class Place < OpenStruct return end - weather = self.parse_weather_data data - return weather + parse_weather_data data end - def self.parse_weather_data data + def self.parse_weather_data(data) temperature = data["temperature"] weather_icon = data["weather_icons"][0] weather_descriptions = data["weather_descriptions"][0] - weather_icon = { image: weather_icon, description: weather_descriptions} + weather_icon = { image: weather_icon, description: weather_descriptions } wind_direction = data["wind_dir"] wind_speed = data["wind_speed"] wind = { direction: wind_direction, speed: wind_speed } - weather = { temperature: temperature, wind: wind, weather_icon: weather_icon} - return weather + { temperature:, wind:, weather_icon: } end def self.api_key return nil if Rails.env.test? + key = Rails.application.credentials.weatherstack_api_key raise 'WEATHERSTACK_API_KEY env variable not defined in credentials' if key.nil? - return key + + key end end diff --git a/lib/beermapping_api.rb b/lib/beermapping_api.rb index 50d0fac..235ea97 100644 --- a/lib/beermapping_api.rb +++ b/lib/beermapping_api.rb @@ -24,8 +24,10 @@ class BeermappingApi def self.key return nil if Rails.env.test? + key = Rails.application.credentials.beermapping_api_key raise 'BEERMAPPING_API_KEY env variable not defined' if key.nil? - return key + + key end end