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.
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/csapi.rb', line 140 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 |