translate_api 1.0.0

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.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +61 -0
  4. data/lib/translate_api.rb +88 -0
  5. metadata +51 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 90a416412321a8c1a2ae79639bfa9b08fe4136a95382de000e2d85e86dd0f3e2
4
+ data.tar.gz: 3d7fe373bd31d366b7612e90ad5be874559c756ec96b24aa0d57d684424c05bf
5
+ SHA512:
6
+ metadata.gz: 52f6a2ebaa3956c30e8bf3ab74756dad624a68b723a0ef229dfd1222a413a1e64c8761828a0dc3298a0f301cdfda410e9447e6755cb123b9ad38b0f2311196d5
7
+ data.tar.gz: 408ee26e7f326d0376d050cf6a436ef0b5e5cb10d61d02443eeae5e69aa71e7d4167c07e0ca1e3d27172d785e60720cc42505593bcc2227341c09fcbac824f36
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Translate API
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # Translate API - Ruby SDK
2
+
3
+ Official Ruby SDK for [Translate API](https://translate-api.com).
4
+
5
+ ## 🚀 Quick Start (For Beginners)
6
+
7
+ ### Step 1: Get Your API Key
8
+ 1. Go to [https://translate-api.com](https://translate-api.com)
9
+ 2. Click "Login" or "Get Started"
10
+ 3. Create an account (it's free to start!)
11
+ 4. Go to your Dashboard
12
+ 5. Click "Create API Key"
13
+ 6. Copy your API key - you'll need it!
14
+
15
+ ### Step 2: Install the SDK
16
+ Open your terminal and run:
17
+
18
+ ```bash
19
+ gem install translate_api
20
+ ```
21
+
22
+ ### Step 3: Use It!
23
+
24
+ ```ruby
25
+ require 'translate_api'
26
+
27
+ # Replace 'your-api-key' with your actual API key from translate-api.com
28
+ client = TranslateAPI::Client.new('your-api-key')
29
+
30
+ # Translate to one language
31
+ result = client.translate('Hello world', 'es')
32
+ puts result['translations']['es'] # Output: "Hola mundo"
33
+
34
+ # Translate to multiple languages at once
35
+ result = client.translate('Hello world', ['es', 'fr', 'de'])
36
+ puts result['translations']
37
+ # Output: {"es"=>"Hola mundo", "fr"=>"Bonjour le monde", "de"=>"Hallo Welt"}
38
+ ```
39
+
40
+ ## 📖 Full API Reference
41
+
42
+ ### Constructor
43
+ ```ruby
44
+ client = TranslateAPI::Client.new(api_key, base_url: 'https://translate-api.com/v1')
45
+ ```
46
+
47
+ ### translate(text, target_language)
48
+ Translate text to one or more languages.
49
+
50
+ ### translate_batch(items)
51
+ Translate multiple texts at once.
52
+
53
+ ## 🌍 Supported Languages
54
+ Visit [translate-api.com/documentation](https://translate-api.com/documentation) for a full list.
55
+
56
+ ## ❓ Need Help?
57
+ - Documentation: [translate-api.com/documentation](https://translate-api.com/documentation)
58
+ - Support: support@translate-api.com
59
+
60
+ ## 📝 License
61
+ MIT License
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Translate API - Official Ruby SDK
5
+ #
6
+ # Get your API key at: https://translate-api.com
7
+ # Documentation: https://translate-api.com/documentation
8
+ #
9
+
10
+ require 'net/http'
11
+ require 'json'
12
+ require 'uri'
13
+
14
+ module TranslateAPI
15
+ VERSION = "1.0.0"
16
+
17
+ class Client
18
+ attr_reader :api_key, :base_url
19
+
20
+ # Create a new Translate API client
21
+ #
22
+ # @param api_key [String] Your API key from translate-api.com
23
+ # @param base_url [String] Optional custom API URL
24
+ #
25
+ # @example
26
+ # client = TranslateAPI::Client.new('your-api-key')
27
+ #
28
+ def initialize(api_key, base_url: 'https://translate-api.com/v1')
29
+ raise ArgumentError, 'API key is required. Get one at https://translate-api.com' if api_key.nil? || api_key.empty?
30
+
31
+ @api_key = api_key
32
+ @base_url = base_url
33
+ end
34
+
35
+ # Translate text to one or more target languages
36
+ #
37
+ # @param text [String] The text to translate
38
+ # @param target_language [String, Array<String>] Target language code(s)
39
+ # @return [Hash] Translation response with 'translations', 'success', 'characters_used'
40
+ #
41
+ # @example Single language
42
+ # result = client.translate('Hello', 'es')
43
+ # puts result['translations']['es'] # => "Hola"
44
+ #
45
+ # @example Multiple languages
46
+ # result = client.translate('Hello', ['es', 'fr'])
47
+ # puts result['translations'] # => {"es"=>"Hola", "fr"=>"Bonjour"}
48
+ #
49
+ def translate(text, target_language)
50
+ uri = URI.parse("#{@base_url}/translate")
51
+
52
+ http = Net::HTTP.new(uri.host, uri.port)
53
+ http.use_ssl = uri.scheme == 'https'
54
+
55
+ request = Net::HTTP::Post.new(uri.path)
56
+ request['Authorization'] = "Bearer #{@api_key}"
57
+ request['Content-Type'] = 'application/json'
58
+ request.body = {
59
+ text: text,
60
+ target_language: target_language
61
+ }.to_json
62
+
63
+ response = http.request(request)
64
+
65
+ unless response.is_a?(Net::HTTPSuccess)
66
+ error = JSON.parse(response.body) rescue {}
67
+ raise StandardError, error['error'] || "Translation failed (HTTP #{response.code})"
68
+ end
69
+
70
+ JSON.parse(response.body)
71
+ end
72
+
73
+ # Translate multiple texts in batch
74
+ #
75
+ # @param items [Array<Hash>] Array of {text:, target_language:}
76
+ # @return [Array<Hash>] Array of translation responses
77
+ #
78
+ # @example
79
+ # results = client.translate_batch([
80
+ # { text: 'Hello', target_language: 'es' },
81
+ # { text: 'Goodbye', target_language: 'fr' }
82
+ # ])
83
+ #
84
+ def translate_batch(items)
85
+ items.map { |item| translate(item[:text], item[:target_language]) }
86
+ end
87
+ end
88
+ end
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: translate_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Translate API
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-11-30 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Simple and powerful translation API client for Ruby. Translate text to
14
+ 100+ languages with ease.
15
+ email:
16
+ - support@translate-api.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - LICENSE
22
+ - README.md
23
+ - lib/translate_api.rb
24
+ homepage: https://translate-api.com
25
+ licenses:
26
+ - MIT
27
+ metadata:
28
+ homepage_uri: https://translate-api.com
29
+ source_code_uri: https://github.com/Translate-api/translate-api-ruby-sdk
30
+ changelog_uri: https://github.com/Translate-api/translate-api-ruby-sdk/blob/main/CHANGELOG.md
31
+ documentation_uri: https://translate-api.com/documentation
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 2.6.0
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubygems_version: 3.0.3.1
48
+ signing_key:
49
+ specification_version: 4
50
+ summary: Official Ruby SDK for Translate API
51
+ test_files: []