Module: PostcodeAnywhere::CapturePlus::Interactive

Includes:
Utils
Included in:
Client
Defined in:
lib/postcode_anywhere/capture_plus/interactive.rb

Defined Under Namespace

Classes: ParentIdExtractor

Constant Summary collapse

API_VERSION =
'2.00'
FIND_ADDRESSES_ENDPOINT =
"CapturePlus/Interactive/Find/v#{API_VERSION}/json.ws"
RETRIEVE_ADDRESS_ENDPOINT =
"CapturePlus/Interactive/Retrieve/v#{API_VERSION}/json.ws"

Instance Method Summary collapse

Methods included from Utils

#perform_with_object, #perform_with_objects

Instance Method Details

#query(search_term, options = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/postcode_anywhere/capture_plus/interactive.rb', line 17

def query(search_term, options = {})
  options.merge!(
    'SearchTerm' => search_term
  )
  options['LastId'] = ParentIdExtractor.new(options.delete(:parent_query)).extract
  options['SearchFor'] = options.delete(:search_for) || EVERYTHING
  options['Country']   = options.delete(:country) || 'GBR'
  options['LanguagePreference'] = options.delete(:language) || 'EN'
  perform_with_objects(
    :get,
    FIND_ADDRESSES_ENDPOINT,
    options,
    PostcodeAnywhere::CapturePlus::SearchResult
  )
end

#query_companies(search_term, options = {}) ⇒ Object



43
44
45
46
# File 'lib/postcode_anywhere/capture_plus/interactive.rb', line 43

def query_companies(search_term, options = {})
  options.merge!(search_for: COMPANY)
  query search_term, options
end

#query_places(search_term, options = {}) ⇒ Object



38
39
40
41
# File 'lib/postcode_anywhere/capture_plus/interactive.rb', line 38

def query_places(search_term, options = {})
  options.merge!(search_for: PLACE)
  query search_term, options
end

#query_postcodes(search_term, options = {}) ⇒ Object



48
49
50
51
# File 'lib/postcode_anywhere/capture_plus/interactive.rb', line 48

def query_postcodes(search_term, options = {})
  options.merge!(search_for: POSTCODE)
  query search_term, options
end

#retrieve(search_result) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/postcode_anywhere/capture_plus/interactive.rb', line 53

def retrieve(search_result)
  options = {}
  options.merge!(
    'Id' => ParentIdExtractor.new(search_result).extract
  )
  perform_with_object(
    :get,
    RETRIEVE_ADDRESS_ENDPOINT,
    options,
    PostcodeAnywhere::CapturePlus::RetrieveResult
  )
end

#sub_query(search_term, parent_query, options = {}) ⇒ Object



33
34
35
36
# File 'lib/postcode_anywhere/capture_plus/interactive.rb', line 33

def sub_query(search_term, parent_query, options = {})
  options.merge!(parent_query: parent_query)
  query(search_term, options)
end