syncsign 0.2.3 → 0.3.0

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
  SHA256:
3
- metadata.gz: 0c71d9ba121262edad7f9e12094cede28b97909345521b48898bc792da31070d
4
- data.tar.gz: 63a4e344b54a6ee357e636c5e62e56fc33565a17561a8b616a356304f5f0d10c
3
+ metadata.gz: e261ff9af0745d4e8e96f7ea246dd5318a9dae6abf59572ae41ad0090d0b91d3
4
+ data.tar.gz: d0964bfcc113b69e72d54c7a513d3ad1156dc2ce6488fc6d2bc29ba1f9814495
5
5
  SHA512:
6
- metadata.gz: d500314480cda678242c4204b88cb0275c5a2d10642922cc79e49f05850bd32a064b646d25aed15401ad56f2b8f01112ced44a676e2ce2f3e00e7ba42a0eece9
7
- data.tar.gz: 5e1acd15b5443e3a5097e1e3a89f520a610efdea3c37caea5f1d328e1f1d60c3dec152bcc9532318e8e21341233c50a4f2056f7ca52fb2a2d09981b2b63b6dcf
6
+ metadata.gz: c9cb756b7b3e6220a23912168fcb098652c038cecb2e3f085af83b917ea74db74429bc13241787c6b4137c894b2ec402336351d9d69a282b538c24adaf79ca30
7
+ data.tar.gz: c8bbd89fd3d3127b36977059accc5fbf340eb4ce13bdc83c5069949c68280babeb794ce16280a4d989494611cf968838b051e721254ad293b46ac4df9bdfa377
data/README.md CHANGED
@@ -29,11 +29,24 @@ Create a SyncSign Service instance using your API key (found in the SyncSign por
29
29
  template = SyncSign::Template.new(items: items)
30
30
  node.render(template: template)
31
31
 
32
+ ## Direct Rendering
33
+ The SyncSign hubs have a simplified API that can be used, bypassing the cloud service. This can result in significant time savings (15s vs 25s) as well as less time between sending the request and the first visible change on the display. This is especially useful for the 4.2" model with buttons, as the time a user spends waiting after pressing a button can be significantly reduced.
34
+
35
+ To enable direct rendering, create a file named signhubs.cfg in either the same directory as your app, the current directory, or /etc/signhubs.cfg. This file should have the following format:
36
+ hub-serial-nbr hub-ip hub-apikey
37
+
38
+ As an example:
39
+ MCFEF5583A9DCA 192.168.0.50 8ab8125b-5d23-1b9a-e55e-a8b3d8c04614
40
+
41
+ Once this is created, you can test it using examples/hubs.rb which should now list your hub as direct rendering capable. To enable this in your app, pass "render\_direct: true" when instantiating a new SyncSign::Service object.
42
+
43
+
32
44
  ## Examples
33
45
 
34
46
  Check out the examples/ folder for:
35
47
  * account\_info.rb - Show information about the account associated with the provided API key.
36
48
  * nodes.rb - List all nodes on the system and information about them.
49
+ * hubs.rb - List all hubs on the system and whether we have enough info to support direct rendering.
37
50
  * render.rb - Render a sample screen to the given node.
38
51
 
39
52
  ## Full Documentation
@@ -6,13 +6,18 @@ module SyncSign
6
6
  attr_reader :sn
7
7
  # @return [String] the friendly name of the hub.
8
8
  attr_reader :name
9
-
9
+ # @return [String] the IP address or hostname of the hub.
10
+ attr_reader :addr
11
+ # @return [String] the API key of the hub.
12
+ attr_reader :apikey
13
+
10
14
  ##
11
15
  # Initialize a new hub object (normally only called from Service#hubs)
12
- def initialize(sn: null, name: null, service: null)
16
+ def initialize(service: nil, sn: nil, name: nil)
13
17
  @sn = sn
14
18
  @name = name
15
19
  @service = service
20
+ load_hub_info
16
21
  end
17
22
 
18
23
  ##
@@ -20,6 +25,38 @@ module SyncSign
20
25
  def nodes
21
26
  SyncSign::Node::parse_collection(service: @service, nodeinfo: @service.api_call(path: "/devices/#{@sn}/nodes"))
22
27
  end
28
+
29
+
30
+ def direct_rendering_capable?
31
+ return @addr && @apikey
32
+ end
33
+
34
+ private
35
+
36
+ ##
37
+ # Load info about a hub from the config file (IP address and API key)
38
+ def load_hub_info
39
+ cfg_locations = [
40
+ "./signhubs.cfg",
41
+ "#{File::dirname($0)}/signhubs.cfg",
42
+ "/etc/signhubs.cfg"
43
+ ]
44
+ cfgfile = cfg_locations.find { |file| File.exist?(file) }
45
+ return unless cfgfile
46
+
47
+ File.open(cfgfile) do |f|
48
+ f.each_line do |line|
49
+ next if line[0] == "#"
50
+
51
+ hubinfo = line.split(/\s+/)
52
+ if(@sn == hubinfo[0]) then
53
+ @addr = hubinfo[1]
54
+ @apikey = hubinfo[2]
55
+ return true
56
+ end
57
+ end
58
+ end
59
+ end
23
60
  end
24
61
  end
25
62
 
@@ -6,7 +6,7 @@ module SyncSign
6
6
  # Render a template to this display.
7
7
  # @param template [Template] Template to render to this display.
8
8
  def render(template: nil)
9
- @service.api_call(type: :post, path: "/nodes/#{@id}/renders", data: template.to_s)
9
+ @service.api_call(type: :post, path: "/nodes/#{@id}/renders", data: template.to_s, node: self, direct: @service.direct_rendering?)
10
10
  end
11
11
 
12
12
  ##
@@ -16,7 +16,7 @@ module SyncSign
16
16
 
17
17
  ##
18
18
  # Initialize a new Node object (normally only called from Hub#nodes or Service#nodes).
19
- def initialize(service: nil, id: nil, name: nil, online: nil, battery: nil, signal: nil, model: nil)
19
+ def initialize(service: nil, id: nil, name: nil, online: nil, battery: nil, signal: nil, model: nil, hubid: nil)
20
20
  @service = service
21
21
  @id = id
22
22
  @name = name
@@ -24,6 +24,7 @@ module SyncSign
24
24
  @battery = battery
25
25
  @signal = signal
26
26
  @model = model
27
+ @hubid = hubid
27
28
  end
28
29
 
29
30
  ##
@@ -32,6 +33,12 @@ module SyncSign
32
33
  @online
33
34
  end
34
35
 
36
+ ##
37
+ # Return the hub that this node is associated with
38
+ def hub
39
+ Hub.new(service: @service, sn: @hubid)
40
+ end
41
+
35
42
  ##
36
43
  # Parse a JSON description of a single node into a +Node+ object.
37
44
  # Normally only called from Hub#nodes or Service#nodes.
@@ -50,7 +57,8 @@ module SyncSign
50
57
  online: nodeinfo['onlined'],
51
58
  battery: nodeinfo['batteryLevel'],
52
59
  signal: nodeinfo['signalLevel'],
53
- model: nodeinfo['model']
60
+ model: nodeinfo['model'],
61
+ hubid: nodeinfo['thingName']
54
62
  )
55
63
  end
56
64
 
@@ -16,8 +16,11 @@ module SyncSign
16
16
  ##
17
17
  # Set up a new connection to the SyncSign cloud service.
18
18
  # @param apikey [String] the API key provided through the SyncSign portal.
19
- def initialize(apikey: null)
19
+ # @param render_direct [Boolean] try to send renders directly to the hub,
20
+ # bypassing the cloud service.
21
+ def initialize(apikey: nil, render_direct: false)
20
22
  @apikey = apikey
23
+ @directrender = render_direct
21
24
  @baseurl = "https://api.sync-sign.com/v2/key/#{apikey}"
22
25
  end
23
26
 
@@ -57,16 +60,28 @@ module SyncSign
57
60
  Node::parse(service: self, nodeinfo: api_call(path: "/nodes/#{id}"))
58
61
  end
59
62
 
63
+ ##
64
+ # Query whether we are rendering direct to the hub or via the cloud.
65
+ def direct_rendering?
66
+ @directrender
67
+ end
68
+
60
69
  ##
61
70
  # Make a call to the SyncSign cloud service.
62
71
  # @param type [Symbol] The HTTP method to use, either :get or :put.
63
72
  # @param path [String] The path to make the API call to, minus the base path.
64
73
  # @param data [String] The POST data to send with the API call.
74
+ # @param direct [Boolean] Whether to try to send the call directly to the hub,
75
+ # bypassing the cloud service.
76
+ # @param node [Node] The SyncSign node that this request is associated with.
77
+ # Optional unless using direct rendering, in which case it is required.
65
78
  # @api private
66
- def api_call(type: :get, path: "", data: "")
67
- apiurl = URI.parse("#{@baseurl}#{path}")
79
+ def api_call(type: :get, path: "", data: "", direct: false, node: nil)
80
+ baseurl = @baseurl
81
+ baseurl = "http://#{node.hub.addr}/key/#{node.hub.apikey}" if direct and node.hub.direct_rendering_capable?
82
+ apiurl = URI.parse("#{baseurl}#{path}")
68
83
  http_obj = Net::HTTP.new(apiurl.host, apiurl.port)
69
- http_obj.use_ssl = true
84
+ http_obj.use_ssl = baseurl.include?("https")
70
85
  response = nil
71
86
  http_obj.start() do |http|
72
87
  req = nil
@@ -1,4 +1,4 @@
1
1
  module SyncSign
2
2
  # The version number of the SyncSign module.
3
- VERSION = '0.2.3'
3
+ VERSION = '0.3.0'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: syncsign
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sarahemm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-18 00:00:00.000000000 Z
11
+ date: 2020-08-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Interface library for SyncSign e-paper displays
14
14
  email: github@sen.cx