Feat/add ruby sdk (#583)

This commit is contained in:
crazywoola 2023-07-18 10:18:58 +08:00 • committed by GitHub
commit cb6e73347e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 460 additions and 2 deletions

View 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

View file

@ -0,0 +1,6 @@
# frozen_string_literal: true
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
require "dify_client"
require "minitest/autorun"