go_api_client 0.5.4 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/.travis.yml +26 -0
  4. data/README.md +86 -0
  5. data/go_api_client.gemspec +11 -11
  6. data/lib/go_api_client/api/abstract_api.rb +12 -0
  7. data/lib/go_api_client/api/cctray.rb +53 -0
  8. data/lib/go_api_client/api/config.rb +60 -0
  9. data/lib/go_api_client/api/feed.rb +39 -0
  10. data/lib/go_api_client/api/job.rb +34 -0
  11. data/lib/go_api_client/api/pipeline.rb +87 -0
  12. data/lib/go_api_client/api/properties.rb +43 -0
  13. data/lib/go_api_client/api/stage.rb +45 -0
  14. data/lib/go_api_client/attribute_helper.rb +9 -0
  15. data/lib/go_api_client/client.rb +20 -0
  16. data/lib/go_api_client/domain/artifact.rb +16 -0
  17. data/lib/go_api_client/domain/author.rb +22 -0
  18. data/lib/go_api_client/domain/changeset.rb +13 -0
  19. data/lib/go_api_client/domain/config/job.rb +15 -0
  20. data/lib/go_api_client/domain/config/pipeline.rb +15 -0
  21. data/lib/go_api_client/domain/config/stage.rb +15 -0
  22. data/lib/go_api_client/domain/entry.rb +13 -0
  23. data/lib/go_api_client/domain/feed.rb +13 -0
  24. data/lib/go_api_client/domain/internal_cache.rb +28 -0
  25. data/lib/go_api_client/domain/job.rb +17 -0
  26. data/lib/go_api_client/domain/material.rb +14 -0
  27. data/lib/go_api_client/domain/pipeline.rb +27 -0
  28. data/lib/go_api_client/domain/project.rb +14 -0
  29. data/lib/go_api_client/domain/scheduled_job.rb +12 -0
  30. data/lib/go_api_client/domain/stage.rb +28 -0
  31. data/lib/go_api_client/domain/user.rb +30 -0
  32. data/lib/go_api_client/http_fetcher.rb +73 -48
  33. data/lib/go_api_client/parsers/artifact_parser.rb +17 -0
  34. data/lib/go_api_client/parsers/author_parser.rb +24 -0
  35. data/lib/go_api_client/parsers/changeset.rb +26 -0
  36. data/lib/go_api_client/parsers/config/job_parser.rb +48 -0
  37. data/lib/go_api_client/parsers/config/pipeline_parser.rb +42 -0
  38. data/lib/go_api_client/parsers/config/stage_parser.rb +33 -0
  39. data/lib/go_api_client/parsers/entry_parser.rb +27 -0
  40. data/lib/go_api_client/parsers/feed_parser.rb +27 -0
  41. data/lib/go_api_client/parsers/job_parser.rb +47 -0
  42. data/lib/go_api_client/parsers/material_parser.rb +29 -0
  43. data/lib/go_api_client/parsers/parser_helper.rb +11 -0
  44. data/lib/go_api_client/parsers/pipeline_parser.rb +30 -0
  45. data/lib/go_api_client/parsers/project_parser.rb +26 -0
  46. data/lib/go_api_client/parsers/scheduled_job_parser.rb +28 -0
  47. data/lib/go_api_client/parsers/stage_parser.rb +31 -0
  48. data/lib/go_api_client/parsers/user_parser.rb +12 -0
  49. data/lib/go_api_client/version.rb +4 -4
  50. data/lib/go_api_client.rb +56 -110
  51. data/test/go_api_client/artifact_test.rb +8 -8
  52. data/test/go_api_client/author_test.rb +27 -0
  53. data/test/go_api_client/building_test.rb +21 -19
  54. data/test/go_api_client/{atom/entry_test.rb → entry_test.rb} +8 -8
  55. data/test/go_api_client/job_test.rb +15 -14
  56. data/test/go_api_client/pipeline_test.rb +24 -27
  57. data/test/go_api_client/stage_test.rb +21 -74
  58. data/test/go_api_client/user_test.rb +15 -20
  59. metadata +108 -78
  60. data/.init.sh +0 -8
  61. data/.rbenv-gemsets +0 -1
  62. data/.ruby-version +0 -1
  63. data/.rvmrc +0 -1
  64. data/.yardopts +0 -6
  65. data/Gemfile.lock +0 -32
  66. data/README.textile +0 -64
  67. data/lib/go_api_client/artifact.rb +0 -27
  68. data/lib/go_api_client/atom/author.rb +0 -42
  69. data/lib/go_api_client/atom/entry.rb +0 -34
  70. data/lib/go_api_client/atom/feed.rb +0 -40
  71. data/lib/go_api_client/atom/feed_page.rb +0 -49
  72. data/lib/go_api_client/atom.rb +0 -4
  73. data/lib/go_api_client/commit.rb +0 -30
  74. data/lib/go_api_client/helpers/simple_attribute_support.rb +0 -11
  75. data/lib/go_api_client/helpers.rb +0 -1
  76. data/lib/go_api_client/job.rb +0 -68
  77. data/lib/go_api_client/pipeline.rb +0 -48
  78. data/lib/go_api_client/stage.rb +0 -57
  79. data/lib/go_api_client/user.rb +0 -36
  80. data/test/go_api_client/atom/author_test.rb +0 -27
  81. data/test/go_api_client/atom/feed_page_test.rb +0 -41
  82. data/test/go_api_client/atom/feed_test.rb +0 -39
  83. data/test/go_api_client/commit_test.rb +0 -38
  84. data/test/schedule_test.rb +0 -12
data/.init.sh DELETED
@@ -1,8 +0,0 @@
1
- #!/bin/bash
2
- set -x
3
- BUNDLE_PATH=/tmp/.bundle-$(basename $(pwd))
4
- if [ -z "$BUNDLE_PATH" ]
5
- then
6
- BUNDLE_PATH=".bundle"
7
- fi
8
- bundle install --local --path $BUNDLE_PATH --binstubs --clean
data/.rbenv-gemsets DELETED
@@ -1 +0,0 @@
1
- go-api-client
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 1.9.3-p392
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm ruby-1.9.2-p290@go-api-client
data/.yardopts DELETED
@@ -1,6 +0,0 @@
1
- --no-private
2
- --protected
3
- --markup="textile" lib/**/*.rb
4
- --main README.textile
5
- --hide-tag todo
6
- -
data/Gemfile.lock DELETED
@@ -1,32 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- go_api_client (0.5.4)
5
- nokogiri
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- addressable (2.2.7)
11
- crack (0.3.1)
12
- multi_json (1.2.0)
13
- nokogiri (1.5.2)
14
- rake (0.9.2.2)
15
- simplecov (0.6.1)
16
- multi_json (~> 1.0)
17
- simplecov-html (~> 0.5.3)
18
- simplecov-html (0.5.3)
19
- test-unit (2.4.8)
20
- webmock (1.8.0)
21
- addressable (>= 2.2.7)
22
- crack (>= 0.1.7)
23
-
24
- PLATFORMS
25
- ruby
26
-
27
- DEPENDENCIES
28
- go_api_client!
29
- rake
30
- simplecov
31
- test-unit
32
- webmock
data/README.textile DELETED
@@ -1,64 +0,0 @@
1
- h2. Go API Client Gem
2
-
3
- This gem provides access to the "ThoughtWorks Studios Go":http://www.thoughtworks-studios.com/go-continuous-delivery API, it is capable of parsing out the atom feed and generate an object graph with all the pipelines/stages/jobs and committer information.
4
-
5
- h2. Installation
6
-
7
- <pre>$ [sudo] gem install go_api_client</pre>
8
-
9
- h2. Usage
10
-
11
- See "GoApiClient":http://rubydoc.info/github/ThoughtWorksInc/go-api-client/GoApiClient for supported options and more details.
12
-
13
- <pre>
14
- require 'go_api_client'
15
-
16
- # check if the server is building
17
- GoApiClient.build_in_progress?(:host => 'go.example.com')
18
-
19
- # check if the build has finished
20
- GoApiClient.build_finished?(:host => 'go.example.com')
21
-
22
- # schedule a pipeline
23
- GoApiClient.schedule_pipeline(:host => 'go.example.com', :pipeline_name => 'MyProject')
24
-
25
- # fetch a list of all pipelines
26
- latest_atom_entry_id = nil
27
- while true
28
- last_run = GoApiClient.runs(:host => 'go.example.com', :pipeline_name => 'MyProject', :latest_atom_entry_id => latest_atom_entry_id)
29
- latest_atom_entry_id = last_run.latest_atom_entry_id # => the last stage that was seen by the api client, keep this for further calls to #runs
30
-
31
- pipelines = last_run.pipelines
32
- last_pipeline = pipelines.last
33
- puts "Finished running stage #{last_pipeline.stages.last.name} from pipeline #{last_pipeline.name}."
34
- puts "The last commit(#{last_pipeline.commits.last.revision}) was checked in by #{last_pipeline.commits.last.user}"
35
- sleep 10
36
- end
37
- </pre>
38
-
39
- h2. License
40
-
41
- Go API Client Gem is MIT Licensed
42
-
43
- The MIT License
44
-
45
- Copyright (c) 2012 ThoughtWorks, Inc. (http://thoughtworks.com)
46
-
47
- Permission is hereby granted, free of charge, to any person obtaining a copy
48
- of this software and associated documentation files (the "Software"), to deal
49
- in the Software without restriction, including without limitation the rights
50
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
51
- copies of the Software, and to permit persons to whom the Software is
52
- furnished to do so, subject to the following conditions:
53
-
54
- The above copyright notice and this permission notice shall be included in
55
- all copies or substantial portions of the Software.
56
-
57
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
58
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
59
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
60
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
61
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
62
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
63
- THE SOFTWARE.
64
-
@@ -1,27 +0,0 @@
1
- module GoApiClient
2
- class Artifact
3
- attr_accessor :base_uri, :src, :dest, :artifact_type
4
- include GoApiClient::Helpers::SimpleAttributesSupport
5
-
6
- def initialize(attributes)
7
- super(attributes)
8
- end
9
-
10
- def as_zip_file_url
11
- "#{File.join(base_uri, src)}.zip"
12
- end
13
-
14
- class << self
15
- def from(artifact_base_uri, artifact_element)
16
- attributes = {
17
- :base_uri => artifact_base_uri,
18
- :src => artifact_element.attributes['src'].value,
19
- :dest => artifact_element.attributes['dest'].value,
20
- :artifact_type => artifact_element.attributes['type'].value,
21
- }
22
-
23
- self.new(attributes)
24
- end
25
- end
26
- end
27
- end
@@ -1,42 +0,0 @@
1
- module GoApiClient
2
- module Atom
3
- class Author
4
-
5
- attr_accessor :name, :email, :uri
6
-
7
- include GoApiClient::Helpers::SimpleAttributesSupport
8
-
9
- def initialize(root, attributes={})
10
- @root = root
11
- super(attributes)
12
- end
13
-
14
- def parse!
15
- self.name = @root.xpath('xmlns:name').first.content
16
- self.email = @root.xpath('xmlns:email').first.content rescue nil
17
- self.uri = @root.xpath('xmlns:uri').first.content rescue nil
18
-
19
- if email.nil? || email.empty?
20
- if name =~ /(.*) <(.+?)>/
21
- self.name, self.email = $1, $2
22
- end
23
- end
24
-
25
- @root = nil
26
- self
27
- end
28
-
29
- def ==(other)
30
- other && self.class.equal?(other.class) &&
31
- name == other.name &&
32
- email == other.email &&
33
- uri == other.uri
34
- end
35
-
36
- def hash
37
- self.class.hash ^ name.hash ^ email.hash ^ uri.hash
38
- end
39
-
40
- end
41
- end
42
- end
@@ -1,34 +0,0 @@
1
- require 'time'
2
-
3
- module GoApiClient
4
- module Atom
5
- class Entry
6
-
7
- attr_accessor :authors, :id, :updated_at, :title, :stage_href, :pipelines
8
-
9
- include GoApiClient::Helpers::SimpleAttributesSupport
10
-
11
- def initialize(root, attributes={})
12
- @root = root
13
- super(attributes)
14
- end
15
-
16
- def parse!
17
- self.updated_at = Time.parse(@root.xpath('xmlns:updated').first.content).utc
18
- self.id = @root.xpath('xmlns:id').first.content
19
- self.title = @root.xpath('xmlns:title').first.content
20
- self.stage_href = @root.
21
- xpath("xmlns:link[@type='application/vnd.go+xml' and @rel='alternate']").
22
- first.
23
- attributes["href"].value
24
-
25
- self.authors = @root.xpath('xmlns:author').collect do |author|
26
- Author.new(author).parse!
27
- end
28
- @root = nil
29
- self
30
- end
31
- end
32
- end
33
- end
34
-
@@ -1,40 +0,0 @@
1
- module GoApiClient
2
- module Atom
3
- class Feed
4
- attr_accessor :feed_pages, :entries
5
-
6
- def initialize(atom_feed_url, last_entry_id=nil)
7
- @atom_feed_url = atom_feed_url
8
- @last_entry_id = last_entry_id
9
- end
10
-
11
- def fetch!(http_fetcher = HttpFetcher.new)
12
- self.entries = []
13
- feed_url = @atom_feed_url
14
-
15
- begin
16
- doc = Nokogiri::XML(http_fetcher.get!(feed_url))
17
- feed_page = GoApiClient::Atom::FeedPage.new(doc.root).parse!
18
-
19
- self.entries += if feed_page.contains_entry?(@last_entry_id)
20
- feed_page.entries_after(@last_entry_id)
21
- else
22
- feed_page.entries
23
- end
24
- feed_url = feed_page.next_page
25
- end while feed_page.next_page && !feed_page.contains_entry?(@last_entry_id)
26
- self
27
- end
28
-
29
- def fetch_all!(http_fetcher = HttpFetcher.new)
30
- begin
31
- doc = Nokogiri::XML(http_fetcher.get!(@atom_feed_url))
32
- doc.css("pipeline").inject({}) do |hash, feed|
33
- hash[feed.attr("href")] = GoApiClient::Atom::Feed.new(feed.attr("href")).fetch!
34
- hash
35
- end
36
- end
37
- end
38
- end
39
- end
40
- end
@@ -1,49 +0,0 @@
1
- require 'time'
2
- module GoApiClient
3
- module Atom
4
- class FeedPage
5
- attr_accessor :updated_at, :next_page, :url, :entries
6
-
7
- include GoApiClient::Helpers::SimpleAttributesSupport
8
-
9
- def initialize(root, attributes={})
10
- @root = root
11
- super(attributes)
12
- end
13
-
14
- def parse!
15
- self.updated_at = Time.parse(@root.xpath('xmlns:updated').first.content).utc
16
- self.next_page = href_from(@root.xpath("xmlns:link[@rel='next']"))
17
- self.url = href_from(@root.xpath("xmlns:link[@rel='self']"))
18
- self.entries = @root.xpath("xmlns:entry").collect do |entry|
19
- Entry.new(entry).parse!
20
- end
21
- @root = nil
22
- self
23
- end
24
-
25
- def entries_after(entry_or_id)
26
- index = if entry_or_id.is_a?(String)
27
- entries.find_index {|e| e.id == entry_or_id}
28
- else
29
- entries.find_index {|e| e == entry_or_id}
30
- end
31
-
32
- index.zero? ? [] : entries[0..index-1]
33
- end
34
-
35
- def contains_entry?(entry_or_id)
36
- if entry_or_id.is_a?(String)
37
- entries.find {|e| e.id == entry_or_id}
38
- else
39
- entries.include?(entry_or_id)
40
- end
41
- end
42
-
43
- private
44
- def href_from(xml)
45
- xml.first.attribute('href').value unless xml.empty?
46
- end
47
- end
48
- end
49
- end
@@ -1,4 +0,0 @@
1
- require 'go_api_client/atom/author'
2
- require 'go_api_client/atom/entry'
3
- require 'go_api_client/atom/feed_page'
4
- require 'go_api_client/atom/feed'
@@ -1,30 +0,0 @@
1
- module GoApiClient
2
- class Commit
3
-
4
- attr_accessor :revision, :message, :time, :user
5
-
6
- include GoApiClient::Helpers::SimpleAttributesSupport
7
-
8
- def initialize(root, attributes={})
9
- @root = root
10
- super(attributes)
11
- end
12
-
13
- def parse!
14
- self.revision = @root.xpath("./revision").first.content
15
- self.message = @root.xpath("./message").first.content
16
- self.time = Time.parse(@root.xpath("./checkinTime").first.content).utc
17
- self.user = User.parse(@root.xpath("./user").first.content)
18
- @root = nil
19
- self
20
- end
21
-
22
- def to_s
23
- "commit #{revision}
24
- Author: #{user}
25
- Date: #{time}
26
-
27
- #{message.each_line.collect {|l| " #{l}"}}"
28
- end
29
- end
30
- end
@@ -1,11 +0,0 @@
1
- module GoApiClient
2
- module Helpers
3
- module SimpleAttributesSupport
4
- def initialize(attributes={})
5
- attributes.each do |name, value|
6
- send("#{name}=", value) unless value.to_s.empty?
7
- end
8
- end
9
- end
10
- end
11
- end
@@ -1 +0,0 @@
1
- require 'go_api_client/helpers/simple_attribute_support'
@@ -1,68 +0,0 @@
1
- module GoApiClient
2
- class Job
3
- attr_accessor :artifacts_uri, :console_log_url, :url, :identifier, :http_fetcher, :name, :artifacts
4
-
5
- PROPERTIES = {
6
- :duration => :cruise_job_duration,
7
- :result => :cruise_job_result,
8
- :scheduled => :cruise_timestamp_01_scheduled,
9
- :assigned => :cruise_timestamp_02_assigned,
10
- :preparing => :cruise_timestamp_03_preparing,
11
- :building => :cruise_timestamp_04_building,
12
- :completing => :cruise_timestamp_05_completing,
13
- :completed => :cruise_timestamp_06_completed,
14
- }
15
-
16
- attr_accessor *PROPERTIES.keys
17
-
18
- include GoApiClient::Helpers::SimpleAttributesSupport
19
-
20
- def initialize(root, attributes={})
21
- @root = root
22
- super(attributes)
23
- end
24
-
25
- class << self
26
- def from(url, attributes = {})
27
- attributes[:http_fetcher] ||= GoApiClient::HttpFetcher.new
28
- doc = Nokogiri::XML(attributes[:http_fetcher].get!(url))
29
- self.new(doc.root, attributes).parse!
30
- end
31
- end
32
-
33
- def parse!
34
- self.artifacts_uri = @root.xpath("./artifacts").first.attributes["baseUri"].value
35
- self.url = href_from(@root.xpath("./link[@rel='self']"))
36
- self.identifier = @root.xpath('./id').first.content
37
- self.name = @root.attributes['name'].value
38
- self.artifacts = @root.xpath("./artifacts/artifact").collect do |artifact_element|
39
- Artifact.from(self.artifacts_uri, artifact_element)
40
- end
41
-
42
- PROPERTIES.each do |variable, property_name|
43
- property_value = @root.xpath("./properties/property[@name='#{property_name}']").first.content rescue nil
44
-
45
- next if property_value.nil? || property_value.empty?
46
-
47
- if property_name =~ /timestamp/
48
- property_value = Time.parse(property_value).utc
49
- elsif property_value =~ /^\d+$/
50
- property_value = property_value.to_i
51
- end
52
- self.send("#{variable}=", property_value)
53
- end
54
-
55
- @root = nil
56
- self
57
- end
58
-
59
- def console_log_url
60
- @console_log_url ||= "#{artifacts_uri}/cruise-output/console.log"
61
- end
62
-
63
- private
64
- def href_from(xml)
65
- xml.first.attribute('href').value unless xml.empty?
66
- end
67
- end
68
- end