gemini_api_ruby 1.0.3 → 1.0.5

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: d836f7394ec2c0b798e2441386d427d53c29bee0d23e34e80a2f4303cce3525e
4
- data.tar.gz: d2630739814cb78d6ef9ead4b64a2886c20da7183d7fb8129a5dc8d810b27175
3
+ metadata.gz: 547f60b4912b4a21c4f2faf3a204f437806a6250975994e3baad4d9df9734125
4
+ data.tar.gz: 8e239a07bc4c20a7aeca22afddd3ee2ec2f01bdc6145a437b16cbc7a48cd96e8
5
5
  SHA512:
6
- metadata.gz: 93ca312338b03c83185837ff7787d02a8c85e57231f7014dae64cf73666004bd2f6673801916a65b6a4c1e85034410eb0a1bab8cbc3e5b998610594817b85975
7
- data.tar.gz: '07609c4359bbf298c8254da60e8e9793c02aa83ade2b7ab43b17c6b8c87e6d906ccec3b4ad6a5fec8d66671934a9de0d63bd898184e46fadff487314605514bb'
6
+ metadata.gz: 1b3c3521cbb1b066478f4dcf64a9b023bdf190540f923ccae11cc1390a966f1aab60578251c1b3bb04925755cc65da7de90ee0af1b40e2618a6520e3f1553294
7
+ data.tar.gz: 3b5639015fb507862962f3e508606f75df26adb0ed3addd04088370d7d005ae9260a7cdff5840b52cdcc5b7f5ab7549bbd1c35a9ce7a19b044955722a9deaabe
@@ -1,25 +1,50 @@
1
+ # lib/gemini_api_ruby/client.rb
2
+
1
3
  module GeminiApiRuby
2
4
  class Client
5
+ BASE_URL = "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash".freeze
6
+
3
7
  def initialize(api_key:)
4
8
  @api_key = api_key
5
9
  end
6
10
 
7
- def generate_text(prompt)
8
- response = request(:post, "/v1/generate", { prompt: prompt })
9
- end
10
-
11
- def get_ticker(symbol)
12
- request(:get, "/v1/pubticker/#{symbol}")
13
- end
11
+ def generate_content(prompt)
12
+ endpoint = "#{BASE_URL}:generateContent?key=#{@api_key}"
13
+ payload = {
14
+ contents: [
15
+ {
16
+ parts: [
17
+ { text: prompt }
18
+ ]
19
+ }
20
+ ]
21
+ }
14
22
 
15
- def get_order_book(symbol)
16
- request(:get, "/v1/book/#{symbol}")
23
+ response = request(:post, endpoint, payload)
24
+ parse_response(response)
17
25
  end
18
26
 
19
27
  private
20
28
 
21
- def request(method, endpoint, params = {})
22
- Request.new(api_key: @api_key).send(method, endpoint, params)
29
+ def request(method, endpoint, payload)
30
+ connection = Faraday.new(url: endpoint) do |faraday|
31
+ faraday.request :json
32
+ faraday.response :json, content_type: /\bjson$/
33
+ faraday.adapter Faraday.default_adapter
34
+ end
35
+
36
+ connection.post do |req|
37
+ req.headers["Content-Type"] = "application/json"
38
+ req.body = payload.to_json
39
+ end
40
+ end
41
+
42
+ def parse_response(response)
43
+ if response.success?
44
+ response.body.dig("candidates", 0, "content", "parts", 0, "text") || "No text generated"
45
+ else
46
+ raise GeminiApiRuby::Error, "API request failed: #{response.body['error']['message']}"
47
+ end
23
48
  end
24
49
  end
25
- end
50
+ end
@@ -1,3 +1,3 @@
1
1
  module GeminiApiRuby
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemini_api_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - marcelodeus98