Sha256: e84fb2688d6e272fdf160839a9490e8d8abff2d11c118ca6ba820db74b246102
Contents?: true
Size: 949 Bytes
Versions: 3
Compression:
Stored size: 949 Bytes
Contents
require 'json' module BugherdClient module Resources class Base DEFAULT_HEADERS = { content_type: :json, accept: :json } attr_accessor :connection, :options def initialize(conn, opts={}) @connection, @options = conn, opts end def send_request(method="GET", path="", params={}, headers={}) headers = DEFAULT_HEADERS.merge(headers) params.merge!(headers) method_name = method.to_s.downcase self.connection[path].__send__(method_name, params) end [:get, :post, :put, :patch, :delete].each do |method_name| define_method("#{method_name}_request") do |path, params={}| send_request(method_name, path, params) end end def parse_response(response, root_element=nil) if root_element JSON.parse(response)[root_element.to_s] else JSON.parse(response) end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
bugherd_client-0.0.4 | lib/bugherd_client/resources/base.rb |
bugherd_client-0.0.3 | lib/bugherd_client/resources/base.rb |
bugherd_client-0.0.2 | lib/bugherd_client/resources/base.rb |