class AlchemyAPI::Base

Attributes

options[RW]
response[RW]

Public Instance Methods

merged_options(opts) click to toggle source
# File lib/alchemy-api/base.rb, line 27
def merged_options(opts)
  opts.merge(Config.default_options)
end
parsed_response() click to toggle source
# File lib/alchemy-api/base.rb, line 17
def parsed_response
  case Config.output_mode
  when :json
    parsed = JSON.parse(@response.body)
    indexer ? parsed[indexer] : parsed
  when :rdf, :xml
    raise NotImplementedError
  end
end

Private Instance Methods

check_options(opts) click to toggle source
# File lib/alchemy-api/base.rb, line 33
def check_options(opts)
  @options = opts

  raise MissingOptionsError unless options && options.keys
  raise UnsupportedSearchMode unless supported_search_types.include?(mode)
end
connection() click to toggle source
# File lib/alchemy-api/base.rb, line 40
def connection
  @connection ||= Faraday.new(url: BASE_URL) do |builder|
    builder.request :url_encoded
    builder.adapter :excon
  end
end
method_prefix() click to toggle source
# File lib/alchemy-api/base.rb, line 59
def method_prefix
  case mode
  when :text then 'Text'
  when :url  then 'URL'
  when :html then 'HTML'
  end
end
mode() click to toggle source
# File lib/alchemy-api/base.rb, line 51
def mode
  %i(text url html).each do |type|
    return type if options.keys && options.keys.include?(type)
  end

  raise MissingOptionsError
end
path() click to toggle source
# File lib/alchemy-api/base.rb, line 67
def path
  "#{mode}/#{web_method}"
end
supported_search_types() click to toggle source
# File lib/alchemy-api/base.rb, line 47
def supported_search_types
  %i(text url html)
end