Class: ParamsService

Inherits:
Object
  • Object
show all
Defined in:
lib/twitter_labs_api/services/params_service.rb

Class Method Summary collapse

Class Method Details

.from_fields(fields) ⇒ Hash

Convert user-passed fields hash to query params

Examples:

input: { tweet: %w[id username], media: ['url'] }
output: { 'tweet.fields' => 'id,username', 'media.fields' => 'url }

Parameters:

  • :fields (Hash)

    A hash of requested fields; see API Reference for details

Returns:

  • (Hash)

    A hash of query params for consumption by API client



8
9
10
11
12
13
14
# File 'lib/twitter_labs_api/services/params_service.rb', line 8

def self.from_fields(fields)
  fields.keys.inject({}) do |memo, key|
    memo["#{key}.fields"] = fields[key].join(',')

    memo
  end
end