Class: NPR::Configuration
- Inherits:
-
Object
- Object
- NPR::Configuration
- Defined in:
- lib/npr/configuration.rb
Overview
NPR::Configuration
Probably doesn’t need to be accessed directly. You can get the global configuration for the NPR gem by accessing NPR.config
Constant Summary collapse
- API_ROOT =
"http://api.npr.org"
- API_QUERY_PATH =
"/query"
- API_LIST_PATH =
"/list"
- API_OPTIONS =
List all the parameters that the NPR API can accept. Some are left out that don’t make sense to globally configure (such as
:id
,:startNum
, and:callback
) [ # List options :storyCountAll, :storyCountMonth, :storyCountToday, :childrenOf, :hideChildren, # Story options :apiKey, :orgId, :meta, :output, :fields, :sort, :numResults, :action, :requiredAssets, :date, :startDate, :endDate, :dateType, :searchTerm, :searchType, :title ]
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Configuration
constructor
——————- You can pass in a hash of options to Configuration.new.
-
#merge(hash) ⇒ Object
——————- Convenience method.
-
#to_hash ⇒ Object
——————- Convert this Configuration object into a Hash.
Constructor Details
#initialize(options = {}) ⇒ Configuration
You can pass in a hash of options to Configuration.new
81 82 83 84 85 |
# File 'lib/npr/configuration.rb', line 81 def initialize(={}) .each do |key, value| send "#{key}=", value end end |
Instance Method Details
#merge(hash) ⇒ Object
Convenience method
89 90 91 |
# File 'lib/npr/configuration.rb', line 89 def merge(hash) to_hash.merge hash end |
#to_hash ⇒ Object
Convert this Configuration object into a Hash
Why don’t we inherit from OrderedOptions?
Since the API options are out of our control (without having to map every API option to internal methods), it is possible that one of the config options will conflict with something in Ruby. For example, the “sort” option that the NPR API allows would mean we’d have to overwrite Ruby’s Hash#sort method.
We could just map out config options to the API options, but I think it’s more important to keep the gem config options in perfect sync with the API options.
112 113 114 115 116 117 118 |
# File 'lib/npr/configuration.rb', line 112 def to_hash hash = {} instance_variables.each do |var| hash[var[1..-1].to_sym] = instance_variable_get(var) end hash end |