Module: SearchEndpoints
- Includes:
- Constants, FormData, ResponseFormatter
- Included in:
- Auciel
- Defined in:
- lib/endpoints/search.rb
Overview
search for item and other search-related methods
Constant Summary collapse
- SEARCH_ITEM_BY_TEXT =
{ method: 'get', path: '/search', responder: search_item_by_text, opts: { content_type: 'application/json' } }.values.freeze
Constants included from ApiErrors
ApiErrors::UNEXPECTED_BLACK_DESERT_RESPONSE
Constants included from Constants
Constants::COOKIE, Constants::MARKET_HOT_LIST, Constants::MARKET_SEARCH_LIST, Constants::MARKET_SELL_BUY_INFO, Constants::MARKET_SUB_LIST, Constants::MARKET_WAIT_LIST, Constants::REQUEST_OPTS, Constants::ROOT_URL, Constants::RVT, Constants::WORLD_MARKET_LIST
Class Method Summary collapse
- .respond_if_available(res) ⇒ Object
- .search_item_by_text ⇒ Object
- .send_post_request(uri, data) ⇒ Object
Methods included from ResponseFormatter
format_cat_response, format_hot_response, format_item_response, format_price_list_response, format_search_response, format_waitlist_response, try_error
Methods included from FormData
item_by_cat_data, item_by_id_data, price_list_data, search_item_by_text_data
Class Method Details
.respond_if_available(res) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/endpoints/search.rb', line 31 def self.respond_if_available(res) return res.body if res.body { error: 'invalid response from the black desert api.', response: res }.to_json end |
.search_item_by_text ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/endpoints/search.rb', line 40 def self.search_item_by_text lambda do |req| search_text = req[:params]['q'] uri = URI "#{Constants::ROOT_URL}#{Constants::MARKET_SEARCH_LIST}" form = FormData.search_item_by_text_data search_text res = send_post_request uri, form ResponseFormatter.format_search_response(respond_if_available(res)) end end |
.send_post_request(uri, data) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/endpoints/search.rb', line 20 def self.send_post_request(uri, data) uri_params = data uri_params = URI.encode_www_form(data) if data.is_a? Hash HTTParty.post( uri, body: uri_params, headers: Constants::REQUEST_OPTS[:headers] ) end |