raekfile updated

rework examples
This commit is contained in:
onyx-and-iris 2023-07-21 06:37:14 +01:00
parent 15dcaeedda
commit 15c4baf5d7
12 changed files with 42 additions and 131 deletions

View File

@ -28,12 +28,13 @@ bundle install
#### Example `main.rb`
pass `host`, `port` and `password` as keyword arguments.
Pass `host`, `port` and `password` as keyword arguments.
```ruby
require "obsws"
def main
class Main
def run
OBSWS::Requests::Client
.new(host: "localhost", port: 4455, password: "strongpassword")
.run do |client|
@ -41,24 +42,25 @@ def main
client.toggle_input_mute("Mic/Aux")
end
end
end
main if $0 == __FILE__
Main.new.run if $PROGRAM_NAME == __FILE__
```
Passing OBSWS::Requests::Client.run a block closes the socket once the block returns.
### Requests
Method names for requests match the API calls but snake cased. `run` accepts a block that closes the socket once you are done.
Method names for requests match the API calls but snake cased.
example:
```ruby
r_client.run do
# GetVersion
resp = r_client.get_version
# SetCurrentProgramScene
r_client.set_current_program_scene("BRB")
end
```
For a full list of requests refer to [Requests](https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#requests)

View File

@ -14,7 +14,7 @@ task :events do
ruby filepath
end
task :levels do
filepath = File.join(HERE, "examples", "levels", "main.rb")
filepath = File.join(HERE, "examples", "events", "main.rb")
ruby filepath
end
task :scene_rotate do

View File

@ -1,7 +0,0 @@
# frozen_string_literal: true
source "https://rubygems.org"
# gem "rails"
gem "obsws", path: "../.."

View File

@ -1,25 +0,0 @@
PATH
remote: ../..
specs:
obsws (0.1.3)
observer (~> 0.1.1)
waitutil (~> 0.2.1)
websocket-driver (~> 0.7.5)
GEM
remote: https://rubygems.org/
specs:
observer (0.1.1)
waitutil (0.2.1)
websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
PLATFORMS
x64-mingw-ucrt
DEPENDENCIES
obsws!
BUNDLED WITH
2.3.22

View File

@ -1,4 +1,4 @@
require "obsws"
require_relative "../../lib/obsws"
require "yaml"
OBSWS::LOGGER.info!
@ -53,4 +53,4 @@ def conn_from_yaml
YAML.load_file("obs.yml", symbolize_names: true)[:connection]
end
Main.new(**conn_from_yaml).run if $0 == __FILE__
Main.new(**conn_from_yaml).run if $PROGRAM_NAME == __FILE__

View File

@ -1,7 +0,0 @@
# frozen_string_literal: true
source "https://rubygems.org"
# gem "rails"
gem "obsws", path: "../.."

View File

@ -1,25 +0,0 @@
PATH
remote: ../..
specs:
obsws (0.1.3)
observer (~> 0.1.1)
waitutil (~> 0.2.1)
websocket-driver (~> 0.7.5)
GEM
remote: https://rubygems.org/
specs:
observer (0.1.1)
waitutil (0.2.1)
websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
PLATFORMS
x64-mingw-ucrt
DEPENDENCIES
obsws!
BUNDLED WITH
2.4.15

View File

@ -1,4 +1,4 @@
require "obsws"
require_relative "../../lib/obsws"
require "yaml"
OBSWS::LOGGER.info!
@ -45,4 +45,4 @@ def conn_from_yaml
YAML.load_file("obs.yml", symbolize_names: true)[:connection]
end
Main.new(**conn_from_yaml).run if $0 == __FILE__
Main.new(**conn_from_yaml).run if $PROGRAM_NAME == __FILE__

View File

@ -1,7 +0,0 @@
# frozen_string_literal: true
source "https://rubygems.org"
# gem "rails"
gem "obsws", path: "../.."

View File

@ -1,25 +0,0 @@
PATH
remote: ../..
specs:
obsws (0.1.3)
observer (~> 0.1.1)
waitutil (~> 0.2.1)
websocket-driver (~> 0.7.5)
GEM
remote: https://rubygems.org/
specs:
observer (0.1.1)
waitutil (0.2.1)
websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
PLATFORMS
x64-mingw-ucrt
DEPENDENCIES
obsws!
BUNDLED WITH
2.3.22

View File

@ -1,13 +1,14 @@
require "obsws"
require_relative "../../lib/obsws"
require "yaml"
OBSWS::LOGGER.info!
class Main
def conn_from_yaml
YAML.load_file("obs.yml", symbolize_names: true)[:connection]
end
def main
def run
OBSWS::Requests::Client.new(**conn_from_yaml).run do |client|
resp = client.get_scene_list
resp.scenes.reverse_each do |scene|
@ -17,5 +18,7 @@ def main
end
end
end
end
main if $0 == __FILE__
Main.new.run if $PROGRAM_NAME == __FILE__

View File

@ -1,6 +1,7 @@
require_relative "lib/obsws"
def main
class Main
def run
OBSWS::Requests::Client.new(
host: "localhost",
port: 4455,
@ -10,5 +11,6 @@ def main
client.toggle_input_mute("Mic/Aux")
end
end
end
main if $0 == __FILE__
Main.new.run if $PROGRAM_NAME == __FILE__