Class: CS::Request

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Request

Returns a new instance of Request.



24
25
26
27
28
29
# File 'lib/csapi/request.rb', line 24

def initialize options={}
  options = @defaults.merge(options)
  options.each do |k,v|
    self.send "@#{k}=", val
  end
end

Instance Attribute Details

#arrivalObject

Returns the value of attribute arrival.



6
7
8
# File 'lib/csapi/request.rb', line 6

def arrival
  @arrival
end

#arrival_flexibleObject

Returns the value of attribute arrival_flexible.



6
7
8
# File 'lib/csapi/request.rb', line 6

def arrival_flexible
  @arrival_flexible
end

#departureObject

Returns the value of attribute departure.



6
7
8
# File 'lib/csapi/request.rb', line 6

def departure
  @departure
end

#departure_flexibleObject

Returns the value of attribute departure_flexible.



6
7
8
# File 'lib/csapi/request.rb', line 6

def departure_flexible
  @departure_flexible
end

#fromObject

Returns the value of attribute from.



6
7
8
# File 'lib/csapi/request.rb', line 6

def from
  @from
end

#is_open_couchrequestObject

Returns the value of attribute is_open_couchrequest.



6
7
8
# File 'lib/csapi/request.rb', line 6

def is_open_couchrequest
  @is_open_couchrequest
end

#messageObject

Returns the value of attribute message.



6
7
8
# File 'lib/csapi/request.rb', line 6

def message
  @message
end

#numberObject

Returns the value of attribute number.



6
7
8
# File 'lib/csapi/request.rb', line 6

def number
  @number
end

#subjectObject

Returns the value of attribute subject.



6
7
8
# File 'lib/csapi/request.rb', line 6

def subject
  @subject
end

#toObject

Returns the value of attribute to.



6
7
8
# File 'lib/csapi/request.rb', line 6

def to
  @to
end

Instance Method Details

#send!Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/csapi/request.rb', line 51

def send!
  raise CS::APIError('You have not authenticated with the service or did not provide a :username and :password') unless CS.instance

  data = self.to_h
  data[:arrival] = data[:arrival].strftime("%FT%TZ")
  data[:departure] = data[:departure].strftime("%FT%TZ")

  me = CS.instance.userdata['uid']
  data[:from] ||= me
  data[:to] ||= me

  CS::HTTP.post('/couchrequests', body: data)

end

#to_hObject



44
45
46
47
48
# File 'lib/csapi/request.rb', line 44

def to_h
  params = {}
  @options.each {|key| params[key.to_sym] = instance_variable_get("@#{key}") }
  params
end