Class: RedmineTicketClient::Sender

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

Instance Method Summary collapse

Instance Method Details

#post_to_redmine(hash_or_exception) ⇒ Object



84
85
86
87
# File 'lib/redmine-ticket/client.rb', line 84

def post_to_redmine hash_or_exception
  ticket = hash_or_exception
  send_to_redmine(:ticket => ticket)
end

#rescue_action_in_public(exception) ⇒ Object



81
82
# File 'lib/redmine-ticket/client.rb', line 81

def rescue_action_in_public(exception)
end

#send_to_redmine(data) ⇒ Object

:nodoc:



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/redmine-ticket/client.rb', line 89

def send_to_redmine data #:nodoc:
  headers = {
    'Content-type' => 'application/x-yaml',
    'Accept' => 'text/xml, application/xml'
  }

  url = RedmineTicketClient.url
  
  http = Net::HTTP::Proxy(RedmineTicketClient.proxy_host, 
                          RedmineTicketClient.proxy_port, 
                          RedmineTicketClient.proxy_user, 
                          RedmineTicketClient.proxy_pass).new(url.host, url.port)

  http.use_ssl = true
    http.read_timeout = RedmineTicketClient.http_read_timeout
    http.open_timeout = RedmineTicketClient.http_open_timeout
  http.use_ssl = !!RedmineTicketClient.secure 

    response = begin
      http.post(url.path, stringify_keys(data).to_yaml, headers)
    rescue TimeoutError => e
      $stderr.puts  "Timeout while contacting the Redmine server."
      nil
    end
   
  case response
  when Net::HTTPSuccess then
    return response.body
  else
    $stderr.puts "Redmine Failure: #{response.class}\n#{response.body if response.respond_to? :body}"
    return response.class
  end
end

#stringify_keys(hash) ⇒ Object

:nodoc:



123
124
125
126
127
128
# File 'lib/redmine-ticket/client.rb', line 123

def stringify_keys(hash) #:nodoc:
  hash.inject({}) do |h, pair|
    h[pair.first.to_s] = pair.last.is_a?(Hash) ? stringify_keys(pair.last) : pair.last
    h
  end
end