Class: YACCL::Services::Internal::BrowserBindingService::Basement
- Inherits:
-
Object
- Object
- YACCL::Services::Internal::BrowserBindingService::Basement
- Defined in:
- lib/yaccl/services/internal/browser_binding_service.rb
Constant Summary collapse
- @@get_cache =
SimpleCache::MemoryCache.new
Instance Method Summary collapse
- #get(params) ⇒ Object
-
#initialize(user, pass) ⇒ Basement
constructor
A new instance of Basement.
- #multipart_post(url, options, headers) ⇒ Object
- #post(params) ⇒ Object
Constructor Details
#initialize(user, pass) ⇒ Basement
Returns a new instance of Basement.
132 133 134 135 |
# File 'lib/yaccl/services/internal/browser_binding_service.rb', line 132 def initialize(user, pass) @username = user @password = pass end |
Instance Method Details
#get(params) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/yaccl/services/internal/browser_binding_service.rb', line 137 def get(params) if @@get_cache[params.to_s].nil? request = Typhoeus::Request.new( params[:url], userpwd: "#{@username}:#{@password}", method: :get, body: params[:body], params: params[:query], headers: params[:headers], followlocation: true ) request.run @@get_cache[params.to_s] = request.run end @@get_cache[params.to_s] end |
#multipart_post(url, options, headers) ⇒ Object
170 171 172 173 174 175 176 177 178 179 |
# File 'lib/yaccl/services/internal/browser_binding_service.rb', line 170 def multipart_post(url, , headers) @@get_cache.clear url = URI.parse(url) req = Net::HTTP::Post::Multipart.new(url.path, ) headers.each {|key, value| req[key] = value } req.basic_auth @username, @password unless @username.nil? opts = url.scheme == 'https' ? { use_ssl: true , verify_mode: OpenSSL::SSL::VERIFY_NONE } : {} Net::HTTP.start(url.host, url.port, opts) { |http| http.request(req) } end |
#post(params) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/yaccl/services/internal/browser_binding_service.rb', line 155 def post(params) # reset on any update @@get_cache.clear request = Typhoeus::Request.new( params[:url], userpwd: "#{@username}:#{@password}", method: :post, body: params[:body], params: params[:query], headers: params[:headers] ) request.run end |