```ruby
require "rest_client"

module CatsocketClient
  class Publisher < Struct.new(:url, :api_key)

    def publish(channel, data)
      RestClient.post(url, guid: 0, api_key: api_key, channel: channel, data: data.to_json)
    end

  end
end
```

Convert data to json only if it is not already a string
user
```ruby
require "rest_client"

module CatsocketClient
  class Publisher < Struct.new(:url, :api_key)

    def publish(channel, data)
      json = data.is_a?(String) ? data : data.to_json
      RestClient.post(url, guid: 0, api_key: api_key, channel: channel, data: json)
    end

  end
end
```
assistant