Class: PolyLingo::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/polylingo/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, base_url: nil, timeout: 120) ⇒ Client

Returns a new instance of Client.

Parameters:

  • api_key (String)

    API key (required)

  • base_url (String, nil) (defaults to: nil)

    API base URL (default: production)

  • timeout (Numeric) (defaults to: 120)

    request open/read timeout in seconds (default: 120)



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/polylingo/client.rb', line 10

def initialize(api_key:, base_url: nil, timeout: 120)
  if api_key.nil? || api_key.to_s.empty?
    raise ArgumentError, "PolyLingo: api_key is required"
  end

  @api_key = api_key
  resolved_base = base_url.nil? || base_url.to_s.empty? ? HttpClient::DEFAULT_BASE_URL : base_url
  @http = HttpClient.new(
    api_key: @api_key,
    base_url: resolved_base.chomp("/"),
    timeout: timeout
  )
  @jobs = Resources::Jobs.new(@http)
end

Instance Attribute Details

#jobsObject (readonly)

Returns the value of attribute jobs.



5
6
7
# File 'lib/polylingo/client.rb', line 5

def jobs
  @jobs
end

Instance Method Details

#batch(items:, targets:, source: nil, model: nil) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/polylingo/client.rb', line 48

def batch(items:, targets:, source: nil, model: nil)
  Resources::Batch.call(
    @http,
    items: items,
    targets: targets,
    source: source,
    model: model
  )
end

#healthObject



25
26
27
# File 'lib/polylingo/client.rb', line 25

def health
  Resources::Health.call(@http)
end

#languagesObject



29
30
31
# File 'lib/polylingo/client.rb', line 29

def languages
  Resources::Languages.call(@http)
end

#translate(content:, targets:, format: nil, source: nil, model: nil) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/polylingo/client.rb', line 37

def translate(content:, targets:, format: nil, source: nil, model: nil)
  Resources::Translate.call(
    @http,
    content: content,
    targets: targets,
    format: format,
    source: source,
    model: model
  )
end

#usageObject



33
34
35
# File 'lib/polylingo/client.rb', line 33

def usage
  Resources::Usage.call(@http)
end