Class: SmartlingApi::Clients::Smartling

Inherits:
Object
  • Object
show all
Defined in:
lib/smartling_api/clients/smartling.rb

Overview

Client used to contact smartling api

Constant Summary collapse

SMARTLING_API =
"https://api.smartling.com"

Instance Method Summary collapse

Instance Method Details

#authenticate(url:, body:) ⇒ Hash

Authentication request used to contact Smartling API. Need to pass Smartling id and secret with the request. This is the only request that does not use a token in request.

Parameters:

  • url (String)

    Path corresponding to API get request

  • body (Hash)

    Request body to pass with request

Returns:

  • (Hash)

    Data returned from request

Raises:



43
44
45
46
# File 'lib/smartling_api/clients/smartling.rb', line 43

def authenticate(url:, body:)
  response = connection.post(url, body, {})
  response.body.fetch("response", {}).fetch("data")
end

#download(url:, token:, params:) ⇒ Hash

Download a file from smartling for the given url

Parameters:

  • url (String)

    Path corresponding to API get request

  • token (String)

    OAuth2 token used for accessing endpoint

  • params (Hash)

    Request params to pass with request

Returns:

  • (Hash)

    Response returned from request

Raises:



69
70
71
72
# File 'lib/smartling_api/clients/smartling.rb', line 69

def download(url:, token:, params:)
  response = connection.get(url, params, header(token))
  response.body
end

#get(url:, token:, params: {}) ⇒ Hash

Get request used to contact Smartling API

Parameters:

  • url (String)

    Path corresponding to API get request

  • token (String)

    OAuth2 token used for accessing endpoint

  • params (Hash) (defaults to: {})

    Additional parameters to pass with request

Returns:

  • (Hash)

    Data returned from request

Raises:



18
19
20
21
# File 'lib/smartling_api/clients/smartling.rb', line 18

def get(url:, token:, params: {})
  response = connection.get(url, params, header(token))
  response.body.fetch("response", {}).fetch("data")
end

#post(url:, token:, body:) ⇒ Hash

Post request used to contact Smartling API

Parameters:

  • url (String)

    Path corresponding to API get request

  • token (String)

    OAuth2 token used for accessing endpoint

  • body (Hash)

    Request body to pass with request

Returns:

  • (Hash)

    Response returned from request

Raises:



30
31
32
33
# File 'lib/smartling_api/clients/smartling.rb', line 30

def post(url:, token:, body:)
  response = connection.post(url, body, header(token))
  response.body.fetch("response", {})
end

#upload(url:, token:, body:) ⇒ Hash

Upload a file using a multipart request

Parameters:

  • url (String)

    Path corresponding to API get request

  • token (String)

    OAuth2 token used for accessing endpoint

  • body (Hash)

    Request body to pass with request

Returns:

  • (Hash)

    Response returned from request

Raises:



55
56
57
58
59
60
# File 'lib/smartling_api/clients/smartling.rb', line 55

def upload(url:, token:, body:)
  response = multipart_connection.post(url, body, header(token)).body
  return response if response.is_a?(String)

  response.fetch('response')
end