rubocop fixes

This commit is contained in:
Aaro Koivukangas
2023-12-06 15:45:40 +02:00
parent db2870bd60
commit 2dceeb4d61
3 changed files with 14 additions and 13 deletions
+2 -2
View File
@@ -51,8 +51,8 @@ class StylesController < ApplicationController
format.json { head :no_content } format.json { head :no_content }
end end
end end
private private
def style_params def style_params
params.require(:style).permit(:name, :description) params.require(:style).permit(:name, :description)
+9 -10
View File
@@ -3,13 +3,12 @@ class Place < OpenStruct
[:id, :name, :status, :street, :city, :zip, :country, :overall] [:id, :name, :status, :street, :city, :zip, :country, :overall]
end end
def self.weather location def self.weather(location)
weather_api_key = self.api_key weather_api_key = api_key
weather_api_url = "http://api.weatherstack.com/current" weather_api_url = "http://api.weatherstack.com/current"
response = HTTParty.get "#{weather_api_url}?access_key=#{weather_api_key}&query=#{location}" 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 "#{weather_api_url}?access_key=#{weather_api_key}&query=#{location}"
puts response.parsed_response puts response.parsed_response
data = response.parsed_response["current"] data = response.parsed_response["current"]
@@ -17,26 +16,26 @@ class Place < OpenStruct
return return
end end
weather = self.parse_weather_data data parse_weather_data data
return weather
end end
def self.parse_weather_data data def self.parse_weather_data(data)
temperature = data["temperature"] temperature = data["temperature"]
weather_icon = data["weather_icons"][0] weather_icon = data["weather_icons"][0]
weather_descriptions = data["weather_descriptions"][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_direction = data["wind_dir"]
wind_speed = data["wind_speed"] wind_speed = data["wind_speed"]
wind = { direction: wind_direction, speed: wind_speed } wind = { direction: wind_direction, speed: wind_speed }
weather = { temperature: temperature, wind: wind, weather_icon: weather_icon} { temperature:, wind:, weather_icon: }
return weather
end end
def self.api_key def self.api_key
return nil if Rails.env.test? return nil if Rails.env.test?
key = Rails.application.credentials.weatherstack_api_key key = Rails.application.credentials.weatherstack_api_key
raise 'WEATHERSTACK_API_KEY env variable not defined in credentials' if key.nil? raise 'WEATHERSTACK_API_KEY env variable not defined in credentials' if key.nil?
return key
key
end end
end end
+3 -1
View File
@@ -24,8 +24,10 @@ class BeermappingApi
def self.key def self.key
return nil if Rails.env.test? return nil if Rails.env.test?
key = Rails.application.credentials.beermapping_api_key key = Rails.application.credentials.beermapping_api_key
raise 'BEERMAPPING_API_KEY env variable not defined' if key.nil? raise 'BEERMAPPING_API_KEY env variable not defined' if key.nil?
return key
key
end end
end end