Class: Redmine::Client

Inherits:
Object
  • Object
show all
Includes:
Debug
Defined in:
lib/redmine/client.rb

Constant Summary collapse

NAMESPACE =
{ "atom" => "http://www.w3.org/2005/Atom" }

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Debug

#debug?

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/redmine/client.rb', line 11

def initialize(options = {})
  options = {
    :key      => nil,
    :domain   => nil,
    :protocol => "http",
    :debug    => true
  }.merge(options)

  @debug    = options[:debug]
  @key      = options[:key]
  @domain   = options[:domain]
  @protocol = options[:protocol]

  debug "[CLIENT]" do
    puts options
  end
end

Instance Attribute Details

#domainObject

Returns the value of attribute domain.



9
10
11
# File 'lib/redmine/client.rb', line 9

def domain
  @domain
end

#keyObject

Returns the value of attribute key.



9
10
11
# File 'lib/redmine/client.rb', line 9

def key
  @key
end

#protocolObject

Returns the value of attribute protocol.



9
10
11
# File 'lib/redmine/client.rb', line 9

def protocol
  @protocol
end

Instance Method Details

#docObject



55
56
57
# File 'lib/redmine/client.rb', line 55

def doc
  @doc ||= Nokogiri::XML(open(issues_url))
end

#my_issues(limit = nil) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/redmine/client.rb', line 29

def my_issues(limit = nil)
  projects = {}

  doc.xpath('//atom:entry', NAMESPACE ).each do |e|
    id = e.xpath('.//atom:id', NAMESPACE).first.content.split("/").last
    raw_title = e.xpath('.//atom:title', NAMESPACE).first.content
    regex = /([^-]*) - (.*)/
    match = raw_title.match(regex)
    project = match[1]
    title   = match[2]


    projects[project] ||= []
    projects[project] << {
      :id => id,
      :title => title
    }
  end

  debug "[URL]" do
    puts issues_url
  end

  return projects
end

#resetObject



59
60
61
# File 'lib/redmine/client.rb', line 59

def reset
  @doc = nil
end