Class: ProcessOut::ProjectSFTPSettings

Inherits:
Object
  • Object
show all
Defined in:
lib/processout/project_sftp_settings.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, data = {}) ⇒ ProjectSFTPSettings

Initializes the ProjectSFTPSettings object Params:

client

ProcessOut client instance

data

data that can be used to fill the object



38
39
40
41
42
43
44
45
46
# File 'lib/processout/project_sftp_settings.rb', line 38

def initialize(client, data = {})
  @client = client

  self.endpoint = data.fetch(:endpoint, nil)
  self.username = data.fetch(:username, nil)
  self.password = data.fetch(:password, nil)
  self.private_key = data.fetch(:private_key, nil)
  
end

Instance Attribute Details

#endpointObject

Returns the value of attribute endpoint.



11
12
13
# File 'lib/processout/project_sftp_settings.rb', line 11

def endpoint
  @endpoint
end

#passwordObject

Returns the value of attribute password.



13
14
15
# File 'lib/processout/project_sftp_settings.rb', line 13

def password
  @password
end

#private_keyObject

Returns the value of attribute private_key.



14
15
16
# File 'lib/processout/project_sftp_settings.rb', line 14

def private_key
  @private_key
end

#usernameObject

Returns the value of attribute username.



12
13
14
# File 'lib/processout/project_sftp_settings.rb', line 12

def username
  @username
end

Instance Method Details

#delete_sftp_settings(id, options = {}) ⇒ Object

Delete the SFTP settings for the project. Params:

id

ID of the project

options

Hash of options



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/processout/project_sftp_settings.rb', line 130

def delete_sftp_settings(id, options = {})
  self.prefill(options)

  request = Request.new(@client)
  path    = "/projects/" + CGI.escape(id) + "/sftp-settings"
  data    = {

  }

  response = Response.new(request.delete(path, data, options))
  return_values = Array.new
  
  return_values.push(response.success)

  
  return_values[0]
end

#fill_with_data(data) ⇒ Object

Fills the object with data coming from the API Params:

data

Hash of data coming from the API



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/processout/project_sftp_settings.rb', line 66

def fill_with_data(data)
  if data.nil?
    return self
  end
  if data.include? "endpoint"
    self.endpoint = data["endpoint"]
  end
  if data.include? "username"
    self.username = data["username"]
  end
  if data.include? "password"
    self.password = data["password"]
  end
  if data.include? "private_key"
    self.private_key = data["private_key"]
  end
  
  self
end

#new(data = {}) ⇒ Object

Create a new ProjectSFTPSettings using the current client



49
50
51
# File 'lib/processout/project_sftp_settings.rb', line 49

def new(data = {})
  ProjectSFTPSettings.new(@client, data)
end

#prefill(data) ⇒ Object

Prefills the object with the data passed as parameters Params:

data

Hash of data



89
90
91
92
93
94
95
96
97
98
99
# File 'lib/processout/project_sftp_settings.rb', line 89

def prefill(data)
  if data.nil?
    return self
  end
  self.endpoint = data.fetch(:endpoint, self.endpoint)
  self.username = data.fetch(:username, self.username)
  self.password = data.fetch(:password, self.password)
  self.private_key = data.fetch(:private_key, self.private_key)
  
  self
end

#save_sftp_settings(id, options = {}) ⇒ Object

Save the SFTP settings for the project. Params:

id

ID of the project

options

Hash of options



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/processout/project_sftp_settings.rb', line 105

def save_sftp_settings(id, options = {})
  self.prefill(options)

  request = Request.new(@client)
  path    = "/projects/" + CGI.escape(id) + "/sftp-settings"
  data    = {
    "endpoint" => @endpoint, 
    "username" => @username, 
    "password" => @password, 
    "private_key" => @private_key
  }

  response = Response.new(request.put(path, data, options))
  return_values = Array.new
  
  return_values.push(response.success)

  
  return_values[0]
end

#to_json(options) ⇒ Object

Overrides the JSON marshaller to only send the fields we want



54
55
56
57
58
59
60
61
# File 'lib/processout/project_sftp_settings.rb', line 54

def to_json(options)
  {
      "endpoint": self.endpoint,
      "username": self.username,
      "password": self.password,
      "private_key": self.private_key,
  }.to_json
end