Class: ContactData::Fetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/contact-data/fetcher.rb

Constant Summary collapse

URL =
ENV['XENDATA_URL'] || 'http://public.xenapto.com'
API =
'api/v2'
LOGLEVEL =
Logger::WARN

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#api_methodObject (readonly)

Returns the value of attribute api_method.



10
11
12
# File 'lib/contact-data/fetcher.rb', line 10

def api_method
  @api_method
end

#http_methodObject (readonly)

Returns the value of attribute http_method.



10
11
12
# File 'lib/contact-data/fetcher.rb', line 10

def http_method
  @http_method
end

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/contact-data/fetcher.rb', line 10

def options
  @options
end

Instance Method Details

#parsed_jsonObject



25
26
27
28
# File 'lib/contact-data/fetcher.rb', line 25

def parsed_json
  logger.debug { "Parsing #{json.length} characters of JSON" }
  JSON.parse(json, symbolize_names: true, allow_nan: true)
end

#urlObject



30
31
32
33
34
35
# File 'lib/contact-data/fetcher.rb', line 30

def url
  return @url if @url
  @url = api_method.is_a?(String) ? "#{url_base}/#{api_method}" : "#{api_base}/#{method_base}#{api_method}"
  @url = "#{@url}.#{options[:format] || :json}" unless options[:noformat]
  @url
end