class Transifex::ResourceComponents::Content
Attributes
project_slug[RW]
resource_slug[RW]
Public Class Methods
new(project_slug, resource_slug)
click to toggle source
# File lib/tx-ruby/resource_components/content.rb, line 9 def initialize(project_slug, resource_slug) raise MissingParametersError.new(["project_slug"]) if project_slug.nil? raise MissingParametersError.new(["resource_slug"]) if resource_slug.nil? @project_slug = project_slug @resource_slug = resource_slug end
parents()
click to toggle source
# File lib/tx-ruby/resource_components/content.rb, line 15 def self.parents [:project, :resource] end
Public Instance Methods
fetch_with_file(path_to_file = nil)
click to toggle source
# File lib/tx-ruby/resource_components/content.rb, line 18 def fetch_with_file(path_to_file = nil) raise MissingParametersError.new(["path_to_file"]) if path_to_file.nil? options = {:file => true} file_body = fetch(options) write_to_file(path_to_file, file_body) end
update(params = {}, options = {})
click to toggle source
Calls superclass method
# File lib/tx-ruby/resource_components/content.rb, line 25 def update(params = {}, options = {}) resource_i18n_type = Transifex::Resource.new(@project_slug, @resource_slug).fetch raise Transifex::Error.new("You must use the mimetype #{resource_i18n_type["i18n_type"]} to upload a new resource file") if !check_i18n_type_concordance?(resource_i18n_type["i18n_type"], params[:i18n_type]) super end
Private Instance Methods
check_i18n_type_concordance?(resource_i18n_type, param)
click to toggle source
# File lib/tx-ruby/resource_components/content.rb, line 44 def check_i18n_type_concordance?(resource_i18n_type, param) case resource_i18n_type when "YML" param == "YML" || param == "YAML" else param == resource_i18n_type end end
write_to_file(path_to_file, content)
click to toggle source
# File lib/tx-ruby/resource_components/content.rb, line 33 def write_to_file(path_to_file, content) case File.extname(path_to_file) when ".yml" # Needed to correct carriage return problems when writing the Api response in the file d = YAML::load(content) File.open(path_to_file, "w") { |file| file.write d.to_yaml } else File.open(path_to_file, "w") { |file| file.write content } end end