weathermatic 0.0.10 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/weathermatic.rb +256 -36
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07ff4e7094d74fd0997c3c304ec99cb7b1847dec
|
4
|
+
data.tar.gz: 3b2b6196a407bc98c98f86310d4e52f159fcb2ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b4c70028210edd2479b312affcf9a470faca82c97e41975981de49c266a33c7786debe1da7bd3f0c72588fd3cdff09ec5caae16c89f9fc96ee249d8a7c6d3c9
|
7
|
+
data.tar.gz: 3b41610a0f5983531e876dddc5f80df63c19e74dbb516a779ffaa41e751492db982b1bb4bdac2348e29bf983c0b7eba98c6c5bb2636e87b8a7e50664af3dc9c8
|
data/lib/weathermatic.rb
CHANGED
@@ -12,9 +12,8 @@ class WeatherMatic
|
|
12
12
|
def initialize(args)
|
13
13
|
@username = args[:username]
|
14
14
|
@password = args[:password]
|
15
|
-
|
15
|
+
@base_uri = "https://my.smartlinknetwork.com"
|
16
16
|
# @base_uri = 'http://localhost:3000'
|
17
|
-
@base_uri = 'https://beta.smartlinknetwork.com'
|
18
17
|
end
|
19
18
|
|
20
19
|
# All requests are essentially the same - the purpose of this note is really just to show the basic authorization header for reference
|
@@ -98,7 +97,7 @@ class WeatherMatic
|
|
98
97
|
|
99
98
|
def sites_list
|
100
99
|
uri = parse_uri(@base_uri+"/api/v2/sites?"+add_timestamp)
|
101
|
-
|
100
|
+
puts uri
|
102
101
|
@request = make_get(uri)
|
103
102
|
make_request(uri,@request)
|
104
103
|
end
|
@@ -437,108 +436,140 @@ class WeatherMatic
|
|
437
436
|
# Usage: wm.site_usage(:site_id => 157, :controller_id => [794,750], :range_start => "2014-06-01", :range_end => "2014-07-25", :interval => 'w' )
|
438
437
|
|
439
438
|
# Example Response: (all units are in gallons for this site)
|
440
|
-
# {
|
441
|
-
# "meta":{
|
439
|
+
# {
|
440
|
+
# "meta":{
|
442
441
|
# "access":true,
|
443
442
|
# "hmac":true,
|
444
443
|
# "success":true,
|
445
|
-
# "request":{
|
444
|
+
# "request":{
|
446
445
|
# "range_start":"2014-06-01",
|
447
446
|
# "range_end":"2014-07-25",
|
448
447
|
# "interval":"w",
|
449
|
-
# "controller_id":[
|
448
|
+
# "controller_id":[
|
450
449
|
# "794",
|
451
450
|
# "750"
|
452
451
|
# ],
|
453
452
|
# "zone_number":null,
|
454
|
-
# "timestamp":"
|
453
|
+
# "timestamp":"1407948694",
|
455
454
|
# "action":"usage",
|
456
455
|
# "controller":"api/v2/reports_sites",
|
457
456
|
# "id":"157",
|
458
457
|
# "format":"json",
|
459
|
-
# "reports_site":{
|
458
|
+
# "reports_site":{
|
460
459
|
|
461
460
|
# }
|
462
461
|
# },
|
463
462
|
# "message":null
|
464
463
|
# },
|
465
|
-
# "result":{
|
466
|
-
# "site":{
|
464
|
+
# "result":{
|
465
|
+
# "site":{
|
467
466
|
# "id":157,
|
468
467
|
# "name":"Engineering Dept",
|
469
|
-
# "controllers":[
|
470
|
-
# {
|
468
|
+
# "controllers":[
|
469
|
+
# {
|
471
470
|
# "id":750,
|
472
471
|
# "name":"Andey's",
|
473
|
-
# "usage":[
|
474
|
-
# {
|
472
|
+
# "usage":[
|
473
|
+
# {
|
475
474
|
# "gallons":1512,
|
475
|
+
# "seconds_ran":19166,
|
476
|
+
# "realtime_average_flow":null,
|
476
477
|
# "date":"2014-06-02"
|
477
478
|
# },
|
478
|
-
# {
|
479
|
+
# {
|
479
480
|
# "gallons":1454,
|
481
|
+
# "seconds_ran":16980,
|
482
|
+
# "realtime_average_flow":null,
|
480
483
|
# "date":"2014-06-09"
|
481
484
|
# },
|
482
|
-
# {
|
485
|
+
# {
|
483
486
|
# "gallons":1240,
|
487
|
+
# "seconds_ran":19788,
|
488
|
+
# "realtime_average_flow":null,
|
484
489
|
# "date":"2014-06-16"
|
485
490
|
# },
|
486
|
-
# {
|
491
|
+
# {
|
487
492
|
# "gallons":1620,
|
493
|
+
# "seconds_ran":16526,
|
494
|
+
# "realtime_average_flow":null,
|
488
495
|
# "date":"2014-06-23"
|
489
496
|
# },
|
490
|
-
# {
|
497
|
+
# {
|
491
498
|
# "gallons":1582,
|
499
|
+
# "seconds_ran":17794,
|
500
|
+
# "realtime_average_flow":null,
|
492
501
|
# "date":"2014-06-30"
|
493
502
|
# },
|
494
|
-
# {
|
503
|
+
# {
|
495
504
|
# "gallons":1217,
|
505
|
+
# "seconds_ran":15418,
|
506
|
+
# "realtime_average_flow":null,
|
496
507
|
# "date":"2014-07-07"
|
497
508
|
# },
|
498
|
-
# {
|
509
|
+
# {
|
499
510
|
# "gallons":1357,
|
511
|
+
# "seconds_ran":15333,
|
512
|
+
# "realtime_average_flow":null,
|
500
513
|
# "date":"2014-07-14"
|
501
514
|
# },
|
502
|
-
# {
|
515
|
+
# {
|
503
516
|
# "gallons":454,
|
517
|
+
# "seconds_ran":15325,
|
518
|
+
# "realtime_average_flow":null,
|
504
519
|
# "date":"2014-07-21"
|
505
520
|
# }
|
506
521
|
# ]
|
507
522
|
# },
|
508
|
-
# {
|
523
|
+
# {
|
509
524
|
# "id":794,
|
510
525
|
# "name":"Plan-Id Test - 1 year basic",
|
511
|
-
# "usage":[
|
512
|
-
# {
|
526
|
+
# "usage":[
|
527
|
+
# {
|
513
528
|
# "gallons":8306,
|
529
|
+
# "seconds_ran":32978,
|
530
|
+
# "realtime_average_flow":null,
|
514
531
|
# "date":"2014-06-02"
|
515
532
|
# },
|
516
|
-
# {
|
533
|
+
# {
|
517
534
|
# "gallons":9015,
|
535
|
+
# "seconds_ran":38352,
|
536
|
+
# "realtime_average_flow":null,
|
518
537
|
# "date":"2014-06-09"
|
519
538
|
# },
|
520
|
-
# {
|
539
|
+
# {
|
521
540
|
# "gallons":8068,
|
541
|
+
# "seconds_ran":35777,
|
542
|
+
# "realtime_average_flow":null,
|
522
543
|
# "date":"2014-06-16"
|
523
544
|
# },
|
524
|
-
# {
|
545
|
+
# {
|
525
546
|
# "gallons":8564,
|
547
|
+
# "seconds_ran":34419,
|
548
|
+
# "realtime_average_flow":null,
|
526
549
|
# "date":"2014-06-23"
|
527
550
|
# },
|
528
|
-
# {
|
551
|
+
# {
|
529
552
|
# "gallons":8693,
|
553
|
+
# "seconds_ran":38603,
|
554
|
+
# "realtime_average_flow":null,
|
530
555
|
# "date":"2014-06-30"
|
531
556
|
# },
|
532
|
-
# {
|
557
|
+
# {
|
533
558
|
# "gallons":7871,
|
559
|
+
# "seconds_ran":37822,
|
560
|
+
# "realtime_average_flow":null,
|
534
561
|
# "date":"2014-07-07"
|
535
562
|
# },
|
536
|
-
# {
|
563
|
+
# {
|
537
564
|
# "gallons":5892,
|
565
|
+
# "seconds_ran":33325,
|
566
|
+
# "realtime_average_flow":null,
|
538
567
|
# "date":"2014-07-14"
|
539
568
|
# },
|
540
|
-
# {
|
569
|
+
# {
|
541
570
|
# "gallons":949,
|
571
|
+
# "seconds_ran":29000,
|
572
|
+
# "realtime_average_flow":null,
|
542
573
|
# "date":"2014-07-21"
|
543
574
|
# }
|
544
575
|
# ]
|
@@ -857,6 +888,195 @@ class WeatherMatic
|
|
857
888
|
make_request(uri,@request)
|
858
889
|
end
|
859
890
|
|
891
|
+
|
892
|
+
# Water Restrictions will tell you what watering restrictions are in effect for a particular postal code.
|
893
|
+
|
894
|
+
# Usage wm.rules(:postal_code => 12345)
|
895
|
+
|
896
|
+
# {
|
897
|
+
# "meta": {
|
898
|
+
# "access": true,
|
899
|
+
# "hmac": false,
|
900
|
+
# "success": true,
|
901
|
+
# "request": {
|
902
|
+
# "postal_code": "12345",
|
903
|
+
# "action": "index",
|
904
|
+
# "controller": "api/v2/water_restrictions",
|
905
|
+
# "format": "json"
|
906
|
+
# },
|
907
|
+
# "message": null
|
908
|
+
# },
|
909
|
+
# "result": {
|
910
|
+
# "water_restrictions": [
|
911
|
+
# {
|
912
|
+
# "id": 2,
|
913
|
+
# "name": "EVERY OTHER DAY",
|
914
|
+
# "effective_date": "2014-09-02",
|
915
|
+
# "restriction_end_date": null,
|
916
|
+
# "period_start_date": null,
|
917
|
+
# "period_length": 7,
|
918
|
+
# "period_frequency": 1,
|
919
|
+
# "days_of_week": 0,
|
920
|
+
# "criteria": 2,
|
921
|
+
# "criteria_2": "",
|
922
|
+
# "zoning": 1,
|
923
|
+
# "voluntary": false,
|
924
|
+
# "voluntary_percentage": null,
|
925
|
+
# "created_at": "2014-09-25T21:16:16Z",
|
926
|
+
# "updated_at": "2014-10-27T18:38:19Z",
|
927
|
+
# "checked_at": "2014-10-24T15:24:45Z",
|
928
|
+
# "authorities": [
|
929
|
+
# {
|
930
|
+
# "name": "Garland Water Department ",
|
931
|
+
# "role": 1,
|
932
|
+
# "category": 1,
|
933
|
+
# "website": "http://www.garlandenvironmentalwaste.com/gov/eg/ews/default.asp",
|
934
|
+
# "rebate": "$35 per Zone",
|
935
|
+
# "rebate_url": "http://www.texasishot.org/energy-efficiency-rebates/",
|
936
|
+
# "address_1": "417 Willowcrest",
|
937
|
+
# "address_2": "",
|
938
|
+
# "city": "Garland",
|
939
|
+
# "state": "Texas",
|
940
|
+
# "postal_code": "75040",
|
941
|
+
# "latitude": 32.9455,
|
942
|
+
# "longitude": -96.6354,
|
943
|
+
# "updated_at": "2014-10-28T17:02:37Z"
|
944
|
+
# }
|
945
|
+
# ],
|
946
|
+
# "boundaries": [
|
947
|
+
# {
|
948
|
+
# "name": "75204",
|
949
|
+
# "precedence": 1,
|
950
|
+
# "postal_code": "75204",
|
951
|
+
# "legal": 2,
|
952
|
+
# "city": null,
|
953
|
+
# "state": null,
|
954
|
+
# "longitude": null,
|
955
|
+
# "latitude": null
|
956
|
+
# },
|
957
|
+
# {
|
958
|
+
# "name": "12345",
|
959
|
+
# "precedence": 1,
|
960
|
+
# "postal_code": "12345",
|
961
|
+
# "legal": 3,
|
962
|
+
# "city": null,
|
963
|
+
# "state": null,
|
964
|
+
# "longitude": null,
|
965
|
+
# "latitude": null
|
966
|
+
# },
|
967
|
+
# {
|
968
|
+
# "name": "65487",
|
969
|
+
# "precedence": 1,
|
970
|
+
# "postal_code": "65487",
|
971
|
+
# "legal": 1,
|
972
|
+
# "city": null,
|
973
|
+
# "state": null,
|
974
|
+
# "longitude": null,
|
975
|
+
# "latitude": null
|
976
|
+
# },
|
977
|
+
# {
|
978
|
+
# "name": "75238",
|
979
|
+
# "precedence": 1,
|
980
|
+
# "postal_code": "75238",
|
981
|
+
# "legal": 1,
|
982
|
+
# "city": null,
|
983
|
+
# "state": null,
|
984
|
+
# "longitude": null,
|
985
|
+
# "latitude": null
|
986
|
+
# }
|
987
|
+
# ]
|
988
|
+
# },
|
989
|
+
# {
|
990
|
+
# "id": 6,
|
991
|
+
# "name": "EVERY OTHER DAY",
|
992
|
+
# "effective_date": "2014-09-02",
|
993
|
+
# "restriction_end_date": null,
|
994
|
+
# "period_start_date": null,
|
995
|
+
# "period_length": 7,
|
996
|
+
# "period_frequency": 3,
|
997
|
+
# "days_of_week": 0,
|
998
|
+
# "criteria": 1,
|
999
|
+
# "criteria_2": "",
|
1000
|
+
# "zoning": null,
|
1001
|
+
# "voluntary": false,
|
1002
|
+
# "voluntary_percentage": null,
|
1003
|
+
# "created_at": "2014-10-24T16:39:30Z",
|
1004
|
+
# "updated_at": "2014-10-27T20:43:09Z",
|
1005
|
+
# "checked_at": "2014-10-24T16:39:30Z",
|
1006
|
+
# "authorities": [
|
1007
|
+
# {
|
1008
|
+
# "name": "Garland Water Department ",
|
1009
|
+
# "role": 1,
|
1010
|
+
# "category": 1,
|
1011
|
+
# "website": "http://www.garlandenvironmentalwaste.com/gov/eg/ews/default.asp",
|
1012
|
+
# "rebate": "$35 per Zone",
|
1013
|
+
# "rebate_url": "http://www.texasishot.org/energy-efficiency-rebates/",
|
1014
|
+
# "address_1": "417 Willowcrest",
|
1015
|
+
# "address_2": "",
|
1016
|
+
# "city": "Garland",
|
1017
|
+
# "state": "Texas",
|
1018
|
+
# "postal_code": "75040",
|
1019
|
+
# "latitude": 32.9455,
|
1020
|
+
# "longitude": -96.6354,
|
1021
|
+
# "updated_at": "2014-10-28T17:02:37Z"
|
1022
|
+
# }
|
1023
|
+
# ],
|
1024
|
+
# "boundaries": [
|
1025
|
+
# {
|
1026
|
+
# "name": "75204",
|
1027
|
+
# "precedence": 1,
|
1028
|
+
# "postal_code": "75204",
|
1029
|
+
# "legal": 2,
|
1030
|
+
# "city": null,
|
1031
|
+
# "state": null,
|
1032
|
+
# "longitude": null,
|
1033
|
+
# "latitude": null
|
1034
|
+
# },
|
1035
|
+
# {
|
1036
|
+
# "name": "12345",
|
1037
|
+
# "precedence": 1,
|
1038
|
+
# "postal_code": "12345",
|
1039
|
+
# "legal": 3,
|
1040
|
+
# "city": null,
|
1041
|
+
# "state": null,
|
1042
|
+
# "longitude": null,
|
1043
|
+
# "latitude": null
|
1044
|
+
# },
|
1045
|
+
# {
|
1046
|
+
# "name": "65487",
|
1047
|
+
# "precedence": 1,
|
1048
|
+
# "postal_code": "65487",
|
1049
|
+
# "legal": 1,
|
1050
|
+
# "city": null,
|
1051
|
+
# "state": null,
|
1052
|
+
# "longitude": null,
|
1053
|
+
# "latitude": null
|
1054
|
+
# },
|
1055
|
+
# {
|
1056
|
+
# "name": "75238",
|
1057
|
+
# "precedence": 1,
|
1058
|
+
# "postal_code": "75238",
|
1059
|
+
# "legal": 1,
|
1060
|
+
# "city": null,
|
1061
|
+
# "state": null,
|
1062
|
+
# "longitude": null,
|
1063
|
+
# "latitude": null
|
1064
|
+
# }
|
1065
|
+
# ]
|
1066
|
+
# }
|
1067
|
+
# ]
|
1068
|
+
# }
|
1069
|
+
# }
|
1070
|
+
|
1071
|
+
def rules(params)
|
1072
|
+
data = URI.encode_www_form({
|
1073
|
+
"postal_code" => params[:postal_code]
|
1074
|
+
})
|
1075
|
+
uri = parse_uri(@base_uri+"/api/v2/water_restrictions.json?"+data)
|
1076
|
+
@request = make_get(uri)
|
1077
|
+
make_request(uri,@request)
|
1078
|
+
end
|
1079
|
+
|
860
1080
|
private
|
861
1081
|
|
862
1082
|
# This is the generic request - it cannot be called directly
|
@@ -871,8 +1091,8 @@ class WeatherMatic
|
|
871
1091
|
@request['x-api-hmac'] = generate_hmac_string(data)
|
872
1092
|
@request["x-api-key"] = api_key
|
873
1093
|
@request.basic_auth(username,password)
|
874
|
-
|
875
|
-
|
1094
|
+
puts "request headers are " + @request.to_hash.to_s
|
1095
|
+
puts "request body is " + @request.body.inspect
|
876
1096
|
response = @http.request(@request)
|
877
1097
|
return JSON.parse(response.body)
|
878
1098
|
# puts JSON.parse(response.body)
|
@@ -892,12 +1112,12 @@ class WeatherMatic
|
|
892
1112
|
|
893
1113
|
def api_key
|
894
1114
|
ENV['SLN_API_KEY']
|
895
|
-
# '
|
1115
|
+
# '0ecf72cdb0701a083a142bb6cb02dd92' # This should be an environment variable for best security - this is not a production key
|
896
1116
|
end
|
897
1117
|
|
898
1118
|
def secret_api_key
|
899
1119
|
ENV['SLN_API_SECRET_KEY']
|
900
|
-
# '
|
1120
|
+
# 'f375c1f9013388fbc0cb01987377f817' # This should be an environment variable for best security - this is not a production key
|
901
1121
|
end
|
902
1122
|
|
903
1123
|
def make_get(uri)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: weathermatic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Merritt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: SmartLink provides a web portal which connects SmartLine controllers
|
14
14
|
in the field to the cloud allowing basic operations like starting or stopping irrigation
|