Class: Xify::Base::RocketChat
- Inherits:
-
Object
- Object
- Xify::Base::RocketChat
- Defined in:
- lib/xify/base/rocket_chat.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(config) ⇒ RocketChat
constructor
A new instance of RocketChat.
- #request(method, path) {|req| ... } ⇒ Object
Constructor Details
#initialize(config) ⇒ RocketChat
Returns a new instance of RocketChat.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/xify/base/rocket_chat.rb', line 8 def initialize(config) @config = config uri = URI.parse config['uri'] @http = Net::HTTP.new uri.host, uri.port @http.use_ssl = true working_dir = "#{ENV['HOME']}/.xify/RocketChat" Dir.mkdir working_dir rescue Errno::EEXIST @auth_file = "#{working_dir}/#{@config['user']}.json" end |
Instance Method Details
#request(method, path) {|req| ... } ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/xify/base/rocket_chat.rb', line 20 def request(method, path, &block) login unless @auth_data req = Object.const_get("Net::HTTP::#{method.capitalize}").new path, 'X-User-Id' => @auth_data['userId'], 'X-Auth-Token' => @auth_data['authToken'] yield req if block_given? res = @http.request req case res when Net::HTTPUnauthorized relogin request method, path, &block when Net::HTTPSuccess # nothing else $stderr.puts res.body raise "Error on #{method.upcase} #{@config['uri']}#{path}: #{res.code} #{res.}" end res end |