Module: Bluevia::Utils
- Defined in:
- lib/bluevia/utils.rb
Overview
Helper to enable internal features
Defined Under Namespace
Classes: Multipart
Class Method Summary collapse
-
.check_attribute(attribute, message) ⇒ Object
Check if an attribute is not null Raise an exception in case of param.nil?.
- .get_file_mime_type(file) ⇒ Object
-
.object_to_json(object) ⇒ Object
Helper to parse an objet to an equivalent JSON format used to serialize body data.
Class Method Details
.check_attribute(attribute, message) ⇒ Object
Check if an attribute is not null Raise an exception in case of param.nil?
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/bluevia/utils.rb', line 56 def Utils.check_attribute(attribute, ) if attribute.nil? raise ClientError, elsif attribute.instance_of?(String) if attribute.empty? raise ClientError, end else if attribute.respond_to?(:size) if attribute.size == 0 raise ClientError, end end end end |
.get_file_mime_type(file) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/bluevia/utils.rb', line 29 def Utils.get_file_mime_type(file) unless file.nil? Magic.guess_file_mime_type(file) else nil end end |
.object_to_json(object) ⇒ Object
Helper to parse an objet to an equivalent JSON format used to serialize body data
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/bluevia/utils.rb', line 41 def Utils.object_to_json(object) name = object.class.to_s name = name[name.rindex(":")+1..name.size].sub(/Type$/,"").sub(/^SMS/, "sms") name = name[0..0].to_s.downcase << name[1..name.size] result = Hash.new result[name] = _object_to_json(object) return result.to_json #return _object_to_json(object).to_json end |