Class: Phocoder::Base
- Inherits:
-
Object
- Object
- Phocoder::Base
- Defined in:
- lib/phocoder/base.rb
Class Method Summary collapse
- .api_key ⇒ Object
- .base_url ⇒ Object
- .decode(content, format = nil) ⇒ Object
- .encode(content, format = nil) ⇒ Object
Instance Method Summary collapse
Class Method Details
.base_url ⇒ Object
8 9 10 |
# File 'lib/phocoder/base.rb', line 8 def self.base_url Phocoder.base_url end |
.decode(content, format = nil) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/phocoder/base.rb', line 30 def self.decode(content, format=nil) begin if content.is_a?(String) if format.to_s == 'xml' Hash.from_xml(content) else ActiveSupport::JSON.decode(content) end else content end rescue Exception => e content end end |
.encode(content, format = nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/phocoder/base.rb', line 12 def self.encode(content, format=nil) if content.is_a?(String) content elsif format.to_s == 'xml' if content.is_a?(Hash) && content.keys.size == 1 content[content.keys.first].to_xml(:root => content.keys.first) else content.to_xml end else content.to_json end end |
Instance Method Details
#decode(content, format = nil) ⇒ Object
46 47 48 |
# File 'lib/phocoder/base.rb', line 46 def decode(content, format=nil) self.class.decode(content, format) end |
#encode(content, format = nil) ⇒ Object
26 27 28 |
# File 'lib/phocoder/base.rb', line 26 def encode(content, format=nil) self.class.encode(content, format) end |