geekdict 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3ce49995415783d264d2993a3f815a7155e4b2a117f5fae350db4b95860c96f8
4
- data.tar.gz: 02fc16dd11252e493b0072fb81fc4cb345d1fc0334b0cde51dfb09e8c8acbe01
3
+ metadata.gz: eff23b6e34e7eb5c9a36430dab91a144290175c92419e434a73b10805182f1b9
4
+ data.tar.gz: 392b150951352cb80c6fa8035e248e1f6c3e5255b314ce6f74f17ba3a87d96ac
5
5
  SHA512:
6
- metadata.gz: 6cb588fef60055e7814131811eb4147fcc1894f4c3d9b918e43732b5e2804d78d4b06ba57989eece6fd0a3a2dee1cbbf74565a586464b8d5332fefab1b683274
7
- data.tar.gz: 570f2f163ff7e424a783ea606aad2cd0e4cf138cdbbec0e2c4a432124b0d9f91b244d60a4fdb254101d59e9fefa615a589ac7b1843b7403cd04568dee31b7b83
6
+ metadata.gz: e4d4ea6ddb6d3701a6f9d5feed9b192ed080f87ac427263e1aa5480e04521dfe65670c6a3e22f798d9386f65eaa188ed2c15f0539e821e42a88d345dbadb07d6
7
+ data.tar.gz: e99e68f27c568c5eeb4564e5593f1b9fac733f4ca799b7858a7819726f0dbc1f471595e552b5e875dcc5ba0e64fd6472c85b717e1e28bac0e7773fb5605eab09
@@ -1,10 +1,11 @@
1
1
  require "yaml"
2
+ require "fileutils"
2
3
 
3
4
  module GeekDict
4
5
  module Config
5
6
  CONFIG_PATH = File.expand_path("~/.geekdict.config")
6
7
  DEFAULT_PROVIDER = "openrouter"
7
- DEFAULT_MODEL = "google/gemini-2.5-flash-preview"
8
+ DEFAULT_MODEL = "google/gemini-2.5-flash-lite"
8
9
  ALLOWED_PROVIDERS = ['openai', 'openrouter', 'youdao'].freeze
9
10
 
10
11
  module_function
@@ -12,6 +13,12 @@ module GeekDict
12
13
  # Method to load configuration from ~/.geekdict.config
13
14
  def load_config
14
15
  config = {}
16
+
17
+ # If config file doesn't exist, create it with default values
18
+ unless File.exist?(CONFIG_PATH)
19
+ create_default_config
20
+ end
21
+
15
22
  if File.exist?(CONFIG_PATH)
16
23
  begin
17
24
  loaded_config = YAML.load_file(CONFIG_PATH)
@@ -29,5 +36,28 @@ module GeekDict
29
36
  model: config[:model]
30
37
  }
31
38
  end
39
+
40
+ # Method to create default configuration file
41
+ def create_default_config
42
+ default_config = {
43
+ 'provider' => DEFAULT_PROVIDER,
44
+ 'model' => DEFAULT_MODEL
45
+ }
46
+
47
+ begin
48
+ # Ensure the directory exists
49
+ config_dir = File.dirname(CONFIG_PATH)
50
+ FileUtils.mkdir_p(config_dir) unless Dir.exist?(config_dir)
51
+
52
+ # Write the default config
53
+ File.open(CONFIG_PATH, 'w') do |file|
54
+ file.write(YAML.dump(default_config))
55
+ end
56
+
57
+ puts "Created default config file at #{CONFIG_PATH}"
58
+ rescue => e
59
+ warn "Warning: Could not create config file #{CONFIG_PATH}: #{e.message}"
60
+ end
61
+ end
32
62
  end
33
63
  end
@@ -13,6 +13,8 @@ module GeekDict
13
13
  effective_model = model || 'google/gemini-2.5-flash-preview' # Fallback, though CLI provides default
14
14
 
15
15
  client = HTTPClient.new
16
+ # OpenRouter is stateless; avoid parsing unsupported SameSite cookie attributes.
17
+ client.cookie_manager = nil
16
18
  headers = {
17
19
  'Content-Type' => 'application/json',
18
20
  'Authorization' => "Bearer #{ENV.fetch('OPENROUTER_API_KEY')}",
@@ -1,3 +1,3 @@
1
1
  module GeekDict
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -0,0 +1,24 @@
1
+ require 'geekdict'
2
+
3
+ describe GeekDict::OpenRouter do
4
+ describe '.translate' do
5
+ it 'disables cookies before posting to OpenRouter' do
6
+ client = double('HTTPClient')
7
+ response = double(
8
+ 'response',
9
+ status: 200,
10
+ body: { choices: [{ message: { content: 'Theory' } }] }.to_json
11
+ )
12
+ original_api_key = ENV['OPENROUTER_API_KEY']
13
+ ENV['OPENROUTER_API_KEY'] = 'test-api-key'
14
+
15
+ HTTPClient.stub(:new).and_return(client)
16
+ client.should_receive(:cookie_manager=).with(nil).ordered
17
+ client.should_receive(:post).ordered.and_return(response)
18
+
19
+ expect(described_class.translate('理论')).to eq('Theory')
20
+ ensure
21
+ ENV['OPENROUTER_API_KEY'] = original_api_key
22
+ end
23
+ end
24
+ end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geekdict
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wenbing Li
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2025-04-22 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rake
@@ -120,12 +119,12 @@ files:
120
119
  - lib/geekdict/youdao/config.rb
121
120
  - spec/cli_spec.rb
122
121
  - spec/debugger_spec.rb
122
+ - spec/openrouter/api_spec.rb
123
123
  - spec/youdao/api_spec.rb
124
124
  homepage: https://github.com/wbinglee/geekdict
125
125
  licenses:
126
126
  - MIT
127
127
  metadata: {}
128
- post_install_message:
129
128
  rdoc_options: []
130
129
  require_paths:
131
130
  - lib
@@ -140,11 +139,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
139
  - !ruby/object:Gem::Version
141
140
  version: '0'
142
141
  requirements: []
143
- rubygems_version: 3.5.22
144
- signing_key:
142
+ rubygems_version: 3.6.9
145
143
  specification_version: 4
146
144
  summary: A command line tool for translation.
147
145
  test_files:
148
146
  - spec/cli_spec.rb
149
147
  - spec/debugger_spec.rb
148
+ - spec/openrouter/api_spec.rb
150
149
  - spec/youdao/api_spec.rb