Class: WebDAV
- Inherits:
-
Object
- Object
- WebDAV
- Defined in:
- lib/gooddata_marketo/helpers/webdav.rb
Instance Attribute Summary collapse
-
#password ⇒ Object
Returns the value of attribute password.
-
#project ⇒ Object
Returns the value of attribute project.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #delete(file) ⇒ Object
- #download(file) ⇒ Object
- #exists?(file) ⇒ Boolean (also: #include?)
- #get_marketo_etl_controller ⇒ Object
-
#initialize(config = {}) ⇒ WebDAV
constructor
A new instance of WebDAV.
- #set_marketo_etl_controller ⇒ Object
- #test ⇒ Object
- #upload(file) ⇒ Object
Constructor Details
#initialize(config = {}) ⇒ WebDAV
Returns a new instance of WebDAV.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/gooddata_marketo/helpers/webdav.rb', line 10 def initialize config = {} self.user = config[:user] self.password = config[:pass] || config[:password] self.project = config[:project] || config[:pid] raise 'ERROR! :user, :password, & :project must be passed in the configuration.' unless self.user && self.project && self.password @uri = URI.parse("https://secure-di.gooddata.com/project-uploads/") end |
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
8 9 10 |
# File 'lib/gooddata_marketo/helpers/webdav.rb', line 8 def password @password end |
#project ⇒ Object
Returns the value of attribute project.
6 7 8 |
# File 'lib/gooddata_marketo/helpers/webdav.rb', line 6 def project @project end |
#user ⇒ Object
Returns the value of attribute user.
7 8 9 |
# File 'lib/gooddata_marketo/helpers/webdav.rb', line 7 def user @user end |
Instance Method Details
#delete(file) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/gooddata_marketo/helpers/webdav.rb', line 99 def delete file Net::HTTP.start(@uri.host, @uri.port, :use_ssl => @uri.scheme == 'https') do |http| request = Net::HTTP::Delete.new @uri+file request.basic_auth self.user, self.password response = http.request request if response.is_a?(Net::HTTPSuccess) response.body else false end end end |
#download(file) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/gooddata_marketo/helpers/webdav.rb', line 51 def download file Net::HTTP.start(@uri.host, @uri.port, :use_ssl => @uri.scheme == 'https') do |http| request = Net::HTTP::Get.new @uri+file request.basic_auth self.user, self.password response = http.request request if response.is_a?(Net::HTTPSuccess) response.body else false end end end |
#exists?(file) ⇒ Boolean Also known as: include?
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/gooddata_marketo/helpers/webdav.rb', line 75 def exists? file Net::HTTP.start(@uri.host, @uri.port, :use_ssl => @uri.scheme == 'https') do |http| request = Net::HTTP::Get.new "#{@uri.to_s}#{file}/" request.basic_auth self.user, self.password response = http.request request if response.is_a?(Net::HTTPSuccess) if response.code == "200" true else false end else false end end end |
#get_marketo_etl_controller ⇒ Object
67 68 69 |
# File 'lib/gooddata_marketo/helpers/webdav.rb', line 67 def get_marketo_etl_controller self.download('marketo_connector.json') end |
#set_marketo_etl_controller ⇒ Object
71 72 73 |
# File 'lib/gooddata_marketo/helpers/webdav.rb', line 71 def set_marketo_etl_controller self.upload('marketo_connector.json') end |
#test ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/gooddata_marketo/helpers/webdav.rb', line 22 def test begin test = self.exists? 'file' puts "#{Time.now} => SETUP: Connect to GoodData WebDAV...success!" if GoodDataMarketo.logging true rescue false end end |
#upload(file) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/gooddata_marketo/helpers/webdav.rb', line 32 def upload file http = Net::HTTP.new(@uri.host, @uri.port) http.use_ssl = @uri.scheme == 'https' request = Net::HTTP::Put.new("#{@uri.request_uri}/#{file}") request.basic_auth self.user, self.password request.body_stream = File.open(file) request["Content-Type"] = "multipart/form-data" request.add_field('Content-Length', File.size(file)) response = http.request(request) if response.is_a?(Net::HTTPSuccess) response else false end end |