obsws 0.2.1 → 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: c125c30687cdcd22d868636a4d7bfbe7776939a8b4997842785b3868e7959151
4
- data.tar.gz: 7f4c51a8231083c220c95d4e0fa34da8bf7712307adcd21b32565043a3e28d7f
3
+ metadata.gz: f55dbfe2267a8b2dec6fc0c347b537b1a9727de641ec762d16128a40ee3397a4
4
+ data.tar.gz: 3ef38f6bfb12db426c31afdb130e25debda7173e135daf9d88677d6002365c55
5
5
  SHA512:
6
- metadata.gz: 5b14e996f1e06788e88b66d44fef72f06d5ba0ad07b38e83332a19dfa833c724f33ea2a2119336105cca63034f0a015e53a38b60d1049dc8745ae9be92d51028
7
- data.tar.gz: bfd3821cefe5a515feca6746edb5d042141492061bfa6303f1c6daf56a2215d0c4ce076224bb3b7873879649fe96f36a4ee223e6aeae08020988f3d8790fe26c
6
+ metadata.gz: c2914cfd19dd1107ecd0d8825ca5386b9e6574983527098801fed5f0ed3c06520490f139d9c3837d45aa2791cd8e20e263b07ada46d46d7957a399aebd629ad2
7
+ data.tar.gz: 1d76544ea453fc16bad1d38b64ff4328ad1665520323112694007377e75959ce78f05027cfb85ef176b74148374f15c60b03b627f92552e6741171919f930c37
data/README.md CHANGED
@@ -114,15 +114,12 @@ For a full list of status codes refer to [Codes](https://github.com/obsproject/o
114
114
 
115
115
  ### Logging
116
116
 
117
- To see the raw messages set log level to debug
117
+ To enable logs set an environmental variable `OBSWS_LOG_LEVEL` to the appropriate level.
118
118
 
119
- example:
120
-
121
- ```ruby
122
- require "obsws"
119
+ example in powershell:
123
120
 
124
- OBSWS::LOGGER.debug!
125
- ...
121
+ ```powershell
122
+ $env:OBSWS_LOG_LEVEL="DEBUG"
126
123
  ```
127
124
 
128
125
  ### Tests
data/lib/obsws/base.rb CHANGED
@@ -6,6 +6,7 @@ require "waitutil"
6
6
 
7
7
  require_relative "mixin"
8
8
  require_relative "error"
9
+ require_relative "logger"
9
10
 
10
11
  module OBSWS
11
12
  class Socket
@@ -22,6 +23,7 @@ module OBSWS
22
23
  end
23
24
 
24
25
  class Base
26
+ include Logging
25
27
  include Mixin::OPCodes
26
28
 
27
29
  attr_reader :closed
@@ -37,14 +39,13 @@ module OBSWS
37
39
  @driver =
38
40
  WebSocket::Driver.client(Socket.new("ws://#{host}:#{port}", @socket))
39
41
  @driver.on :open do |msg|
40
- LOGGER.debug("driver socket open")
42
+ logger.debug("driver socket open")
41
43
  end
42
44
  @driver.on :close do |msg|
43
- LOGGER.debug("driver socket closed")
45
+ logger.debug("driver socket closed")
44
46
  @closed = true
45
47
  end
46
48
  @driver.on :message do |msg|
47
- LOGGER.debug("received: #{msg.data}")
48
49
  msg_handler(JSON.parse(msg.data, symbolize_names: true))
49
50
  end
50
51
  start_driver
@@ -91,7 +92,7 @@ module OBSWS
91
92
  if @password.empty?
92
93
  raise OBSWSError("auth enabled but no password provided")
93
94
  end
94
- LOGGER.info("initiating authentication")
95
+ logger.info("initiating authentication")
95
96
  payload[:d][:authentication] = auth_token(**auth)
96
97
  end
97
98
  @driver.text(JSON.generate(payload))
@@ -117,7 +118,7 @@ module OBSWS
117
118
  }
118
119
  }
119
120
  payload[:d][:requestData] = data if data
120
- LOGGER.debug("sending request: #{payload}")
121
+ logger.debug("sending request: #{payload}")
121
122
  @driver.text(JSON.generate(payload))
122
123
  end
123
124
  end
data/lib/obsws/event.rb CHANGED
@@ -2,6 +2,7 @@ require "json"
2
2
 
3
3
  require_relative "util"
4
4
  require_relative "mixin"
5
+ require_relative "logger"
5
6
 
6
7
  module OBSWS
7
8
  module Events
@@ -62,6 +63,7 @@ module OBSWS
62
63
  end
63
64
 
64
65
  class Client
66
+ include Logging
65
67
  include Callbacks
66
68
  include Mixin::TearDown
67
69
  include Mixin::OPCodes
@@ -69,9 +71,10 @@ module OBSWS
69
71
  def initialize(**kwargs)
70
72
  kwargs[:subs] ||= SUBS::LOW_VOLUME
71
73
  @base_client = Base.new(**kwargs)
72
- LOGGER.info("#{self} succesfully identified with server")
74
+ logger.info("#{self} succesfully identified with server")
73
75
  @base_client.updater = ->(op_code, data) {
74
76
  if op_code == Mixin::OPCodes::EVENT
77
+ logger.debug("received: #{data}")
75
78
  event = data[:eventType]
76
79
  data = data.fetch(:eventData, {})
77
80
  notify_observers(event, Mixin::Data.new(data, data.keys))
@@ -0,0 +1,11 @@
1
+ require "logger"
2
+
3
+ module OBSWS
4
+ module Logging
5
+ def logger
6
+ @logger = Logger.new($stdout, level: ENV.fetch("OBSWS_LOG_LEVEL", "WARN"))
7
+ @logger.progname = instance_of?(::Module) ? name : self.class.name
8
+ @logger
9
+ end
10
+ end
11
+ end
data/lib/obsws/req.rb CHANGED
@@ -4,18 +4,21 @@ require_relative "base"
4
4
  require_relative "error"
5
5
  require_relative "util"
6
6
  require_relative "mixin"
7
+ require_relative "logger"
7
8
 
8
9
  module OBSWS
9
10
  module Requests
10
11
  class Client
12
+ include Logging
11
13
  include Error
12
14
  include Mixin::TearDown
13
15
  include Mixin::OPCodes
14
16
 
15
17
  def initialize(**kwargs)
16
18
  @base_client = Base.new(**kwargs)
17
- LOGGER.info("#{self} succesfully identified with server")
19
+ logger.info("#{self} succesfully identified with server")
18
20
  @base_client.updater = ->(op_code, data) {
21
+ logger.debug("response received: #{data}")
19
22
  @response = data if op_code == Mixin::OPCodes::REQUESTRESPONSE
20
23
  }
21
24
  @response = {requestId: 0}
@@ -56,7 +59,7 @@ module OBSWS
56
59
  @response[:responseData]
57
60
  rescue WaitUtil::TimeoutError
58
61
  msg = "no response with matching id received"
59
- LOGGER.error(msg)
62
+ logger.error(msg)
60
63
  raise OBSWSError.new(msg)
61
64
  end
62
65
 
data/lib/obsws/util.rb CHANGED
@@ -2,12 +2,11 @@ module OBSWS
2
2
  module Util
3
3
  class ::String
4
4
  def to_camel
5
- self.split(/_/).map(&:capitalize).join
5
+ split("_").map(&:capitalize).join
6
6
  end
7
7
 
8
8
  def to_snake
9
- self
10
- .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
9
+ gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
11
10
  .gsub(/([a-z\d])([A-Z])/, '\1_\2')
12
11
  .downcase
13
12
  end
data/lib/obsws/version.rb CHANGED
@@ -7,11 +7,11 @@ module OBSWS
7
7
  end
8
8
 
9
9
  def minor
10
- 2
10
+ 3
11
11
  end
12
12
 
13
13
  def patch
14
- 1
14
+ 0
15
15
  end
16
16
 
17
17
  def to_a
data/lib/obsws.rb CHANGED
@@ -1,11 +1,5 @@
1
- require "logger"
2
-
3
1
  require_relative "obsws/req"
4
2
  require_relative "obsws/event"
5
3
 
6
4
  module OBSWS
7
- include Logger::Severity
8
-
9
- LOGGER = Logger.new(STDOUT)
10
- LOGGER.level = WARN
11
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: obsws
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - onyx_online
@@ -108,6 +108,7 @@ files:
108
108
  - lib/obsws/base.rb
109
109
  - lib/obsws/error.rb
110
110
  - lib/obsws/event.rb
111
+ - lib/obsws/logger.rb
111
112
  - lib/obsws/mixin.rb
112
113
  - lib/obsws/req.rb
113
114
  - lib/obsws/util.rb