Class: Asdawqw::YieldsController

Inherits:
BaseController show all
Defined in:
lib/asdawqw/controllers/yields_controller.rb

Overview

YieldsController

Class Attribute Summary collapse

Attributes inherited from BaseController

#http_call_back, #http_client

Instance Method Summary collapse

Methods inherited from BaseController

#execute_request, #initialize, #validate_parameters, #validate_response

Constructor Details

This class inherits a constructor from Asdawqw::BaseController

Class Attribute Details

.instanceObject

Returns the value of attribute instance.



12
13
14
# File 'lib/asdawqw/controllers/yields_controller.rb', line 12

def instance
  @instance
end

Instance Method Details

#create_ymr(content_type, body) ⇒ Object

This function allows the logged-in user to add yield management rules for the specific product. Yield management rules can affect the final price of the property depending on some special conditions (like the length of stay, early booking, etc.). These rules automate price manipulations, on an inquiry by inquiry basis. When set criteria are met, they help maximize revenue and occupancy. How is the price calculated? The price for a night is calculated based on the basic price and the yield management rules.

  • If no YMR:

price per night = price per night

  • If YMR is set it can Increase/decrease percent or increase/decrease

amount: price per night + amount = per night or price per night - amount = per night The below examples will use the scenario to walk you step by step and explain how the price is calculated based on different YMRs. Let’s say that the basic price per night for 2016 is 100 USD. This function is used also for updating yield. So if you already create a specific yield for some date - and you send a new one - we will update the yield for this date. If you need to delete a specific yield type - you can send an empty list for that type. Important: The maximum allowed end date is 3 years in the future.

Parameters:

Returns:

  • YieldResponse response from the API call



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/asdawqw/controllers/yields_controller.rb', line 79

def create_ymr(content_type,
               body)
  # Prepare query url.
  _path_url = '/yield'
  _query_builder = Configuration.get_base_uri
  _query_builder << _path_url
  _query_url = APIHelper.clean_url _query_builder
  # Prepare headers.
  _headers = {
    'accept' => 'application/json',
    'x-api-key' => Configuration.x_api_key,
    'Content-Type' => content_type
  }
  # Prepare and execute HttpRequest.
  _request = @http_client.post(
    _query_url,
    headers: _headers,
    parameters: body.to_json
  )
  CustomQueryAuth.apply(_request)
  _context = execute_request(_request)
  validate_response(_context)
  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_context.response.raw_body)
  YieldResponse.from_hash(decoded)
end

#get_ymr_list_by_product_id(product_id) ⇒ Object

This function allows the logged in user to get yield management rules list of the specific product.

Parameters:

  • product_id (String)

    Required parameter: ID of the property

Returns:

  • YieldResponse response from the API call



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/asdawqw/controllers/yields_controller.rb', line 23

def get_ymr_list_by_product_id(product_id)
  # Prepare query url.
  _path_url = '/yield/{productId}'
  _path_url = APIHelper.append_url_with_template_parameters(
    _path_url,
    'productId' => product_id
  )
  _query_builder = Configuration.get_base_uri
  _query_builder << _path_url
  _query_url = APIHelper.clean_url _query_builder
  # Prepare headers.
  _headers = {
    'accept' => 'application/json',
    'x-api-key' => Configuration.x_api_key
  }
  # Prepare and execute HttpRequest.
  _request = @http_client.get(
    _query_url,
    headers: _headers
  )
  CustomQueryAuth.apply(_request)
  _context = execute_request(_request)
  validate_response(_context)
  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_context.response.raw_body)
  YieldResponse.from_hash(decoded)
end

#instanceObject



15
16
17
# File 'lib/asdawqw/controllers/yields_controller.rb', line 15

def instance
  self.class.instance
end