Class: Presss

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

Defined Under Namespace

Classes: Authorization, HTTP

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configObject

Returns the value of attribute config.



183
184
185
# File 'lib/presss.rb', line 183

def config
  @config
end

.loggerObject

Returns the value of attribute logger.



184
185
186
# File 'lib/presss.rb', line 184

def logger
  @logger
end

Class Method Details

.get(path) ⇒ Object

Get a object with a certain key.



189
190
191
192
193
194
195
196
197
198
199
# File 'lib/presss.rb', line 189

def self.get(path)
  request = Presss::HTTP.new(config)
  log("Trying to GET #{path}")
  response = request.get(path)
  if response.success?
    log("Got response: #{response.status_code}")
    response.body
  else
    nil
  end
end

.log(message) ⇒ Object

Logs to the configured logger if a logger was configured.



213
214
215
216
217
# File 'lib/presss.rb', line 213

def self.log(message)
  if logger
    logger.info('[Presss] ' + message)
  end
end

.put(path, file, content_type = 'application/x-download') ⇒ Object

Puts an object with a key using a file or string. Optionally pass in the content-type if you want to set a specific one.



203
204
205
206
207
208
209
210
# File 'lib/presss.rb', line 203

def self.put(path, file, content_type='application/x-download')
  request = Presss::HTTP.new(config)
  log("Trying to PUT #{path}")
  response = request.put(path, file, content_type)
  log("Got response: #{response.status_code}")
  log(response.body) unless response.success?
  response.success?
end