Sha256: 35ba1a0332b3b914a250215dbd88b27e335135235c3e3f8ce48d44b8fce16ef9

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

require 'faraday'
require 'faraday_middleware'

module Mattermost
	module Request

		def get(path, options = {}, &block)
			puts "get #{path}, #{options}"
			connection.send(:get) do |request|
				request.url api(path), options
			end
		end

		def post(path, options = {}, &block)
			connection.send(:post) do |request|
				request.path = api(path)
				request.body = options[:body] if options.key? :body
			end
		end

		def put(path, options = {}, &block)
			connection.send(:put) do |request|
				request.path = api(path)
				request.body = options[:body] if options.key? :body
			end
		end

		def delete(path, options = {}, &block)
			connection.send(:delete) do |request|
				request.path = api(path)
				request.body = options[:body] if options.key? :body
			end
		end

		private

		def connection
			Faraday::Connection.new({
				:headers => self.headers,
				:url => server
			}) do |connection|
				connection.response :json
				connection.adapter :httpclient
			end
		end

		def api(path)
			"/api/v4#{path}"
		end

	end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mattermost-api4-ruby-0.0.8 lib/mattermost/request.rb