Class: AlchemyAPI::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/alchemy-api/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsObject

Returns the value of attribute options


6
7
8
# File 'lib/alchemy-api/base.rb', line 6

def options
  @options
end

#responseObject

Returns the value of attribute response


6
7
8
# File 'lib/alchemy-api/base.rb', line 6

def response
  @response
end

Instance Method Details

#merged_options(opts) ⇒ Object


27
28
29
# File 'lib/alchemy-api/base.rb', line 27

def merged_options(opts)
  opts.merge(Config.default_options)
end

#parsed_responseObject


17
18
19
20
21
22
23
24
25
# 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

#search(opts) ⇒ Object


8
9
10
11
12
13
14
15
# File 'lib/alchemy-api/base.rb', line 8

def search(opts)
  check_options(opts)
  body = { apikey: Config.apikey }.merge!(merged_options(options))

  @response = connection.post(path, body)

  parsed_response
end