sunscout 0.2 → 0.3

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: 644c483147167e8f1ef8cdfb1523410f0f573db2
4
- data.tar.gz: db5cd8d9fa95c7e639d8709462c6b384f30552c5
3
+ metadata.gz: 5f45706ac844935afe862c622ae4c429e11df56f
4
+ data.tar.gz: a0370ee2d6c1d12308ffde2e89c850a50521780e
5
5
  SHA512:
6
- metadata.gz: 086a705e56e0537293fef631e8e7e363547b9b35864a86887d32bbe230ab612da11585b66e04bec7035cf3c5cd921720565381d62a970c33726132dd85613438
7
- data.tar.gz: 800a75d24883102b32a6549235f685958c0040c59f4c0ca00cd5adcd9763b3fcdebdeddf8094ae62abcf706808b79a74e50d566166f5e8959317f7073439a4d7
6
+ metadata.gz: 906d6627928f2519e448079efb0a2f20c8bc3c51093176005fcc1fa261df4b94d7d9ee39d6fae76f7946c10df7cfd5514393b544b849027d4a61edac39f64d9f
7
+ data.tar.gz: 0a437e0385cbef5a53428a5189b15c913e68008bb37e1d95a2e7462f13e379c708c22bae3bce75e0b3a9149eb711cb8b0970585fce349d610a8512861cbd7797
@@ -0,0 +1,41 @@
1
+ # Change log
2
+
3
+ This document represents a high-level overview of changes made to this project.
4
+ It will not list every miniscule change, but will allow you to view - at a
5
+ glance - what to expact from upgrading to a new version.
6
+
7
+ ## [unpublished]
8
+
9
+ ### Added
10
+
11
+ ### Changed
12
+
13
+ ### Fixed
14
+
15
+ ### Security
16
+
17
+ ### Deprecated
18
+
19
+ ### Removed
20
+
21
+ ## [0.3.0] - 2016-09-08
22
+
23
+ ### Added
24
+
25
+ - [Net::SSH::Gateway](https://net-ssh.github.io/) support, to allow proxying
26
+ API requests via an SSH gateway.
27
+ - Changelog :)
28
+
29
+ ## [0.2.0] - 2016-08-31
30
+
31
+ ### Added
32
+
33
+ - Timezone support to Sunscout::SolarLog::SolarLog.
34
+
35
+
36
+ ## [0.1.0] - 2016-08-16
37
+
38
+ ### Added
39
+
40
+ - Bindings to [SolarLog](http://www.solar-log.com) controllers via
41
+ Sunscout::SolarLog::SolarLog and Sunscout::SolarLog::Client.
@@ -15,28 +15,55 @@ module Sunscout
15
15
  # c = Sunscout::SolarLog::Client.new('http://10.60.1.10')
16
16
  # data = c.get_data()
17
17
  # puts "Current power output: #{ data[:power_ac] }W"
18
+ #
19
+ # @example Proxying via SSH host
20
+ # require 'sunscout'
21
+ # require 'net/ssh/gateway'
22
+ # gateway = Net::SSH::Gateway.new('jump.example.com', 'johndoe', password: 'hidden')
23
+ # c = Sunscout::SolarLog::Client.new('http://192.168.1.10', ssh_gateway: gateway)
18
24
  class Client
19
25
  # Initialize a new instance of the class.
20
26
  # @param host [String] URI of the SolarLog web interface.
21
- def initialize(host)
27
+ # @param opts [Hash] Additional options
28
+ # @option opts [Net::SSH::Gateway] :ssh_gateway SSH gateway through which to proxy the request.
29
+ def initialize(host, opts = {})
22
30
  @host = host
31
+
32
+ @ssh_gateway = opts.fetch(:ssh_gateway, nil)
23
33
  end
24
34
 
25
35
  # Retrieve data from the HTTP API.
26
36
  # @return [Hash<Symbol, String|Integer>] Hash containing retrieved data
27
37
  def get_data
38
+ if @ssh_gateway
39
+ get_data_ssh
40
+ else
41
+ get_data_direct
42
+ end
43
+ end
44
+
45
+ private
46
+ def get_data_direct
28
47
  uri = build_uri
29
48
  req = build_request(uri)
30
- data = send_request(req, uri)
49
+ send_request(req, uri)
50
+ end
31
51
 
32
- data
52
+ def get_data_ssh
53
+ uri = build_uri
54
+ @ssh_gateway.open(uri.hostname, uri.port) do |port|
55
+ uri.hostname = '127.0.0.1'
56
+ uri.port = port
57
+
58
+ req = build_request(uri)
59
+ send_request(req, uri)
60
+ end
33
61
  end
34
62
 
35
- private
36
63
  # Create URI of HTTP endpoint
37
64
  def build_uri
38
65
  URI("#{ @host }/#{ REQUEST_QUERY }")
39
- end
66
+ end
40
67
 
41
68
  # Build HTTP POST request
42
69
  # @param uri [URI] URI of HTTP endpoint
@@ -56,7 +83,7 @@ module Sunscout
56
83
  http.request(req)
57
84
  end
58
85
 
59
- # Todo: Exception handling:
86
+ # TODO: Exception handling:
60
87
  # - catching in case of failure (DNS, timeout, ...)
61
88
  # - throwing in case of API failure
62
89
  case res
@@ -72,10 +72,15 @@ module Sunscout
72
72
  # This also immediately queries data from the SolarLog API.
73
73
  #
74
74
  # @param host [String] URI of the SolarLog web interface
75
- # @param timezone [String] Timezone (or offset) which the SolarLog station resides in.
75
+ # @param opts [Hash] Additional options.
76
+ # If not consumed by this class itself, they are passed to {Client#initialize}
77
+ # Be sure to check there for all possibilities!
78
+ # @option opts [String] :timezone Timezone (or offset) which the SolarLog station resides in.
76
79
  # If none is specified, assume UTC.
77
- def initialize(host, timezone: '+0000')
78
- client = Sunscout::SolarLog::Client.new(host)
80
+ def initialize(host, opts = {})
81
+ timezone = opts.delete('timezone') || '+0000'
82
+
83
+ client = Sunscout::SolarLog::Client.new(host, opts)
79
84
  data = client.get_data
80
85
 
81
86
  # SolarLog returns the time a) without a timezone indicator and b) as whatever the station is configured.
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "sunscout"
7
- spec.version = '0.2'
7
+ spec.version = '0.3'
8
8
  spec.authors = ["Michael Senn"]
9
9
  spec.email = ["michael@morrolan.ch"]
10
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sunscout
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Senn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-31 00:00:00.000000000 Z
11
+ date: 2016-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -76,6 +76,7 @@ files:
76
76
  - ".gitignore"
77
77
  - ".rspec"
78
78
  - ".travis.yml"
79
+ - CHANGELOG.md
79
80
  - Gemfile
80
81
  - LICENSE.txt
81
82
  - README.md