Class: TranslationEngine::Connection

Inherits:
Object
  • Object
show all
Defined in:
app/models/translation_engine/connection.rb

Constant Summary collapse

NotFound =
Class.new(Exception)

Instance Method Summary collapse

Instance Method Details

#get_release(version) ⇒ Object

Raises:



36
37
38
39
40
41
42
43
44
45
# File 'app/models/translation_engine/connection.rb', line 36

def get_release(version)
  response = connection.get do |req|
    req.url "/api/v1/releases/#{version}.yaml"
    req.headers['Authorization'] = api_token
  end

  raise NotFound, "Release #{version} Not found" if response.status != 200

  response
end

#get_releasesObject



25
26
27
28
29
30
31
32
33
34
# File 'app/models/translation_engine/connection.rb', line 25

def get_releases
  response = connection.get do |req|
    req.url '/api/v1/releases.json'
    req.headers['Authorization'] = api_token
  end

  JSON.parse(response.body).with_indifferent_access[:releases].map do |args|
    TranslationEngine::Release.new args
  end
end

#get_translationsObject



47
48
49
50
51
52
# File 'app/models/translation_engine/connection.rb', line 47

def get_translations
  connection.get do |req|
    req.url '/api/v1/translations.yaml'
    req.headers['Authorization'] = api_token
  end
end

#get_translations_headObject



54
55
56
57
58
59
# File 'app/models/translation_engine/connection.rb', line 54

def get_translations_head
  connection.head do |req|
    req.url '/api/v1/translations.yaml'
    req.headers['Authorization'] = api_token
  end
end

#send_images(data) ⇒ Object



7
8
9
10
11
12
13
14
# File 'app/models/translation_engine/connection.rb', line 7

def send_images(data)
  connection.post do |req|
    req.url '/api/v1/images'
    req.headers['Content-Type']  = 'application/json'
    req.headers['Authorization'] = api_token
    req.body = data.to_json
  end
end

#send_translations(data) ⇒ Object



16
17
18
19
20
21
22
23
# File 'app/models/translation_engine/connection.rb', line 16

def send_translations(data)
  connection.post do |req|
    req.url '/api/v1/translations'
    req.headers['Content-Type']  = 'application/json'
    req.headers['Authorization'] = api_token
    req.body = data.to_json
  end
end