Class: Fugle::HTTP::Query Private

Inherits:
Object
  • Object
show all
Defined in:
lib/fugle/http/query.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

HTTP Query String

Since:

  • 0.1.0

Defined Under Namespace

Classes: MissingParameterError

Instance Method Summary collapse

Constructor Details

#initialize(query, parameters) ⇒ Query

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create new query

Parameters:

  • query (Hash)

    the user inputs query

  • parameters (Array<Hash>)

    the api parameter requirements

Since:

  • 0.1.0



21
22
23
24
25
26
# File 'lib/fugle/http/query.rb', line 21

def initialize(query, parameters)
  @query = query
  @parameters = parameters

  verify!
end

Instance Method Details

#all_required?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

Since:

  • 0.1.0



40
41
42
43
44
45
46
# File 'lib/fugle/http/query.rb', line 40

def all_required?
  @parameters
    .requires
    .reduce(true) do |prev, curr|
      @query[curr[:name]] && prev
    end
end

#to_hObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0



50
51
52
53
54
55
56
57
# File 'lib/fugle/http/query.rb', line 50

def to_h
  @query
    .map do |name, value|
      as = @parameters[name]&.fetch(:alias, nil)
      [as || name, value]
    end
    .to_h
end

#to_sObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0



61
62
63
# File 'lib/fugle/http/query.rb', line 61

def to_s
  URI.encode_www_form(to_h)
end

#verify!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Verify parameters

Raises:

Since:

  • 0.1.0



32
33
34
35
36
# File 'lib/fugle/http/query.rb', line 32

def verify!
  raise MissingParameterError unless all_required?

  true
end