Class: Watobo::HTTPData::JSONData
- Defined in:
- lib/watobo/http/data/json.rb
Instance Method Summary collapse
- #has_parm?(parm_name) ⇒ Boolean
-
#initialize(root) ⇒ JSONData
constructor
A new instance of JSONData.
- #parameters(&block) ⇒ Object
- #set(parm) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(root) ⇒ JSONData
Returns a new instance of JSONData.
41 42 43 44 |
# File 'lib/watobo/http/data/json.rb', line 41 def initialize(root) super root end |
Instance Method Details
#has_parm?(parm_name) ⇒ Boolean
17 18 19 20 21 |
# File 'lib/watobo/http/data/json.rb', line 17 def has_parm?(parm_name) parms = JSON.parse(@root.body.to_s) return true if parms.has_key? parm_name false end |
#parameters(&block) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/watobo/http/data/json.rb', line 23 def parameters(&block) parms = [] json_str = @root.body.to_s return parms if json_str.empty? begin JSON.parse(json_str).each do |k,v| val = v.is_a?(String) ? v : v.to_s parms << Watobo::JSONParameter.new( :name => k, :value => val ) end rescue => bang puts "! could not parse JSON parameters !" puts @root.headers puts json_str.gsub(/[^[:print:]]/, '.') end parms end |
#set(parm) ⇒ Object
11 12 13 14 15 |
# File 'lib/watobo/http/data/json.rb', line 11 def set(parm) parms = JSON.parse(@root.body.to_s) parms[parm.name] = parm.value @root.set_body parms.to_json end |
#to_s ⇒ Object
7 8 9 |
# File 'lib/watobo/http/data/json.rb', line 7 def to_s s = @root.body.nil? ? "" : @root.body end |