Module: TPEX::Client::Files
- Included in:
- TPEX::Client
- Defined in:
- lib/tpex/client/files.rb
Defined Under Namespace
Classes: File
Constant Summary collapse
- FIELDS =
{ file: {machine_name: "file", required: true}, filename: {machine_name: "filename", required: true}, filesize: {machine_name: "filesize", required: true} }
Instance Method Summary collapse
Instance Method Details
#build_file(options = {}) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/tpex/client/files.rb', line 20 def build_file(={}) required_fields = [] arguments = [] TPEX::Client::Files::FIELDS.each do |key, value| required_fields << key if value[:required] arguments << [key] end required_fields.each do |key| return nil if [key].nil? end return File.new(*arguments); end |
#jsonify_file(file) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/tpex/client/files.rb', line 36 def jsonify_file(file) jsonobject = {} fields = TPEX::Client::Files::FIELDS file.each_pair do |name, value| if !value.nil? jsonobject[fields[name][:machine_name]] = value end end JSON.generate({"file" => jsonobject}) end |
#post_file(file) ⇒ Object
15 16 17 18 |
# File 'lib/tpex/client/files.rb', line 15 def post_file(file) data = jsonify_file(file) response = post("file", data) end |