Class: TranslationIO::API::Segments
- Inherits:
-
Object
- Object
- TranslationIO::API::Segments
- Defined in:
- lib/translation_io/api/segments.rb
Overview
Client for segment endpoints
Instance Method Summary collapse
-
#add_tag(segment_id, name:) ⇒ TranslationIO::API::Response
Add a tag to a segment.
-
#create(target_language, type:, key:, source:) ⇒ TranslationIO::API::Response
Create a segment.
-
#initialize(api_key:) ⇒ Segments
constructor
A new instance of Segments.
-
#list(target_language, options = {}) ⇒ TranslationIO::API::Response
List segments for target language.
-
#remove_tag(segment_id, name:) ⇒ TranslationIO::API::Response
Remove a tag from a segment.
Constructor Details
#initialize(api_key:) ⇒ Segments
Returns a new instance of Segments.
7 8 9 10 |
# File 'lib/translation_io/api/segments.rb', line 7 def initialize(api_key:) @api_key = api_key @base_url = "https://translation.io/api/v1/segments" end |
Instance Method Details
#add_tag(segment_id, name:) ⇒ TranslationIO::API::Response
Note:
a unique color will be attributed to the tag. If this tag already exists in the project, the same color will be reused.
Note:
if this tag is already added to the segment, nothing will change and no error will be triggered.
Add a tag to a segment
73 74 75 |
# File 'lib/translation_io/api/segments.rb', line 73 def add_tag(segment_id, name:) request.post(@base_url + "/#{segment_id}/add_tag", { name: name }) end |
#create(target_language, type:, key:, source:) ⇒ TranslationIO::API::Response
Create a segment
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/translation_io/api/segments.rb', line 49 def create(target_language, type:, key:, source:) request.post( @base_url, { target_language: target_language, type: type, key: key, source: source } ) end |
#list(target_language, options = {}) ⇒ TranslationIO::API::Response
List segments for target language
30 31 32 33 34 35 |
# File 'lib/translation_io/api/segments.rb', line 30 def list(target_language, = {}) request.get( @base_url, .merge("target_language": target_language) ) end |
#remove_tag(segment_id, name:) ⇒ TranslationIO::API::Response
Note:
if this tag doesn’t exist or is not linked to this segment, nothing will change and no error will be triggered.
Remove a tag from a segment
88 89 90 |
# File 'lib/translation_io/api/segments.rb', line 88 def remove_tag(segment_id, name:) request.post(@base_url + "/#{segment_id}/remove_tag", { name: name }) end |