Class: LingotekClient::Resource::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/lingotek-client/resource/base.rb

Direct Known Subclasses

Document, Project, TranslationTarget, User, Workflow

Constant Summary collapse

ERRORS =
'errors'
RESULTS =
'results'
FAIL =
'fail'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs) ⇒ Base

Returns a new instance of Base.



10
11
12
# File 'lib/lingotek-client/resource/base.rb', line 10

def initialize(attrs)
  @data = attrs
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



4
5
6
# File 'lib/lingotek-client/resource/base.rb', line 4

def data
  @data
end

Class Method Details

.allObject



14
15
16
17
18
# File 'lib/lingotek-client/resource/base.rb', line 14

def self.all
  action_name = "#{key}s"
  objects = JSON.parse(LingotekClient::API::send("list#{action_name}"))[action_name.downcase]
  objects.map { |obj| self.new obj }
end

.find(id) ⇒ Object



20
21
22
23
24
25
# File 'lib/lingotek-client/resource/base.rb', line 20

def self.find(id)
  action_name = key
  object = self.new(JSON.parse(Lingotek::API::api.send("get#{action_name}", "#{action_name.downcase}Id" => id)))
  raise Exception.new "#{Key} not found" if object.id == nil
  object
end

.keyObject



27
28
29
# File 'lib/lingotek-client/resource/base.rb', line 27

def self.key
  "#{self.name.split("::").last}"
end