Class: TranslationCms::Api::Materials::Attachment
- Inherits:
-
Base
- Object
- JsonApiClient::Resource
- Base
- Base
- TranslationCms::Api::Materials::Attachment
show all
- Defined in:
- lib/translation_cms/api/materials/attachment.rb
Constant Summary
collapse
'application/json'
Class Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
all!, custom_scope!, default_attributes, destroy, dummy_resource!, #method_missing_with_translations_will_change, parsed!, path_with_custom_scope, resource_type!, update
Class Attribute Details
.endpoint ⇒ Object
Returns the value of attribute endpoint.
21
22
23
|
# File 'lib/translation_cms/api/materials/attachment.rb', line 21
def endpoint
@endpoint
end
|
Class Method Details
.build_connection ⇒ Object
.endpoint!(endpoint) ⇒ Object
23
24
25
26
27
28
29
30
31
|
# File 'lib/translation_cms/api/materials/attachment.rb', line 23
def endpoint!(endpoint)
if block_given?
yield self
elsif endpoint&.is_a?(Proc)
@endpoint = endpoint.call(self)
else
@endpoint = endpoint.to_s
end
end
|
.path_params(model) ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/translation_cms/api/materials/attachment.rb', line 44
def path_params(model)
type = model.assetable_type.tableize.singularize
return [["#{type}_id", model.guid]].to_h if model.is_a?(RefMaterial)
return {} if model.assetable_id.blank? || model.assetable_id.zero?
[["#{type}_id", model.assetable_id]].to_h
end
|
.upload(model, file) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/translation_cms/api/materials/attachment.rb', line 52
def upload(model, file)
params_hash = path_params(model)
@dynamic_endpoint ||= {}
@dynamic_endpoint[params_hash] ||= File.join(site, path(params_hash))
params = payload(file, model.guid || model.public_token)
response = build_connection.post(@dynamic_endpoint[params_hash]) do |req|
req.body = params
req.['Accept'] = HEADER_ACCEPT
end
handle_data(response).tap { |data| words_count_request(data.public_token, data.payload) }
end
|
Instance Method Details
#uri ⇒ Object
16
17
18
|
# File 'lib/translation_cms/api/materials/attachment.rb', line 16
def uri
@uri ||= URI(url)
end
|