Module: Cnf

Extended by:
Cnf
Included in:
Cnf
Defined in:
lib/cnf.rb,
lib/cnf/catalog.rb,
lib/cnf/watcher.rb,
lib/cnf/marketplace.rb

Defined Under Namespace

Classes: AbebooksCatalog, Catalog, Marketplace, MiraklCatalog, NearfineCatalog, TestCatalog, Watcher

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



21
22
23
# File 'lib/cnf.rb', line 21

def method_missing(m, *args, &block)
  parsed_fetched_data.send(m)
end

Instance Method Details

#fetch_dataObject Also known as: all



9
10
11
12
13
14
# File 'lib/cnf.rb', line 9

def fetch_data
  @_cnf ||= begin
    res = Excon.get(url, headers: headers)
    JSON.load(res.body)
  end
end

#hostsObject



29
30
31
32
33
34
35
# File 'lib/cnf.rb', line 29

def hosts
  return if amazon.nil?

  amazon.map do |catalog|
    [ catalog.marketplace.country_code, catalog.api_hostname ]
  end.to_h
end

#marketplace_idsObject



37
38
39
40
41
42
43
# File 'lib/cnf.rb', line 37

def marketplace_ids
  return if amazon.nil?

  amazon.map do |catalog|
    [ catalog.marketplace.country_code, catalog.marketplace.id ]
  end.to_h
end

#markupsObject



25
26
27
# File 'lib/cnf.rb', line 25

def markups
  fetch_data['markups']
end

#parsed_fetched_dataObject



17
18
19
# File 'lib/cnf.rb', line 17

def parsed_fetched_data
  @parsed_fetched_data ||= RecursiveOpenStruct.new(fetch_data, recurse_over_arrays: true)
end