cimis-ruby 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -16
- data/lib/cimis/station.rb +23 -3
- data/lib/cimis/station_data.rb +20 -1
- data/lib/cimis/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dcb7f255c2565a3cc934607b6a222b1786ede27e
|
4
|
+
data.tar.gz: 9f1a2af4b7d7a81bab898585952bc94ae88300c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2d5623aed0522ff6a6bac689c72c0ca6253e7f71479516c4e01d7d10a55d478e9a9f10be2ae0bce3184928afb1eb16836357dbd170d187023152de35beee69e
|
7
|
+
data.tar.gz: 2e8e0c2395fd609136336b688b5896d47003d7d2e4d6e167e0719cbec3fc1268f65ecec565bcad28ad19a6b8d1e9309944b6ee556c5a9b800368f8a4d96b913c
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Cimis Ruby
|
2
2
|
|
3
|
-
This is a slim wrapper around the Department of Water Resources CIMIS REST API.
|
3
|
+
This is a slim wrapper around the Department of Water Resources CIMIS REST API.
|
4
4
|
It allows you to easily query the API and get easy to handle responses.
|
5
5
|
|
6
6
|
## Installation
|
@@ -22,7 +22,7 @@ Or install it yourself as:
|
|
22
22
|
## Usage
|
23
23
|
|
24
24
|
### Setup
|
25
|
-
The first thing you need to do is setup your app key. If you haven't yet
|
25
|
+
The first thing you need to do is setup your app key. If you haven't yet
|
26
26
|
registered, go to the [CIMIS website](http://wwwcimis.water.ca.gov/) and
|
27
27
|
register. You can then go to your account page and retrieve the app key.
|
28
28
|
|
@@ -42,44 +42,50 @@ This will return an array of station objects. Each station can then be used
|
|
42
42
|
to query for data from that station on the object itself:
|
43
43
|
```ruby
|
44
44
|
station = Cimis::Station.all.first
|
45
|
-
station.data(
|
45
|
+
station.data(start_date: "2015-10-10", end_date: "2015-10-12")
|
46
|
+
```
|
47
|
+
|
48
|
+
This will return daily stats by default, if you would instead like to get
|
49
|
+
hourly stats, just add the hourly option:
|
50
|
+
```ruby
|
51
|
+
station.data(start_date: "2015-10-10", end_date: "2015-10-12", hourly: true)
|
46
52
|
```
|
47
53
|
|
48
54
|
### General Querying
|
49
55
|
|
50
56
|
Aside from getting data for a station, you can also query the api using a
|
51
|
-
variety of location targets (lat, lng, zip, address). See the
|
57
|
+
variety of location targets (lat, lng, zip, address). See the
|
52
58
|
[CIMIS API reference](http://et.water.ca.gov/Rest/Index) for more details.
|
53
59
|
```ruby
|
54
|
-
Cimis.data(
|
60
|
+
Cimis.data(
|
55
61
|
targets: "lat=34.99,lng=-119.34",
|
56
62
|
start_date: "2015-10-10",
|
57
63
|
end_date: "2015-10-12"
|
58
|
-
|
64
|
+
)
|
59
65
|
```
|
60
66
|
|
61
67
|
## Development
|
62
68
|
|
63
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then,
|
64
|
-
run `rake test` to run the tests. You can also run `bin/console` for an
|
69
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then,
|
70
|
+
run `rake test` to run the tests. You can also run `bin/console` for an
|
65
71
|
interactive prompt that will allow you to experiment.
|
66
72
|
|
67
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
68
|
-
To release a new version, update the version number in `version.rb`, and then
|
69
|
-
run `bundle exec rake release`, which will create a git tag for the version,
|
70
|
-
push git commits and tags, and push the `.gem` file to
|
73
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
74
|
+
To release a new version, update the version number in `version.rb`, and then
|
75
|
+
run `bundle exec rake release`, which will create a git tag for the version,
|
76
|
+
push git commits and tags, and push the `.gem` file to
|
71
77
|
[rubygems.org](https://rubygems.org).
|
72
78
|
|
73
79
|
## Contributing
|
74
80
|
|
75
|
-
Bug reports and pull requests are welcome on GitHub at
|
76
|
-
https://github.com/[USERNAME]/cimis-ruby. This project is intended to be a
|
77
|
-
safe, welcoming space for collaboration, and contributors are expected to
|
81
|
+
Bug reports and pull requests are welcome on GitHub at
|
82
|
+
https://github.com/[USERNAME]/cimis-ruby. This project is intended to be a
|
83
|
+
safe, welcoming space for collaboration, and contributors are expected to
|
78
84
|
adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
79
85
|
|
80
86
|
|
81
87
|
## License
|
82
88
|
|
83
|
-
The gem is available as open source under the terms of the
|
89
|
+
The gem is available as open source under the terms of the
|
84
90
|
[MIT License](http://opensource.org/licenses/MIT).
|
85
91
|
|
data/lib/cimis/station.rb
CHANGED
@@ -28,7 +28,7 @@ module Cimis
|
|
28
28
|
response = Cimis.connection.get("station")
|
29
29
|
response.body["Stations"].map do |station|
|
30
30
|
new(station)
|
31
|
-
end
|
31
|
+
end
|
32
32
|
end
|
33
33
|
|
34
34
|
def process_params(params)
|
@@ -36,7 +36,7 @@ module Cimis
|
|
36
36
|
symbolized[:hms_latitude] = extract_coordinate(symbolized[:hms_latitude])
|
37
37
|
symbolized[:hms_longitude] = extract_coordinate(symbolized[:hms_longitude])
|
38
38
|
symbolized[:connect_date] = parse_date(symbolized[:connect_date])
|
39
|
-
symbolized[:disconnect_date] = parse_date(symbolized[:disconnect_date])
|
39
|
+
symbolized[:disconnect_date] = parse_date(symbolized[:disconnect_date])
|
40
40
|
symbolized
|
41
41
|
end
|
42
42
|
|
@@ -50,9 +50,29 @@ module Cimis
|
|
50
50
|
DateTime.strptime(date_str, "%m/%d/%Y")
|
51
51
|
end
|
52
52
|
|
53
|
+
def hourly_options
|
54
|
+
%w(
|
55
|
+
hly-air-tmp
|
56
|
+
hly-dew-pnt
|
57
|
+
hly-eto
|
58
|
+
hly-net-rad
|
59
|
+
hly-asce-eto
|
60
|
+
hly-asce-etr
|
61
|
+
hly-precip
|
62
|
+
hly-rel-hum
|
63
|
+
hly-res-wind
|
64
|
+
hly-soil-tmp
|
65
|
+
hly-sol-rad
|
66
|
+
hly-vap-pres
|
67
|
+
hly-wind-dir
|
68
|
+
hly-wind-spd
|
69
|
+
).join(',')
|
70
|
+
end
|
71
|
+
|
53
72
|
def data(options = {})
|
73
|
+
options.merge!(dataItems: hourly_options) if options.delete(:hourly)
|
54
74
|
options.merge!({app_key: Cimis.app_key, targets: station_nbr})
|
55
|
-
response = Cimis.connection.get("data?#{Cimis.to_query(options)}")
|
75
|
+
response = Cimis.connection.get("data?#{Cimis.to_query(options)}")
|
56
76
|
response.body["Data"]["Providers"].first["Records"].map do |record|
|
57
77
|
StationData.new(record)
|
58
78
|
end
|
data/lib/cimis/station_data.rb
CHANGED
@@ -6,10 +6,13 @@ module Cimis
|
|
6
6
|
include Virtus.model
|
7
7
|
|
8
8
|
attribute :julian, Integer, default: 0
|
9
|
+
attribute :hour, Integer
|
9
10
|
attribute :station, Integer, default: 0
|
10
11
|
attribute :standard, String
|
11
12
|
attribute :zip_codes, Array[String]
|
12
13
|
attribute :scope, String
|
14
|
+
|
15
|
+
# Daily Data Points
|
13
16
|
attribute :day_air_tmp_avg, Cimis::DataPoint
|
14
17
|
attribute :day_air_tmp_max, Cimis::DataPoint
|
15
18
|
attribute :day_air_tmp_min, Cimis::DataPoint
|
@@ -25,8 +28,24 @@ module Cimis
|
|
25
28
|
attribute :day_wind_run, Cimis::DataPoint
|
26
29
|
attribute :day_wind_spd_avg, Cimis::DataPoint
|
27
30
|
|
31
|
+
# Hourly Data Points
|
32
|
+
attribute :hly_air_tmp, Cimis::DataPoint
|
33
|
+
attribute :hly_dew_pnt, Cimis::DataPoint
|
34
|
+
attribute :hly_eto, Cimis::DataPoint
|
35
|
+
attribute :hly_net_rad, Cimis::DataPoint
|
36
|
+
attribute :hly_asce_eto, Cimis::DataPoint
|
37
|
+
attribute :hly_asce_etr, Cimis::DataPoint
|
38
|
+
attribute :hly_precip, Cimis::DataPoint
|
39
|
+
attribute :hly_rel_hum, Cimis::DataPoint
|
40
|
+
attribute :hly_res_wind, Cimis::DataPoint
|
41
|
+
attribute :hly_soil_temp, Cimis::DataPoint
|
42
|
+
attribute :hly_sol_rad, Cimis::DataPoint
|
43
|
+
attribute :hly_vap_pres, Cimis::DataPoint
|
44
|
+
attribute :hly_wind_dir, Cimis::DataPoint
|
45
|
+
attribute :hly_wind_spd, Cimis::DataPoint
|
46
|
+
|
28
47
|
def initialize(params)
|
29
|
-
super(Cimis.symbolize_keys(params))
|
48
|
+
super(Cimis.symbolize_keys(params))
|
30
49
|
end
|
31
50
|
end
|
32
51
|
end
|
data/lib/cimis/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cimis-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- dphaener
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -177,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
177
177
|
version: '0'
|
178
178
|
requirements: []
|
179
179
|
rubyforge_project:
|
180
|
-
rubygems_version: 2.
|
180
|
+
rubygems_version: 2.5.1
|
181
181
|
signing_key:
|
182
182
|
specification_version: 4
|
183
183
|
summary: A Ruby wrapper for the CIMIS data API
|