Class: Redmine::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/redmine-ruby.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, token) ⇒ Client



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/redmine-ruby.rb', line 14

def initialize(url, token)
  self.url    = url
  self.token  = token
  self.api = Her::API.new
  self.api.setup url: url, ssl: { verify: false } do |c|
    c.use Faraday::Request::BasicAuthentication, token, ''
    c.use Faraday::Request::UrlEncoded
    c.use Redmine::Middleware::XmlParser
    c.use Faraday::Adapter::NetHttp
  end
end

Instance Attribute Details

#apiObject

Returns the value of attribute api.



12
13
14
# File 'lib/redmine-ruby.rb', line 12

def api
  @api
end

#tokenObject

Returns the value of attribute token.



12
13
14
# File 'lib/redmine-ruby.rb', line 12

def token
  @token
end

#urlObject

Returns the value of attribute url.



12
13
14
# File 'lib/redmine-ruby.rb', line 12

def url
  @url
end

Instance Method Details

#issuesObject



41
42
43
# File 'lib/redmine-ruby.rb', line 41

def issues
  resource(:issue)
end

#projectsObject



37
38
39
# File 'lib/redmine-ruby.rb', line 37

def projects
  resource(:project)
end

#resource(name, options = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/redmine-ruby.rb', line 26

def resource(name, options={})
  klass   = "Redmine::#{name.to_s.classify}".constantize
  the_api = api
  Class.new(klass) do |c|
    c.uses_api        the_api
    c.element_name    name.to_s.underscore.to_sym
    c.collection_path klass.collection_path
    c.resource_path   klass.resource_path
  end
end