class Travis::Client::Action::Template
Public Instance Methods
accept_everything?()
click to toggle source
# File lib/travis/client/action.rb, line 61 def accept_everything? method != 'GET' and body_params.empty? end
entity_params(key, value)
click to toggle source
# File lib/travis/client/action.rb, line 38 def entity_params(key, value) result = {} params.each do |param| next unless param =~ /^#{key}\.(.+)$/ next unless value.respond_to? $1 result[param] = value.public_send($1) end result[key] = value if result.empty? result end
map_pair(key, value, prefix)
click to toggle source
# File lib/travis/client/action.rb, line 9 def map_pair(key, value, prefix) return if value.nil? return entity_params(key, value) if value.is_a? Entity return map_pair("#{prefix}.#{key}", value, prefix) if !params.include?(key) and params.include?("#{prefix}.#{key}") if value.is_a? Hash and !body_params.include? key return value.map { |k,v| map_pair("#{prefix}.#{k}", v, prefix).to_h }.inject(&:merge) end if mandatory.include? key or optional.include? key value = prepare_segment(value) else value = prepare_json(value) end { key => value } end
map_params(params, prefix)
click to toggle source
# File lib/travis/client/action.rb, line 5 def map_params(params, prefix) params.map { |key, value| map_pair(key.to_s, value, prefix).to_h }.inject({}, &:merge) end
params()
click to toggle source
# File lib/travis/client/action.rb, line 57 def params @params ||= mandatory + optional + body_params end
payload(params)
click to toggle source
# File lib/travis/client/action.rb, line 53 def payload(params) params.reject { |k,_| mandatory.include? k or optional.include? k } end
possible_params(prefix)
click to toggle source
# File lib/travis/client/action.rb, line 65 def possible_params(prefix) [mandatory, optional + body_params]. map { |list| list.map { |p| p.sub(/^#{prefix}\./, '').inspect }.join(',') if list.any? }. compact.join(', optionally ') end
prepare_json(value)
click to toggle source
# File lib/travis/client/action.rb, line 34 def prepare_json(value) value end
prepare_segment(value)
click to toggle source
# File lib/travis/client/action.rb, line 27 def prepare_segment(value) case value when Array then value.map { |v| prepare_segment(v) }.join(',') else value.to_s end end
uri(params)
click to toggle source
# File lib/travis/client/action.rb, line 49 def uri(params) uri_template.expand(params) end