Module: SitraClient
- Defined in:
- lib/sitra_client.rb,
lib/sitra_client/version.rb
Constant Summary collapse
- MAX_COUNT =
100- MAX_LOOPS =
Safety net
5- VERSION =
'0.3.2'
Class Method Summary collapse
- .config ⇒ Object
-
.configure(opts = {}) ⇒ Object
Configure through hash.
- .query(criteria, all_results = false) ⇒ Object
- .selections ⇒ Object
Class Method Details
.config ⇒ Object
30 31 32 |
# File 'lib/sitra_client.rb', line 30 def self.config @config end |
.configure(opts = {}) ⇒ Object
Configure through hash
26 27 28 |
# File 'lib/sitra_client.rb', line 26 def self.configure(opts = {}) opts.each {|k,v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym} end |
.query(criteria, all_results = false) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/sitra_client.rb', line 34 def self.query(criteria, all_results = false) query_result = {} if all_results loops = 0 criteria[:first] = 0 criteria[:count] = MAX_COUNT response = get_response(criteria) results = response.as_array while response.results_count > results.length && loops < MAX_LOOPS loops += 1 criteria[:first] += MAX_COUNT results += get_response(criteria).as_array end query_result[:count] = response.results_count query_result[:results] = results else response = get_response(criteria) results = response.as_array query_result[:count] = response.results_count query_result[:results] = results end query_result end |
.selections ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/sitra_client.rb', line 58 def self.selections response = '' query = SitraQuery.new(@config[:api_key], @config[:site_identifier]) @logger.info "Selections retrieval query : #{@config[:base_url]}/referentiel/selections?query=#{query.to_params}" open("#{@config[:base_url]}/referentiel/selections?query=#{CGI.escape query.to_params}") { |f| f.each_line {|line| response += line if line} } JSON.parse response, symbolize_names: true end |