Sha256: ea5c0d6be9a4d89ade92ce62ccdfeeaa1a1f3f605000512164b84a102734d677

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

class Ragoon::Services
  SERVICE_LOCATIONS = {
    schedule:     '/cbpapi/schedule/api?',
    notification: '/cbpapi/notification/api?',
    workflow:     '/cbpapi/workflow/api?',
  }.freeze

  attr_reader :client, :action_type

  def initialize(options = Ragoon.default_options)
    @options = options
    @action_type = self.class.name.split('::').pop.downcase.to_sym
    @client = Ragoon::Client.new(self.endpoint, options)
  end

  def endpoint
    "#{base_endpoint}#{SERVICE_LOCATIONS[action_type]}"
  end

  def self.start_and_end(date = Date.today)
    {
      start: date.to_time.utc,
      end:   ((date + 1).to_time - 1).utc,
    }
  end

  def garoon_endpoint
    base_endpoint
  end

  private

  def base_endpoint
    endpoint = URI(@options[:endpoint])
    "#{endpoint.scheme}://#{endpoint.host}#{endpoint.path}"
  end

  def parse_time(str)
    return nil if str.nil?
    Time.parse(str).localtime
  end

  def to_date_str(time)
    return nil if time.nil?
    time.localtime.strftime('%F')
  end

  def to_datetime_str(time)
    return nil if time.nil?
    time.utc.strftime('%FT%TZ')
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ragoon-0.8.1 lib/ragoon/services.rb
ragoon-0.8.0 lib/ragoon/services.rb