concerto_weather 0.4 → 0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f3b305c49d520a14b485d360e103d7d9d50aeae1
4
- data.tar.gz: a9174426494b15866b904fbac424c2eed53cf1c6
3
+ metadata.gz: 71f297c5a33be038f4b200406aa29a80b9fb6d18
4
+ data.tar.gz: 153d8f18b91219bc5592e5d3e36e97bff4498ba6
5
5
  SHA512:
6
- metadata.gz: cc5772d0ec6f33c20500d4db8e07cb667e2791db2fc84eb0ee428db97a712f585577ba49c21bd04d9b2d34e2e97225ce8d52de30ac3233fa608f6340b2c06318
7
- data.tar.gz: 66a587392ffbe69540564a511e09b58b9c3a4757efb79d969fbe75f618d8db60e6e7e2458a29d14b48923d8b2cc1a02c8eb49b4d0337d14c85536378bce2e31b
6
+ metadata.gz: 83d44d494a800265ec646e4af6f699ac910e42be7ade1ec1514dcd98f2be18898fe672307d2a9471e399d8ce106e48394b937c4b8a5a543b1cfbe248f71b65b7
7
+ data.tar.gz: 3db8207e0d7cd9cdf60f8f80809aedf66c6830ed88ed4fe2fb69689fc821d9487d7a9844c3c862f8b304540e5adf04d1ddf4eb919f453af969cab1dbb4600cff
@@ -24,7 +24,7 @@ function reverseGeocode(place) {
24
24
  };
25
25
 
26
26
  $.ajax({
27
- url: "http://nominatim.openstreetmap.org/reverse",
27
+ url: "//nominatim.openstreetmap.org/reverse",
28
28
  data: params,
29
29
  dataType: "json",
30
30
  success: function(data) {
@@ -51,13 +51,15 @@ function buildResultsTable(data) {
51
51
  table = "<table id='cityResults' class='table table-condensed'> \
52
52
  <thead><th>Name</th><th>District/County/Region</th><th>Province/State</th><th>Country</th>";
53
53
  tableBody = "<tbody></tbody></table>";
54
- tableBody += "<hr/><i>Can't find your city? Try entering your zip code <b>or</b> your city along with its state (ex: Madison, WI).</i>"
54
+ tableBody += "<hr/><i>You must select your city from the list above. Can't find your city? Try entering your zip code <b>or</b> your city along with its state (ex: Madison, WI).</i>"
55
55
  // Insert our empty results table
56
56
  $(info_el).empty().html(table + tableBody);
57
57
  // Find the address info for each weather search result
58
58
  // Then insert the place data into our results table
59
- for (var i = 0; i < places.length; i++) {
60
- reverseGeocode(places[i]);
59
+ if (typeof places != 'undefined') {
60
+ for (var i = 0; i < places.length; i++) {
61
+ reverseGeocode(places[i]);
62
+ }
61
63
  }
62
64
  }
63
65
 
@@ -66,6 +68,10 @@ function searchForCityInfo() {
66
68
  var cityQuery = $("input#weather_config_city_query").val();
67
69
 
68
70
  if (info_el.length != 0 && cityQuery.length > 0) {
71
+ // clear out any prior selected city
72
+ $("#weather_config_lat").val("");
73
+ $("#weather_config_lng").val("");
74
+
69
75
  // Add a 'searching' placeholder while city query results are loading
70
76
  $(info_el).empty().html("<i class='fa fa-spinner fa-spin'></i> searching...");
71
77
  // Query the OpenWeatherAPI to find a list of matching cities based on input
@@ -73,12 +79,12 @@ function searchForCityInfo() {
73
79
  url: "/concerto_weather/city_search.js",
74
80
  data: {"q": cityQuery},
75
81
  dataType: "json",
76
- timeout: 4000,
82
+ timeout: 6000,
77
83
  success: function(data) {
78
84
  // Build a table of results returned from city query
79
85
  buildResultsTable(data);
80
86
  },
81
- error: function() {
87
+ error: function(data) {
82
88
  $(info_el).empty().html("<p>No results found.</p>");
83
89
  }
84
90
  });
@@ -0,0 +1,11 @@
1
+ #cityResults tr {
2
+ cursor: pointer;
3
+ }
4
+
5
+ textarea#weather_config_format_string {
6
+ width: 100%;
7
+ }
8
+
9
+ label[for=weather_config_format_string] + div.input {
10
+ padding-right: 2em;
11
+ }
@@ -8,7 +8,7 @@ class Weather < DynamicContent
8
8
 
9
9
  FONTS = {
10
10
  'owf' => 'Open Weather Font',
11
- 'wi' => 'Weather Icons'
11
+ 'wi' => 'Weather Icons'
12
12
  }
13
13
 
14
14
  FORECAST = {
@@ -16,6 +16,8 @@ class Weather < DynamicContent
16
16
  'forecast' => 'Max and Min temps forecast for the day'
17
17
  }
18
18
 
19
+ validate :validate_config
20
+
19
21
  def build_content
20
22
  require 'json'
21
23
  require 'net/http'
@@ -41,8 +43,14 @@ class Weather < DynamicContent
41
43
  response = Net::HTTP.get_response(URI.parse(url)).body
42
44
  data = JSON.parse(response)
43
45
 
46
+ # if there was an error, then return nil
47
+ if data['cod'].present? && !data['cod'].to_s.starts_with?('2')
48
+ Rails.logger.error("response (#{url}) = #{response}")
49
+ return nil
50
+ end
51
+
44
52
  # Build HTML using API data
45
-
53
+
46
54
  self.config["location_name"] = data["city"]["name"]
47
55
 
48
56
  format_city = data['city']['name']
@@ -56,7 +64,7 @@ class Weather < DynamicContent
56
64
 
57
65
  format_high = "#{data['list'][0]['temp']['max'].round(0)} &deg;#{UNITS[params[:units]][0]}"
58
66
  format_low = "#{data['list'][0]['temp']['min'].round(0)} &deg;#{UNITS[params[:units]][0]}"
59
- emptyhtml = "
67
+ empty_html = "
60
68
  <h1> Today in #{format_city} </h1>
61
69
  <div style='float: left; width: 50%'>
62
70
  #{format_icon}
@@ -85,6 +93,12 @@ class Weather < DynamicContent
85
93
  response = Net::HTTP.get_response(URI.parse(url)).body
86
94
  data = JSON.parse(response)
87
95
 
96
+ # if there was an error, then return nil
97
+ if data['cod'].present? && !data['cod'].to_s.starts_with?('2')
98
+ Rails.logger.error("response (#{url}) = #{response}")
99
+ return nil
100
+ end
101
+
88
102
  # Build HTML using API data
89
103
 
90
104
  self.config["location_name"] = data["name"]
@@ -101,7 +115,7 @@ class Weather < DynamicContent
101
115
  format_high = "#{data['main']['temp_max'].round(0)} &deg;#{UNITS[params[:units]][0]}"
102
116
  format_low = "#{data['main']['temp_min'].round(0)} &deg;#{UNITS[params[:units]][0]}"
103
117
  format_current = "#{data['main']['temp'].round(0)} &deg;#{UNITS[params[:units]][0]}"
104
- emptyhtml = "
118
+ empty_html = "
105
119
  <h1> Today in #{format_city} </h1>
106
120
  <div style='float: left; width: 50%'>
107
121
  #{format_icon}
@@ -111,15 +125,13 @@ class Weather < DynamicContent
111
125
  <h1> #{format_current} </h1>
112
126
  </div>
113
127
  "
114
-
115
128
  end
116
129
 
117
-
118
130
  format_string = self.config['format_string']
119
131
 
120
- if format_string.blank?
132
+ if format_string.blank?
121
133
  rawhtml = empty_html
122
- else
134
+ else
123
135
  rawhtml = eval("\"" + format_string + "\"")
124
136
  end
125
137
 
@@ -135,4 +147,10 @@ class Weather < DynamicContent
135
147
  attributes = super()
136
148
  attributes.concat([:config => [:lat, :lng, :units, :font_name, :location_name, :format_string, :forecast_type]])
137
149
  end
150
+
151
+ def validate_config
152
+ if self.config['lat'].blank? || self.config['lng'].blank?
153
+ errors.add(:base, 'A city must be selected')
154
+ end
155
+ end
138
156
  end
@@ -4,6 +4,11 @@
4
4
  <fieldset>
5
5
  <legend><span>Weather</span></legend>
6
6
  <div class="row-fluid">
7
+ <% if ConcertoConfig["open_weather_map_api_key"].blank? %>
8
+ <div class='alert alert-warning'>
9
+ The OpenWeatherMap API Key under Settings appears to be blank. An API key is required for this content.
10
+ </div>
11
+ <% end %>
7
12
  <div class='span4'>
8
13
  <%= form.fields_for :config do |config| %>
9
14
  <div class="clearfix">
@@ -1,3 +1,3 @@
1
1
  module ConcertoWeather
2
- VERSION = "0.4"
2
+ VERSION = "0.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: concerto_weather
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.4'
4
+ version: '0.5'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Michalski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-15 00:00:00.000000000 Z
11
+ date: 2017-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -51,6 +51,7 @@ files:
51
51
  - app/assets/stylesheets/concerto_weather/owfont-regular.css.scss
52
52
  - app/assets/stylesheets/concerto_weather/weather-icons-wind.min.css.scss
53
53
  - app/assets/stylesheets/concerto_weather/weather-icons.min.css.scss
54
+ - app/assets/stylesheets/concerto_weather/weather.scss
54
55
  - app/controllers/concerto_weather/application_controller.rb
55
56
  - app/controllers/concerto_weather/search_controller.rb
56
57
  - app/helpers/concerto_weather/application_helper.rb