Class: Highrise::CurlHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/highrise/curlhelper.rb

Instance Method Summary collapse

Constructor Details

#initializeCurlHelper



6
7
8
9
# File 'lib/highrise/curlhelper.rb', line 6

def initialize
  @curly = Curly.new
  @curly.http_auth_types = Curl::CURLAUTH_BASIC
end

Instance Method Details

#get_document(url) ⇒ Object



17
18
19
20
# File 'lib/highrise/curlhelper.rb', line 17

def get_document(url)
  @curly.userpwd = get_userpwd_from_url(url)
  @curly.get(url).doc
end

#get_document_from_id(collection_name_and_id) ⇒ Object



22
23
24
# File 'lib/highrise/curlhelper.rb', line 22

def get_document_from_id(collection_name_and_id)
  get_document("#{Highrise::Base.site.to_s}#{collection_name_and_id}")
end

#get_userpwd_from_url(url) ⇒ Object



11
12
13
14
15
# File 'lib/highrise/curlhelper.rb', line 11

def get_userpwd_from_url(url)
  userpwd_from_url_regex = /(http|https):\/\/((?:[\w\.\-\+%!$&'\(\)*\+,;=]+:)*[\w\.\-\+%!$&'\(\)*\+,;=]+)?/
  match = userpwd_from_url_regex.match(url)
  match.captures[1] unless match.nil?
end