Sha256: eb10e4967c59e7f78cccd96b4daf31bd6d21e7a2e73491cc4b8e7ed03dd06c67

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

module TimeTree
  class BaseClient
    API_HOST = 'https://timetreeapis.com'
    # @return [Integer]
    attr_reader :ratelimit_limit
    # @return [Integer]
    attr_reader :ratelimit_remaining
    # @return [Time]
    attr_reader :ratelimit_reset_at

    #
    # update ratelimit properties
    #
    # @param res [Faraday::Response]
    # apis http response.
    def update_ratelimit(res)
      limit = res.headers['x-ratelimit-limit']
      remaining = res.headers['x-ratelimit-remaining']
      reset = res.headers['x-ratelimit-reset']
      @ratelimit_limit = limit.to_i if limit
      @ratelimit_remaining = remaining.to_i if remaining
      @ratelimit_reset_at = Time.at reset.to_i if reset
    end

  private

    def check_event_id(value)
      check_required_property(value, 'event_id')
    end

    def check_required_property(value, name)
      err = Error.new "#{name} is required."
      raise err if value.nil?
      raise err if value.to_s.empty?

      true
    end

    def to_model(data, included: nil)
      TimeTree::BaseModel.to_model data, client: self, included: included
    end

    def relationships_params(relationships, default)
      params = {}
      relationships ||= default
      params[:include] = relationships.join ',' if relationships.is_a? Array
      params
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
timetree-1.0.0 lib/timetree/base_client.rb