Sha256: 11ae85bf6cdf877d3122f97f94b5f5f0ad24166c1e8d62ffe6d2c824135ffec3

Contents?: true

Size: 1.43 KB

Versions: 2

Compression:

Stored size: 1.43 KB

Contents

module Masheri
  class InvalidDateRange < Exception
    def initialize(start_date, end_date)
      days = ((end_date - start_date) / 1.day).ceil

      super("Your start_date and end_date are #{days} days apart. Mashery's API does not like date ranges that span longer than 7 days. Please use multiple queries to gather your data.")
    end
  end

  class QueryParamMissing < Exception
    def initialize(param)
      super "Couldn't complete request. The query param #{param} is missing."
    end
  end

  class ParamMissing < Exception
    def initialize(param)
      super "Couldn't determine Mashery #{param}! Please check your config/masheri.yml"
    end
  end

  class ConfigMissing < Exception
    def initialize
      super "No configuration has been loaded! Please call Masheri.load_config! with a valid Yaml file."
    end
  end

  class MissingConfig < Exception
    def initialize
      if defined?(Rails)
        super("Couldn't find config/masheri.yml! \n" +
              "Please run `rails g masheri:install` to create one and populate it with the necessary API credentials.")
      else
        super("Couldn't find ~/.masheri.yml! \n" +
              "Please run `masheri --init` to create one and populate it with the necessary API credentials.")
      end
    end
  end

  class UnknownFormat < Exception
    def initialize(format)
      super "Unknown format #{format} for REST API call. Standard formats are CSV and JSON."
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
masheri-0.3.5 lib/masheri/exceptions.rb
masheri-0.3.4 lib/masheri/exceptions.rb