Sha256: 1bd6b3fa78c3258386108c65ba3d155593187022fa2a17ce8b08444fd3f848a9
Contents?: true
Size: 1.64 KB
Versions: 7
Compression:
Stored size: 1.64 KB
Contents
require 'json' module Bamboo module Client module Http class Json < Abstract class Doc attr_reader :data def self.from(str) new JSON.parse(str) end def initialize(data) @data = data pp @data if $DEBUG end def doc_for(key) Doc.new @data.fetch(key) end def auto_expand(klass, client) key_to_expand = @data.fetch('expand') obj = @data[key_to_expand] case obj when Hash if obj.has_key?('expand') Doc.new(obj).auto_expand(klass, client) else klass.new(obj, client) end when Array obj.map { |e| klass.new(e, client) } else raise TypeError, "don't know how to auto-expand #{obj.inspect}" end end end # Doc attr_reader :cookies def post(uri_or_path, data = {}, cookies = nil) resp = RestClient.post(uri_for(uri_or_path), data.to_json, :accept => :json, :content_type => :json, :cookies => cookies) Doc.from(resp) unless resp.empty? end def get(uri_or_path, params = nil, cookies = nil) uri = uri_for(uri_or_path, params) Doc.from RestClient.get(uri, :accept => :json, :cookies => cookies) end def get_cookies(uri_or_path, params = nil) uri = uri_for(uri_or_path, nil) resp = RestClient.get(uri, :params => params) @cookies = resp.cookies end end # Json end # Http end # Client end # Bamboo
Version data entries
7 entries across 7 versions & 1 rubygems