cctray 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +25 -0
  3. data/lib/cctray.rb +54 -0
  4. metadata +86 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0085f12af3d61745b12f68c438f380f7608c6d02
4
+ data.tar.gz: 413d22e4451220e05bd0fc83cc9e6ef94b36e664
5
+ SHA512:
6
+ metadata.gz: 463f7928fc4b18b40d89ba20fc868b7176a7523c9762bb277110bc800e448721ccb92da7ec08adc990eadd2bca315762657a797db37dbf2a5f3af0e2183ac37a
7
+ data.tar.gz: d2b8e2373fea225eb17780dd6bb10c672816a13bd11b2239f0f5e5067cc1903fa3d32a40c28f97d4a8d39c8eff32c8bd3c17eac08c256b4b65e343fc55d32236
@@ -0,0 +1,25 @@
1
+ # CCTray
2
+
3
+ Simply fetch and parse cctray feed xml as ruby objects.
4
+
5
+
6
+ ## Example
7
+
8
+ ```ruby
9
+ tray = CCTray.new("http://server/cctray.xml", 'user', 'pass')
10
+ projects = tray.fetch
11
+
12
+ projects.each do |proj|
13
+ proj.name # String
14
+ proj.activity # String
15
+ proj.last_build_status # String
16
+ proj.last_build_label # String
17
+ proj.last_build_time # DateTime
18
+ proj.last_build_time_str # The original String value of lastBuildTime parsed out from feed
19
+ proj.web_url # String
20
+ proj.messages.each do |mes|
21
+ mes.kind # String
22
+ mes.text # String
23
+ end
24
+ end
25
+ ```
@@ -0,0 +1,54 @@
1
+ require 'net/http'
2
+ require 'net/https'
3
+ require 'nokogiri'
4
+
5
+ class CCTray
6
+
7
+ class Project < Struct.new(:name,
8
+ :activity,
9
+ :last_build_status,
10
+ :last_build_label,
11
+ :last_build_time_str,
12
+ :web_url,
13
+ :messages)
14
+ def last_build_time
15
+ @last_build_time ||= DateTime.parse(last_build_time_str)
16
+ end
17
+ end
18
+ class Message < Struct.new(:kind, :text)
19
+ end
20
+
21
+ def initialize(feed_url, user=nil, pass=nil)
22
+ @feed_url = feed_url
23
+ @user, @pass = user, pass
24
+ end
25
+
26
+ def fetch
27
+ Nokogiri::XML(get).css("Project").map do |proj|
28
+ Project.new(proj[:name],
29
+ proj[:activity],
30
+ proj[:lastBuildStatus],
31
+ proj[:lastBuildLabel],
32
+ proj[:lastBuildTime],
33
+ proj[:webUrl],
34
+ proj.css('message').map{|m| Message.new(m[:kind], m[:text])})
35
+ end
36
+ end
37
+
38
+ def get
39
+ uri = URI(@feed_url)
40
+ http_opts = { use_ssl: uri.scheme == 'https' }
41
+ Net::HTTP.start uri.host, uri.port, http_opts do |https|
42
+ req = Net::HTTP::Get.new(uri.path).tap do |req|
43
+ req.basic_auth @user, @pass if @user
44
+ end
45
+
46
+ case res = https.request(req)
47
+ when Net::HTTPSuccess
48
+ res.body
49
+ else
50
+ res.error!
51
+ end
52
+ end
53
+ end
54
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cctray
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Xiao Li
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.6.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.6'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.6.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: rake
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '10.1'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 10.0.0
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '10.1'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 10.0.0
53
+ description: A simple CCTray class to fetch and parse the feed xml as ruby objects
54
+ email:
55
+ - swing1979@gmail.com
56
+ executables: []
57
+ extensions: []
58
+ extra_rdoc_files: []
59
+ files:
60
+ - README.md
61
+ - lib/cctray.rb
62
+ homepage: https://github.com/xli/cctray
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.2.0
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Simply fetch and parse cctray feed xml.
86
+ test_files: []