Class: Hungrytable::RestaurantSlotlock

Inherits:
Object
  • Object
show all
Includes:
RequestExtensions
Defined in:
lib/hungrytable/restaurant_slotlock.rb

Overview

Locks a reservation time slot before making a reservation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(restaurant_search, requester = PostRequest) ⇒ RestaurantSlotlock

Returns a new instance of RestaurantSlotlock.



10
11
12
13
14
# File 'lib/hungrytable/restaurant_slotlock.rb', line 10

def initialize(restaurant_search, requester = PostRequest)
  @restaurant_search = restaurant_search
  @requester = requester
  validate_search_has_results
end

Instance Attribute Details

#restaurant_searchObject (readonly)

Returns the value of attribute restaurant_search.



8
9
10
# File 'lib/hungrytable/restaurant_slotlock.rb', line 8

def restaurant_search
  @restaurant_search
end

Instance Method Details

#errorsString?

Get error messages if slotlock failed

Returns:

  • (String, nil)

    error message or nil



24
25
26
# File 'lib/hungrytable/restaurant_slotlock.rb', line 24

def errors
  details['ns:ErrorMessage']
end

#paramsHash

Parameters to send with the slotlock request

Returns:

  • (Hash)

    request parameters



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

def params
  {
    'RID' => restaurant.id,
    'datetime' => restaurant_search.ideal_time,
    'partysize' => restaurant_search.party_size,
    'timesecurityID' => restaurant_search.ideal_security_id,
    'resultskey' => restaurant_search.results_key
  }
end

#slotlock_idString?

Get the slotlock ID needed for making a reservation

Returns:

  • (String, nil)

    slotlock ID or nil if unsuccessful



30
31
32
33
34
# File 'lib/hungrytable/restaurant_slotlock.rb', line 30

def slotlock_id
  return nil unless successful?

  details['ns:SlotLockID']
end

#successful?Boolean

Check if the slotlock was successful

Returns:

  • (Boolean)

    true if no errors



18
19
20
# File 'lib/hungrytable/restaurant_slotlock.rb', line 18

def successful?
  details['ns:ErrorID'].to_s == '0'
end