class BookingSync::API::Relation

Attributes

client[R]
href_template[R]
method[R]
name[R]

Public Class Methods

new(client, name, href, method = nil) click to toggle source

A Relation represents an available next action for a resource.

@param client [BookingSync::API::Client] The client that made the HTTP

request.

@param name [Symbol] The name of the relation. @param href [String] The String URL of the location of the next action. @param method [Symbol] The Symbol HTTP method. Default: :get

# File lib/bookingsync/api/relation.rb, line 45
def initialize(client, name, href, method = nil)
  @client = client
  @name = name.to_sym
  @href = href
  @href_template = ::Addressable::Template.new(href.to_s)
  @method = (method || :get).to_sym
end

Public Instance Methods

call(data = {}, options = {}) click to toggle source

Make an API request with the curent Relation.

@param data [Hash|String] The Optional Hash or Resource body to be sent.

:get or :head requests can have no body, so this can be the options Hash
instead.

@param options [Hash] A Hash of option to configure the API request. @option options [Hash] headers: A Hash of API headers to set. @option options [Hash] query: Hash of URL query params to set. @option options [Symbol] method: Symbol HTTP method. @return [BookingSync::API::Response]

# File lib/bookingsync/api/relation.rb, line 85
def call(data = {}, options = {})
  m = options.delete(:method)
  client.call m || method, href_template, data, options
end
get(data = {}) click to toggle source

Make an API request with the curent Relation using GET.

@param options [Hash] Options to configure the API request. @option options [Hash] headers: Hash of API headers to set. @option options [Hash] query: Hash of URL query params to set. @option options [Symbol] method: Symbol HTTP method. @return [BookingSync::API::Response] A response

# File lib/bookingsync/api/relation.rb, line 60
def get(data = {})
  call data, method: :get
end
href(options = {}) click to toggle source

@param options [Hash] Params to be included in expanded URL @return [String] expanded URL

# File lib/bookingsync/api/relation.rb, line 95
def href(options = {})
  return @href if @href_template.nil?
  @href_template.expand(options.to_h).to_s
end
post(data = {}) click to toggle source

Make an API request with the curent Relation using POST.

@param options [Hash] Options to configure the API request. @option options [Hash] headers: Hash of API headers to set. @option options [Hash] query: Hash of URL query params to set. @option options [Symbol] method: Symbol HTTP method. @return [BookingSync::API::Response] A response

# File lib/bookingsync/api/relation.rb, line 71
def post(data = {})
  call data, method: :post
end