Class: AlchemyLanguage::CombinedCall

Inherits:
ActiveModel::Base show all
Defined in:
lib/alchemy_language/model/combined_call.rb

Instance Attribute Summary

Attributes inherited from ActiveModel::Base

#auth_token, #json_result, #options, #path, #prefix, #type

Instance Method Summary collapse

Methods inherited from ActiveModel::Base

#check_prefix, #params_addressable, #request

Methods included from Generators::AlchemyRequest

#base_url, #json_parser, #rest_client_api

Methods inherited from ActiveMethod::Extra

add_response_field, #result

Constructor Details

#initialize(path, type, options = {}) ⇒ CombinedCall

Returns a new instance of CombinedCall.



6
7
8
9
# File 'lib/alchemy_language/model/combined_call.rb', line 6

def initialize(path, type, options={})
  super 
  check_options
end

Instance Method Details

#add_dynamic_response_field(name) ⇒ Object



27
28
29
30
31
32
# File 'lib/alchemy_language/model/combined_call.rb', line 27

def add_dynamic_response_field(name)
  self.class.send(:define_method, name) do 
    name = name.to_s.gsub('_', '-')
    @json_result[name.to_s]
  end
end

#check_optionsObject



19
20
21
22
23
24
25
# File 'lib/alchemy_language/model/combined_call.rb', line 19

def check_options
  if @options.key?(:extract)
    @options[:extract].split(',').each do |option|
      add_dynamic_response_field(option)
    end
  end
end

#endpointObject



11
12
13
14
15
16
17
# File 'lib/alchemy_language/model/combined_call.rb', line 11

def endpoint
  url = "#{@type}/#{@prefix}GetCombinedData"
  url << "?apikey=#{@auth_token}"
  url << "&#{@type}=#{@path}&outputMode=json"
  url << "&#{params_addressable}" unless params_addressable.empty?
  url
end