Class: FantasticstayApi::Client

Inherits:
API
  • Object
show all
Defined in:
lib/fantasticstay_api/client.rb

Overview

Main client class that implements communication with the API global_params:

  • include_related_objects: int 0-1 0

  • page: int positive 1

  • per_page: int positive 20

Constant Summary

Constants inherited from API

API::API_ENDPOINT, API::API_TIMEOUT, API::API_TOKEN, API::HTTP_STATUS_MAPPING

Constants included from HttpStatusCodes

HttpStatusCodes::HTTP_BAD_REQUEST_CODE, HttpStatusCodes::HTTP_FORBIDDEN_CODE, HttpStatusCodes::HTTP_NOT_FOUND_CODE, HttpStatusCodes::HTTP_OK_CODE, HttpStatusCodes::HTTP_UNAUTHORIZED_CODE, HttpStatusCodes::HTTP_UNPROCESSABLE_ENTITY_CODE

Constants included from Constants

FantasticstayApi::Constants::ACCEPT, FantasticstayApi::Constants::ACCEPTED_OAUTH_SCOPES, FantasticstayApi::Constants::ACCEPT_CHARSET, FantasticstayApi::Constants::CACHE_CONTROL, FantasticstayApi::Constants::CONTENT_LENGTH, FantasticstayApi::Constants::CONTENT_TYPE, FantasticstayApi::Constants::DATE, FantasticstayApi::Constants::ETAG, FantasticstayApi::Constants::HEADER_LAST, FantasticstayApi::Constants::HEADER_LINK, FantasticstayApi::Constants::HEADER_NEXT, FantasticstayApi::Constants::LOCATION, FantasticstayApi::Constants::META_FIRST, FantasticstayApi::Constants::META_LAST, FantasticstayApi::Constants::META_NEXT, FantasticstayApi::Constants::META_PREV, FantasticstayApi::Constants::META_REL, FantasticstayApi::Constants::OAUTH_SCOPES, FantasticstayApi::Constants::PARAM_INCLUDE_RELATED, FantasticstayApi::Constants::PARAM_PAGE, FantasticstayApi::Constants::PARAM_PER_PAGE, FantasticstayApi::Constants::PARAM_START_PAGE, FantasticstayApi::Constants::RATELIMIT_LIMIT, FantasticstayApi::Constants::RATELIMIT_REMAINING, FantasticstayApi::Constants::RATELIMIT_RESET, FantasticstayApi::Constants::SERVER, FantasticstayApi::Constants::USER_AGENT

Constants included from ApiExceptions

ApiExceptions::APIExceptionError, ApiExceptions::ApiError, ApiExceptions::ApiRequestsQuotaReachedError, ApiExceptions::BadRequestError, ApiExceptions::ForbiddenError, ApiExceptions::NotFoundError, ApiExceptions::UnauthorizedError, ApiExceptions::UnprocessableEntityError

Instance Method Summary collapse

Methods inherited from API

#initialize, #yield_or_eval

Constructor Details

This class inherits a constructor from FantasticstayApi::API

Instance Method Details

#calendar(listing_id, start_date = nil, end_date = nil, filters = {}, global_params = {}) ⇒ Object

FantasticstayApi::Client.new.calendar(38859, ‘2022-01-01’, ‘2022-07-31’)



24
25
26
27
28
29
30
31
32
33
# File 'lib/fantasticstay_api/client.rb', line 24

def calendar(listing_id, start_date = nil, end_date = nil, filters = {}, global_params = {})
  response = request(
    http_method: :get,
    endpoint: 'calendar',
    params: {
      listing_id: listing_id, start_date: start_date, end_date: end_date, filters: filters.to_json
    }.merge(global_params)
  )
  process_response(response)
end

#guest(guest_id, global_params = {}) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'lib/fantasticstay_api/client.rb', line 66

def guest(guest_id, global_params = {})
  response = request(
    http_method: :get,
    endpoint: "guests/#{guest_id}",
    params: global_params,
    cache_ttl: 3600 * 24
  )
  process_response(response)
end

#integrations(global_params = {}) ⇒ Object



76
77
78
79
80
81
82
83
# File 'lib/fantasticstay_api/client.rb', line 76

def integrations(global_params = {})
  response = request(
    http_method: :get,
    endpoint: 'integrations',
    params: global_params
  )
  process_response(response)
end

#listing(listing_id, global_params = {}) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/fantasticstay_api/client.rb', line 35

def listing(listing_id, global_params = {})
  response = request(
    http_method: :get,
    endpoint: "listings/#{listing_id}",
    params: global_params
  )
  process_response(response)
end

#listings(global_params = {}) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/fantasticstay_api/client.rb', line 14

def listings(global_params = {})
  response = request(
    http_method: :get,
    endpoint: 'listings',
    params: global_params
  )
  process_response(response)
end

#reservation(reservation_id, global_params = {}) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/fantasticstay_api/client.rb', line 57

def reservation(reservation_id, global_params = {})
  response = request(
    http_method: :get,
    endpoint: "reservations/#{reservation_id}",
    params: global_params
  )
  process_response(response)
end

#reservations(listing_id, filters = [], sort = { order: 'checkIn', direction: 'desc' }, global_params = {}) ⇒ Object

FantasticstayApi::Client.new.reservations(38859)



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/fantasticstay_api/client.rb', line 45

def reservations(listing_id, filters = [], sort = { order: 'checkIn', direction: 'desc' }, global_params = {})
  response = request(
    http_method: :get,
    endpoint: 'reservations',
    params: {
      listing_id: listing_id, filters: filters.to_json, sort: sort[:order], direction: sort[:direction]
    }.merge!(global_params),
    cache_ttl: 3600 * 24
  )
  process_response(response)
end

#search(query, type = nil, global_params = {}) ⇒ Object

FantasticstayApi::Client.new.search(query)



86
87
88
89
90
91
92
93
94
# File 'lib/fantasticstay_api/client.rb', line 86

def search(query, type = nil, global_params = {})
  response = request(
    http_method: :get,
    endpoint: 'search',
    params: { q: query, type: type }.merge!(global_params),
    cache_ttl: 3600 * 24
  )
  process_response(response)
end