Sha256: ccc1e1d6d57f4f00440635aaac553c7a4e233fe32d1b1907f8694dfb9a857512
Contents?: true
Size: 1.87 KB
Versions: 1
Compression:
Stored size: 1.87 KB
Contents
require 'thor' require 'active_resource' require 'active_support/core_ext/object/with_options' require 'redmine-cli/config' require 'pp' module Redmine module Cli class BaseResource < ActiveResource::Base self.site = Redmine::Cli::config.url self.user = Redmine::Cli::config.username self.password = Redmine::Cli::config.password class << self # HACK: Redmine API isn't ActiveResource-friendly out of the box, so # we need to pass nometa=1 to all requests since we don't care about # the metadata that gets passed back in the top level attributes. def find(*arguments) arguments[1] = arguments[1] || {} arguments[1][:params] = arguments[1][:params] || {} arguments[1][:params][:nometa] = 1 super end def fetch_all(params = {}) limit = 100 offset = 0 resources = [] while((fetched_resources = self.all(:params => params.merge({:limit => limit, :offset => offset}))).any?) resources += fetched_resources offset += limit if fetched_resources.length < limit then break end end resources end end end class Issue < BaseResource; end class User < BaseResource; end class Project < BaseResource; end class Query < BaseResource; end end end # HACK: Redmine API isn't ActiveResource-friendly out of the box, and # also some versions of Redmine ignore the nometa=1 parameter. So we # need to manually strip out metadata that confuses ActiveResource. class Hash class << self alias_method :from_xml_original, :from_xml def from_xml(xml) scrubbed = scrub_attributes(xml) from_xml_original(scrubbed) end def scrub_attributes(xml) xml.gsub(/<issues .*?>/, "<issues type=\"array\">") end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
redmine-cli-0.1.5 | lib/redmine-cli/resources.rb |