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



16
17
18
19
20
21
22
23
24
25
# File 'lib/alchemy-api/base.rb', line 16

def parsed_response
  case Config.output_mode
  when :json
    parsed = JSON.parse(@response.body)
    indexer ? parsed[indexer] : parsed
  when :xml
  when :rdf
    fail NotImplementedError
  end
end

#search(opts) ⇒ Object



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

def search(opts)
  check_options(opts)

  @response = connection.post(path, construct_body)

  parsed_response
end