Sha256: f03b569ab73716e5c5e7dca722f8fa280d2e29ff7d6d893fabb18dc76bf070a5

Contents?: true

Size: 1.79 KB

Versions: 8

Compression:

Stored size: 1.79 KB

Contents

require 'hashie'
require 'active_support/time'

module DataComApi
  class QueryParameters < Hashie::Trash
    UNALLOWED_FIELDS = [
      :offset,
      :pageSize,
      :page_size,
      :username,
      :password,
      :token
    ].freeze

    property :companyId,        from: :company_id
    property :updatedSince,     from: :updated_since, with: ->(v) do
      Time.parse(v).utc.in_time_zone(Client::TIME_ZONE)
    end
    property :title
    property :companyName,      from: :company_name
    property :name
    property :lastname
    property :firstname
    property :email
    property :levels
    property :departments
    property :country
    property :state
    property :metroArea,        from: :metro_area
    property :areaCode,         from: :area_code
    property :zipCode,          from: :zip_code
    property :industry
    property :subIndustry,      from: :sub_industry
    property :employees
    property :revenue
    property :ownership
    property :websiteType,      from: :website_type
    property :fortuneRank,      from: :fortune_rank
    property :includeGraveyard, from: :include_graveyard
    property :order
    property :orderBy,          from: :order_by
    property :purchaseFlag,     from: :purchase_flag
    property :endOrgId,         from: :end_org_id
    property :endUserId,        from: :end_user_id

    # Special params, used to inject into query, set only through gem
    property :offset
    property :pageSize,         from: :page_size
    property :username
    property :password
    property :token

    # Destructively convert all values using into strings
    def self.stringify_hash_values(hash)
      hash.each_pair do |key, value|
        hash[key] = value.to_s
      end
      hash
    end

    def to_hash
      self.class.stringify_hash_values(super)
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
data-com-api-0.2.1 lib/data-com-api/query_parameters.rb
data-com-api-0.2.0 lib/data-com-api/query_parameters.rb
data-com-api-0.1.5 lib/data-com-api/query_parameters.rb
data-com-api-0.1.4 lib/data-com-api/query_parameters.rb
data-com-api-0.1.3 lib/data-com-api/query_parameters.rb
data-com-api-0.1.2 lib/data-com-api/query_parameters.rb
data-com-api-0.1.1 lib/data-com-api/query_parameters.rb
data-com-api-0.1.0 lib/data-com-api/query_parameters.rb