Sha256: cad32d7a1237611061013999ada49f52de8e38e0777e0672118f5d3d542605bc
Contents?: true
Size: 933 Bytes
Versions: 3
Compression:
Stored size: 933 Bytes
Contents
# api = JoshuaRemote.new 'http://localhost:4567/api', debug: true # api.company(1).index # api.call 'company/1/index' # api.call [:company, 1, :index] # api.call :company, 1, :index # api.success? # api.response require 'awesome_print' require 'http' class JoshuaRemote attr_reader :response def initialize root, debug: false @debug = debug @root = root @path = [] end def method_missing name, *args @path.push name return call if @path[1] @path.push args.first if args.first self end def call *args path = if args.first args = args.flatten args[1] ? args.join('/') : args.first else '/' + @path.join('/') end path = [@root, path].join('/') puts 'Joshua: %s' % path if @debug @path = [] @response = JSON.parse HTTP.get(path).to_s end def success? @response['success'] == true end def error? !success? end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
joshua-0.2.2 | ./lib/misc/ruby_client.rb |
joshua-0.2.1 | ./lib/misc/ruby_client.rb |
joshua-0.1.0 | ./lib/misc/ruby_client.rb |