lib/freshbooks/oauth2_rest_client.rb
def create
      response = @client.post @parent.path, serialized, :expected_response => 200
      if @client.media_type.downcase == "application/json"
        @key = nil
        json_data = JSON.parse(response.body)
        if json_data.key?("response") && json_data["response"].key?("result")
          @key, json_data = json_data["response"]["result"].find {|k, v| v.is_a?(Array) || v.is_a?(Hash)}#[1]
        elsif json_data.key?("response")
          json_data = json_data["response"]
        end
        @data, @document, @path = response.body, nil, @parent.send(:path_from, json_data["id"])
      else
        @data, @document, @path = response.body, nil, @parent.send(:path_for, response['Location'])
      end
      @parent.refresh
      true
    end
# replace these REST::Resource methods so they support XML or JSON
replace these REST::Resource methods so they support XML or JSON
replace these REST :: Resource methods so they support XML or JSON
def create
      response = @client.post @parent.path, serialized, :expected_response => 200
      if @client.media_type.downcase == "application/json"
        @key = nil
        json_data = JSON.parse(response.body)
        if json_data.key?("response") && json_data["response"].key?("result")
          @key, json_data = json_data["response"]["result"].find {|k, v| v.is_a?(Array) || v.is_a?(Hash)}
        elsif json_data.key?("response")
          json_data = json_data["response"]
        end
        @data, @document, @path = response.body, nil, @parent.send(:path_from, json_data["id"])
      else
        @data, @document, @path = response.body, nil, @parent.send(:path_for, response['Location'])
      end
      @parent.refresh
      true
    end
def create response = @client . post @parent . path , serialized , :expected_response => 200 if @client . media_type . downcase == "application/json" @key = nil json_data = JSON . parse ( response . body ) if json_data . key? ( "response" ) && json_data [ "response" ] . key? ( "result" ) @key , json_data = json_data [ "response" ] [ "result" ] . find { | k , v | v . is_a? ( Array ) || v . is_a? ( Hash ) } elsif json_data . key? ( "response" ) json_data = json_data [ "response" ] end @data , @document , @path = response . body , nil , @parent . send ( :path_from , json_data [ "id" ] ) else @data , @document , @path = response . body , nil , @parent . send ( :path_for , response [ 'Location' ] ) end @parent . refresh true end
replace these REST::Resource methods so they support XML or JSON
replace these REST :: Resource methods so they support XML or JSON
#[1]