8 def latest_note(issue_id, session_cookie)
9 result = {:value => nil, :notes => {:text => nil, :is_private => nil}}
11 feed = get_feed("issues/#{issue_id}.atom", session_cookie).css("entry")
12 feed_limitted = get_feed("issues/#{issue_id}.atom").css("entry")
15 entry_limitted = feed_limitted.pop
17 parsed_entry = parse_feed_entry(entry)
18 parsed_entry_limitted = parse_feed_entry(entry_limitted)
20 #p parsed_entry.inspect
21 #p "parsed_entry_for_guest---"
22 #p parsed_entry_limitted.inspect
25 if parsed_entry[:notes][:journal_id].to_s != parsed_entry_limitted[:notes][:journal_id].to_s
26 result[:notes][:is_private] = true
28 result[:notes][:is_private] = false
31 # The <entry> was splitted if notes is private.
32 if result[:notes][:is_private]
33 result[:value] = parsed_entry_limitted[:value]
34 result[:notes][:text] = parsed_entry[:notes][:text]
36 result[:value] = parsed_entry[:value]
37 result[:notes][:text] = parsed_entry[:notes][:text]
43 def parse_feed_entry(entry)
44 result = {:value => nil, :notes => {:journal_id => nil, :text => nil, :is_private => nil}}
47 result[:notes][:journal_id] = entry.css("id").text
50 src = entry.css("content").text
52 html = Nokogiri::HTML(src)
54 # get change field from <content>
55 # - attension - one field only.
56 unless html.css("li").empty?
57 change_desc = html.css("li").first
58 #p "li=" + change_desc.inner_html
60 field_name = change_desc.css("strong").first.text
61 if change_desc.css("i").length == 2
62 result[:value] = change_desc.css("i").last.text
64 result[:value] = :none
68 # get notes from <content>
69 # - attension - not support wiki format
70 #p "inner html=" + html.inner_html
71 notes = Nokogiri::HTML(html.inner_html).css("p").inner_html.gsub(/<br>/, "\n")
73 result[:notes][:text] = notes
78 def get_feed(path, session_cookie=nil)
79 uri = URI::parse "#{@base_url}#{path}"
80 if session_cookie.nil?
83 headers = {'Cookie' => cookie_hash_to_header_string(session_cookie)}
85 res = Net::HTTP.start(uri.host, uri.port) do |http|
86 http.get(uri.path, headers)
88 src = res.body.gsub(/<content type="html">/, "<content>") # To avoid erroneous decisions made by Nokogiri
92 def cookie_hash_to_header_string(cookie)
93 "#{cookie[:name]}=#{cookie[:value]};path=#{cookie[:path]}"