Class: FunTranslations::Client

Inherits:
Object
  • Object
show all
Includes:
Request
Defined in:
lib/fun_translations/client.rb

Overview

FunTranslations API client

Constant Summary

Constants included from Connection

FunTranslations::Connection::BASE_URL

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Request

#post

Methods included from Connection

#connection

Constructor Details

#initialize(token = nil) ⇒ Client

Returns a new instance of Client.



10
11
12
# File 'lib/fun_translations/client.rb', line 10

def initialize(token = nil)
  @token = token
end

Instance Attribute Details

#tokenObject

Returns the value of attribute token.



8
9
10
# File 'lib/fun_translations/client.rb', line 8

def token
  @token
end

Instance Method Details

#translate(endpoint, text, params = {}) ⇒ FunTranslations::Translation

Performs translation

Parameters:

  • endpoint (String, Symbol)
  • text (String)
  • params (Hash) (defaults to: {})

Returns:



19
20
21
22
23
24
25
26
27
# File 'lib/fun_translations/client.rb', line 19

def translate(endpoint, text, params = {})
  FunTranslations::Translation.new(
    post(
      "/translate/#{endpoint}.json",
      self,
      {text: text}.merge(params)
    )
  )
end