Class: CS::Request
- Inherits:
-
Object
- Object
- CS::Request
- Defined in:
- lib/csapi.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Request
constructor
A new instance of Request.
Constructor Details
#initialize(options = {}) ⇒ Request
Returns a new instance of Request.
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/csapi.rb', line 212 def initialize(={}) if [:username] && [:password] api = CS.new([:username], [:password]) .del(:username) .del(:password) else api = CS::instance if api==nil raise CS::APIError('You have not authenticated with the service or did not provide a :username and :password') end end #pp api.userdata [:subject] = [:subject] || "#{api.userdata['realname']} from #{api.userdata['address']['country']} sent you a new CouchRequest!" [:number] = [:number] || 1 [:arrival_flexible] = [:arrival_flexible] || false [:departure_flexible] = [:departure_flexible] || false [:is_open_couchrequest] = [:is_open_couchrequest] || false [:from] = api.userdata['uid'] [:to] = [:to] || api.userdata['uid'] [:arrival] = Time.at([:arrival]).strftime("%FT%TZ") || (Time.now()+86400).strftime("%FT%TZ") [:departure] = Time.at([:departure]).strftime("%FT%TZ") || (Time.now()+86400*3).strftime("%FT%TZ") [:message] = [:message] || "I'm to lazy to write a proper couch request. HOST ME PLZ?" #puts options.to_json url = "/couchrequests" api.post(url, body:.to_json) #pp response.code #pp response.body end |