Feat/add ruby sdk (#583)
This commit is contained in:
parent
ecd6cbaee6
commit
cb6e73347e
15 changed files with 460 additions and 2 deletions
42
sdks/ruby-client/test/dify_client_test.rb
Normal file
42
sdks/ruby-client/test/dify_client_test.rb
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
require 'test_helper'
|
||||
require 'webmock/minitest'
|
||||
require 'json'
|
||||
require 'dify_client'
|
||||
|
||||
class DifyClientTest < Minitest::Test
|
||||
def setup
|
||||
@api_key = 'YOUR_API_KEY'
|
||||
@client = DifyClient::Client.new(@api_key)
|
||||
end
|
||||
|
||||
def test_update_api_key
|
||||
new_api_key = 'NEW_API_KEY'
|
||||
|
||||
@client.update_api_key(new_api_key)
|
||||
|
||||
assert_equal new_api_key, @client.instance_variable_get(:@api_key)
|
||||
end
|
||||
|
||||
def test_get_application_parameters
|
||||
user = 'USER_ID'
|
||||
expected_response = {}
|
||||
|
||||
stub_request(:get, "https://api.dify.ai/v1/parameters").
|
||||
with(
|
||||
body: {"user"=>"USER_ID"},
|
||||
headers: {
|
||||
'Accept'=>'*/*',
|
||||
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
||||
'Authorization'=>'Bearer YOUR_API_KEY',
|
||||
'Content-Type'=>'application/x-www-form-urlencoded',
|
||||
'Responsetype'=>'json',
|
||||
'User-Agent'=>'Ruby'
|
||||
}).
|
||||
to_return(status: 200, body: expected_response.to_json, headers: {})
|
||||
|
||||
response = @client.get_application_parameters(user)
|
||||
|
||||
assert_equal expected_response, response
|
||||
end
|
||||
|
||||
end
|
||||
6
sdks/ruby-client/test/test_helper.rb
Normal file
6
sdks/ruby-client/test/test_helper.rb
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
|
||||
require "dify_client"
|
||||
|
||||
require "minitest/autorun"
|
||||
Loading…
Add table
Add a link
Reference in a new issue