go_api_client 0.0.8 → 0.3.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.
- data/.gitignore +7 -39
- data/.rvmrc +1 -0
- data/Gemfile.lock +12 -2
- data/Rakefile +8 -9
- data/go_api_client.gemspec +5 -2
- data/lib/go_api_client/atom/author.rb +25 -1
- data/lib/go_api_client/atom/entry.rb +9 -3
- data/lib/go_api_client/atom/feed.rb +19 -14
- data/lib/go_api_client/atom/feed_page.rb +49 -0
- data/lib/go_api_client/atom.rb +1 -0
- data/lib/go_api_client/commit.rb +30 -0
- data/lib/go_api_client/helpers/simple_attribute_support.rb +11 -0
- data/lib/go_api_client/helpers.rb +1 -0
- data/lib/go_api_client/http_fetcher.rb +41 -0
- data/lib/go_api_client/job.rb +56 -10
- data/lib/go_api_client/pipeline.rb +36 -12
- data/lib/go_api_client/stage.rb +43 -14
- data/lib/go_api_client/user.rb +36 -0
- data/lib/go_api_client/version.rb +7 -1
- data/lib/go_api_client.rb +45 -12
- data/test/fixtures/building/job_1.xml +41 -0
- data/test/fixtures/building/job_2.xml +43 -0
- data/test/fixtures/building/job_3.xml +40 -0
- data/test/fixtures/building/job_4.xml +40 -0
- data/test/fixtures/building/pipeline_1.xml +45 -0
- data/test/fixtures/building/pipeline_2.xml +39 -0
- data/test/fixtures/building/pipeline_3.xml +71 -0
- data/test/fixtures/building/stages.xml +180 -0
- data/test/fixtures/building/stages_1.xml +16 -0
- data/test/fixtures/building/stages_2.xml +16 -0
- data/test/fixtures/building/stages_3.xml +16 -0
- data/test/fixtures/building/stages_4.xml +16 -0
- data/test/fixtures/jobs_1.xml +3 -3
- data/test/fixtures/jobs_with_no_properties.xml +42 -0
- data/test/fixtures/ordering/go/api/jobs/1.xml +29 -0
- data/test/fixtures/ordering/go/api/jobs/10.xml +31 -0
- data/test/fixtures/ordering/go/api/jobs/2.xml +29 -0
- data/test/fixtures/ordering/go/api/jobs/3.xml +29 -0
- data/test/fixtures/ordering/go/api/jobs/4.xml +29 -0
- data/test/fixtures/ordering/go/api/jobs/5.xml +29 -0
- data/test/fixtures/ordering/go/api/jobs/6.xml +29 -0
- data/test/fixtures/ordering/go/api/jobs/7.xml +31 -0
- data/test/fixtures/ordering/go/api/jobs/8.xml +31 -0
- data/test/fixtures/ordering/go/api/jobs/9.xml +31 -0
- data/test/fixtures/ordering/go/api/pipelines/defaultPipeline/1.xml +31 -0
- data/test/fixtures/ordering/go/api/pipelines/defaultPipeline/2.xml +26 -0
- data/test/fixtures/ordering/go/api/pipelines/defaultPipeline/3.xml +26 -0
- data/test/fixtures/ordering/go/api/pipelines/defaultPipeline/4.xml +27 -0
- data/test/fixtures/ordering/go/api/pipelines/defaultPipeline/5.xml +33 -0
- data/test/fixtures/ordering/go/api/pipelines/defaultPipeline/stages.xml +255 -0
- data/test/fixtures/ordering/go/api/stages/1.xml +14 -0
- data/test/fixtures/ordering/go/api/stages/10.xml +14 -0
- data/test/fixtures/ordering/go/api/stages/2.xml +14 -0
- data/test/fixtures/ordering/go/api/stages/3.xml +14 -0
- data/test/fixtures/ordering/go/api/stages/4.xml +14 -0
- data/test/fixtures/ordering/go/api/stages/5.xml +14 -0
- data/test/fixtures/ordering/go/api/stages/6.xml +14 -0
- data/test/fixtures/ordering/go/api/stages/7.xml +14 -0
- data/test/fixtures/ordering/go/api/stages/8.xml +14 -0
- data/test/fixtures/ordering/go/api/stages/9.xml +14 -0
- data/test/fixtures/pagination/stages.xml +636 -0
- data/test/fixtures/pagination/stages_before_7916973.xml +615 -0
- data/test/fixtures/pagination/stages_before_7959831.xml +615 -0
- data/test/fixtures/pipelines_1.xml +8 -1
- data/test/fixtures/stages.xml +1 -1
- data/test/go_api_client/atom/author_test.rb +27 -0
- data/test/go_api_client/atom/entry_test.rb +27 -0
- data/test/go_api_client/atom/feed_page_test.rb +41 -0
- data/test/go_api_client/atom/feed_test.rb +25 -0
- data/test/go_api_client/building_test.rb +38 -0
- data/test/go_api_client/commit_test.rb +38 -0
- data/test/go_api_client/job_test.rb +42 -0
- data/test/go_api_client/pipeline_test.rb +63 -16
- data/test/go_api_client/stage_test.rb +48 -14
- data/test/go_api_client/user_test.rb +27 -0
- data/test/test_helper.rb +19 -3
- metadata +173 -10
- data/bin/go_api_client +0 -3
    
        data/.gitignore
    CHANGED
    
    | @@ -1,40 +1,8 @@ | |
| 1 | 
            -
             | 
| 2 | 
            -
             | 
| 3 | 
            -
             | 
| 4 | 
            -
             | 
| 5 | 
            -
             | 
| 6 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
            *.so
         | 
| 9 | 
            -
             | 
| 10 | 
            -
            # Packages #
         | 
| 11 | 
            -
            ############
         | 
| 12 | 
            -
            # it's better to unpack these files and commit the raw source
         | 
| 13 | 
            -
            # git has its own built in compression methods
         | 
| 14 | 
            -
            *.7z
         | 
| 15 | 
            -
            *.dmg
         | 
| 16 | 
            -
            *.gz
         | 
| 17 | 
            -
            *.iso
         | 
| 18 | 
            -
            *.jar
         | 
| 19 | 
            -
            *.rar
         | 
| 20 | 
            -
            *.tar
         | 
| 21 | 
            -
            *.zip
         | 
| 22 | 
            -
             | 
| 23 | 
            -
            # Logs and databases #
         | 
| 24 | 
            -
            ######################
         | 
| 25 | 
            -
            *.log
         | 
| 26 | 
            -
            *.sql
         | 
| 27 | 
            -
            *.sqlite
         | 
| 28 | 
            -
             | 
| 29 | 
            -
            # OS generated files #
         | 
| 30 | 
            -
            ######################
         | 
| 31 | 
            -
            .DS_Store*
         | 
| 32 | 
            -
            ehthumbs.db
         | 
| 33 | 
            -
            Icon?
         | 
| 34 | 
            -
            Thumbs.db
         | 
| 35 | 
            -
             | 
| 36 | 
            -
             | 
| 37 | 
            -
             | 
| 38 | 
            -
            \#*\#
         | 
| 39 | 
            -
            .\#*
         | 
| 1 | 
            +
            coverage
         | 
| 2 | 
            +
            .bundle
         | 
| 3 | 
            +
            bundle/
         | 
| 4 | 
            +
            pkg/*
         | 
| 5 | 
            +
            /tmp/
         | 
| 6 | 
            +
            /vendor/ruby
         | 
| 7 | 
            +
            .idea/*
         | 
| 40 8 | 
             
            TAGS
         | 
    
        data/.rvmrc
    ADDED
    
    | @@ -0,0 +1 @@ | |
| 1 | 
            +
            rvm ruby-1.9.2-p290@go-api-client
         | 
    
        data/Gemfile.lock
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            PATH
         | 
| 2 2 | 
             
              remote: .
         | 
| 3 3 | 
             
              specs:
         | 
| 4 | 
            -
                go_api_client (0.0 | 
| 4 | 
            +
                go_api_client (0.3.0)
         | 
| 5 5 | 
             
                  nokogiri
         | 
| 6 6 |  | 
| 7 7 | 
             
            GEM
         | 
| @@ -9,7 +9,14 @@ GEM | |
| 9 9 | 
             
              specs:
         | 
| 10 10 | 
             
                addressable (2.2.7)
         | 
| 11 11 | 
             
                crack (0.3.1)
         | 
| 12 | 
            -
                 | 
| 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)
         | 
| 13 20 | 
             
                webmock (1.8.0)
         | 
| 14 21 | 
             
                  addressable (>= 2.2.7)
         | 
| 15 22 | 
             
                  crack (>= 0.1.7)
         | 
| @@ -19,4 +26,7 @@ PLATFORMS | |
| 19 26 |  | 
| 20 27 | 
             
            DEPENDENCIES
         | 
| 21 28 | 
             
              go_api_client!
         | 
| 29 | 
            +
              rake
         | 
| 30 | 
            +
              simplecov
         | 
| 31 | 
            +
              test-unit
         | 
| 22 32 | 
             
              webmock
         | 
    
        data/Rakefile
    CHANGED
    
    | @@ -1,13 +1,12 @@ | |
| 1 1 | 
             
            require "bundler/gem_tasks"
         | 
| 2 2 | 
             
            require 'rake/testtask'
         | 
| 3 3 |  | 
| 4 | 
            -
             | 
| 5 | 
            -
             | 
| 6 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
            end
         | 
| 11 | 
            -
             | 
| 12 | 
            -
            task :default => :test
         | 
| 4 | 
            +
            desc "Run all tests"
         | 
| 5 | 
            +
            Rake::TestTask.new do |t|
         | 
| 6 | 
            +
               t.libs << "test"
         | 
| 7 | 
            +
               t.test_files = FileList['test/**/*test.rb']
         | 
| 8 | 
            +
               t.verbose = true
         | 
| 9 | 
            +
             end
         | 
| 13 10 |  | 
| 11 | 
            +
            desc "the default task"
         | 
| 12 | 
            +
            task :default => :test
         | 
    
        data/go_api_client.gemspec
    CHANGED
    
    | @@ -4,7 +4,7 @@ require "go_api_client/version" | |
| 4 4 |  | 
| 5 5 | 
             
            Gem::Specification.new do |s|
         | 
| 6 6 | 
             
              s.name        = "go_api_client"
         | 
| 7 | 
            -
              s.version     = GoApiClient::VERSION
         | 
| 7 | 
            +
              s.version     = GoApiClient::Version::VERSION
         | 
| 8 8 | 
             
              s.authors     = ["Nikhil Mungel", "Ketan Padegaonkar", "Shishir Das"]
         | 
| 9 9 | 
             
              s.email       = ["hyfather@gmail.com", "KetanPadegaonkar@gmail.com", "shishir.das@gmail.com"]
         | 
| 10 10 | 
             
              s.homepage    = "https://github.com/ThoughtWorksInc/go-api-client"
         | 
| @@ -13,13 +13,16 @@ Gem::Specification.new do |s| | |
| 13 13 |  | 
| 14 14 | 
             
              s.rubyforge_project = "go_api_client"
         | 
| 15 15 |  | 
| 16 | 
            -
              s.files         = `git ls-files`.split("\n")
         | 
| 16 | 
            +
              s.files         = `git ls-files`.split("\n") - `git ls-files -- vendor/cache`.split("\n")
         | 
| 17 17 | 
             
              s.test_files    = `git ls-files -- {test,spec,features}/*`.split("\n")
         | 
| 18 18 | 
             
              s.executables   = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
         | 
| 19 19 | 
             
              s.require_paths = ["lib"]
         | 
| 20 20 |  | 
| 21 21 | 
             
              # specify any dependencies here; for example:
         | 
| 22 22 | 
             
              s.add_development_dependency "webmock"
         | 
| 23 | 
            +
              s.add_development_dependency "simplecov"
         | 
| 24 | 
            +
              s.add_development_dependency 'rake'
         | 
| 25 | 
            +
              s.add_development_dependency 'test-unit'
         | 
| 23 26 |  | 
| 24 27 | 
             
              s.add_runtime_dependency "nokogiri"
         | 
| 25 28 | 
             
            end
         | 
| @@ -1,18 +1,42 @@ | |
| 1 1 | 
             
            module GoApiClient
         | 
| 2 2 | 
             
              module Atom
         | 
| 3 3 | 
             
                class Author
         | 
| 4 | 
            +
             | 
| 4 5 | 
             
                  attr_accessor :name, :email, :uri
         | 
| 5 | 
            -
             | 
| 6 | 
            +
             | 
| 7 | 
            +
                  include GoApiClient::Helpers::SimpleAttributesSupport
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                  def initialize(root, attributes={})
         | 
| 6 10 | 
             
                    @root = root
         | 
| 11 | 
            +
                    super(attributes)
         | 
| 7 12 | 
             
                  end
         | 
| 8 13 |  | 
| 9 14 | 
             
                  def parse!
         | 
| 10 15 | 
             
                    self.name     = @root.xpath('xmlns:name').first.content
         | 
| 11 16 | 
             
                    self.email    = @root.xpath('xmlns:email').first.content rescue nil
         | 
| 12 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 | 
            +
             | 
| 13 25 | 
             
                    @root = nil
         | 
| 14 26 | 
             
                    self
         | 
| 15 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 | 
            +
             | 
| 16 40 | 
             
                end
         | 
| 17 41 | 
             
              end
         | 
| 18 42 | 
             
            end
         | 
| @@ -1,20 +1,26 @@ | |
| 1 | 
            +
            require 'time'
         | 
| 2 | 
            +
             | 
| 1 3 | 
             
            module GoApiClient
         | 
| 2 4 | 
             
              module Atom
         | 
| 3 5 | 
             
                class Entry
         | 
| 6 | 
            +
             | 
| 4 7 | 
             
                  attr_accessor :authors, :id, :updated_at, :title, :stage_href, :pipelines
         | 
| 5 8 |  | 
| 6 | 
            -
                   | 
| 9 | 
            +
                  include GoApiClient::Helpers::SimpleAttributesSupport
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                  def initialize(root, attributes={})
         | 
| 7 12 | 
             
                    @root = root
         | 
| 13 | 
            +
                    super(attributes)
         | 
| 8 14 | 
             
                  end
         | 
| 9 15 |  | 
| 10 16 | 
             
                  def parse!
         | 
| 11 | 
            -
                    self.updated_at = @root.xpath('xmlns:updated').first.content
         | 
| 17 | 
            +
                    self.updated_at = Time.parse(@root.xpath('xmlns:updated').first.content).utc
         | 
| 12 18 | 
             
                    self.id         = @root.xpath('xmlns:id').first.content
         | 
| 13 19 | 
             
                    self.title      = @root.xpath('xmlns:title').first.content
         | 
| 14 20 | 
             
                    self.stage_href = @root.
         | 
| 15 21 | 
             
                      xpath("xmlns:link[@type='application/vnd.go+xml' and  @rel='alternate']").
         | 
| 16 22 | 
             
                      first.
         | 
| 17 | 
            -
                      attributes["href"]
         | 
| 23 | 
            +
                      attributes["href"].value
         | 
| 18 24 |  | 
| 19 25 | 
             
                    self.authors    = @root.xpath('xmlns:author').collect do |author|
         | 
| 20 26 | 
             
                      Author.new(author).parse!
         | 
| @@ -1,24 +1,29 @@ | |
| 1 1 | 
             
            module GoApiClient
         | 
| 2 2 | 
             
              module Atom
         | 
| 3 3 | 
             
                class Feed
         | 
| 4 | 
            -
                  attr_accessor : | 
| 4 | 
            +
                  attr_accessor :feed_pages, :entries
         | 
| 5 5 |  | 
| 6 | 
            -
                  def initialize( | 
| 7 | 
            -
                    @ | 
| 6 | 
            +
                  def initialize(atom_feed_url, last_entry_id=nil)
         | 
| 7 | 
            +
                    @atom_feed_url = atom_feed_url
         | 
| 8 | 
            +
                    @last_entry_id = last_entry_id
         | 
| 8 9 | 
             
                  end
         | 
| 9 10 |  | 
| 10 | 
            -
                  def  | 
| 11 | 
            -
                    self. | 
| 12 | 
            -
                     | 
| 13 | 
            -
                    self.url        = href_from(@root.xpath("xmlns:link[@rel='self']"))
         | 
| 14 | 
            -
                    self.entries    = @root.xpath("xmlns:entry").collect do |entry|
         | 
| 15 | 
            -
                      Entry.new(entry).parse!
         | 
| 16 | 
            -
                    end
         | 
| 17 | 
            -
                    self
         | 
| 18 | 
            -
                  end
         | 
| 11 | 
            +
                  def fetch!(http_fetcher = HttpFetcher.new)
         | 
| 12 | 
            +
                    self.entries = []
         | 
| 13 | 
            +
                    feed_url = @atom_feed_url
         | 
| 19 14 |  | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 15 | 
            +
                    begin
         | 
| 16 | 
            +
                      doc = Nokogiri::XML(http_fetcher.get_response_body(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
         | 
| 22 27 | 
             
                  end
         | 
| 23 28 | 
             
                end
         | 
| 24 29 | 
             
              end
         | 
| @@ -0,0 +1,49 @@ | |
| 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
         | 
    
        data/lib/go_api_client/atom.rb
    CHANGED
    
    
| @@ -0,0 +1,30 @@ | |
| 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
         | 
| @@ -0,0 +1 @@ | |
| 1 | 
            +
            require 'go_api_client/helpers/simple_attribute_support'
         | 
| @@ -0,0 +1,41 @@ | |
| 1 | 
            +
            require 'net/http'
         | 
| 2 | 
            +
            require 'net/https'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            module GoApiClient
         | 
| 5 | 
            +
              class HttpFetcher
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                def initialize(options={})
         | 
| 8 | 
            +
                  @username = options[:username]
         | 
| 9 | 
            +
                  @password = options[:password]
         | 
| 10 | 
            +
                end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                def get(url, options={})
         | 
| 13 | 
            +
                  uri = URI.parse(url)
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                  password = options[:password] || uri.password || @password
         | 
| 16 | 
            +
                  username = options[:username] || uri.user     || @username
         | 
| 17 | 
            +
                  params   = options[:params]   || {}
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                  uri.query = URI.encode_www_form(params) if params.any?
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                  http = Net::HTTP.new(uri.host, uri.port)
         | 
| 22 | 
            +
                  http.use_ssl = uri.scheme == 'https'
         | 
| 23 | 
            +
                  
         | 
| 24 | 
            +
                  res = http.start do |http|
         | 
| 25 | 
            +
                    req = Net::HTTP::Get.new(uri.request_uri)
         | 
| 26 | 
            +
                    req.basic_auth(username, password) if username || password
         | 
| 27 | 
            +
                    http.request(req)
         | 
| 28 | 
            +
                  end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                  case res
         | 
| 31 | 
            +
                  when Net::HTTPSuccess
         | 
| 32 | 
            +
                    return res
         | 
| 33 | 
            +
                  end
         | 
| 34 | 
            +
                  res.error!
         | 
| 35 | 
            +
                end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                def get_response_body(url, options={})
         | 
| 38 | 
            +
                  get(url, options).body
         | 
| 39 | 
            +
                end
         | 
| 40 | 
            +
              end
         | 
| 41 | 
            +
            end
         | 
    
        data/lib/go_api_client/job.rb
    CHANGED
    
    | @@ -1,18 +1,64 @@ | |
| 1 1 | 
             
            module GoApiClient
         | 
| 2 2 | 
             
              class Job
         | 
| 3 | 
            -
                 | 
| 4 | 
            -
             | 
| 5 | 
            -
                 | 
| 6 | 
            -
                   | 
| 7 | 
            -
                   | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 3 | 
            +
                attr_accessor :artifacts_uri, :console_log_url, :url, :identifier, :http_fetcher, :name
         | 
| 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_response_body(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 | 
            +
                  PROPERTIES.each do |variable, property_name|
         | 
| 39 | 
            +
                    property_value = @root.xpath("./properties/property[@name='#{property_name}']").first.content rescue nil
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                    next if property_value.nil? || property_value.empty?
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                    if property_name =~ /timestamp/
         | 
| 44 | 
            +
                      property_value = Time.parse(property_value).utc
         | 
| 45 | 
            +
                    elsif property_value =~ /^\d+$/
         | 
| 46 | 
            +
                      property_value = property_value.to_i
         | 
| 47 | 
            +
                    end
         | 
| 48 | 
            +
                    self.send("#{variable}=", property_value)
         | 
| 10 49 | 
             
                  end
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                  @root = nil
         | 
| 52 | 
            +
                  self
         | 
| 53 | 
            +
                end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                def console_log_url
         | 
| 56 | 
            +
                  @console_log_url ||= "#{artifacts_uri}/cruise-output/console.log"
         | 
| 11 57 | 
             
                end
         | 
| 12 58 |  | 
| 13 | 
            -
                 | 
| 14 | 
            -
             | 
| 15 | 
            -
                   | 
| 59 | 
            +
                private
         | 
| 60 | 
            +
                def href_from(xml)
         | 
| 61 | 
            +
                  xml.first.attribute('href').value unless xml.empty?
         | 
| 16 62 | 
             
                end
         | 
| 17 63 | 
             
              end
         | 
| 18 64 | 
             
            end
         | 
| @@ -1,24 +1,48 @@ | |
| 1 1 | 
             
            module GoApiClient
         | 
| 2 2 | 
             
              class Pipeline
         | 
| 3 | 
            -
                 | 
| 4 | 
            -
                attr_accessor :stages
         | 
| 3 | 
            +
                attr_accessor :url, :commits, :label, :counter, :authors, :stages, :name, :http_fetcher, :identifier, :schedule_time
         | 
| 5 4 |  | 
| 6 | 
            -
                 | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 5 | 
            +
                include GoApiClient::Helpers::SimpleAttributesSupport
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                def initialize(root, attributes={})
         | 
| 8 | 
            +
                  @root = root
         | 
| 9 | 
            +
                  super(attributes)
         | 
| 10 | 
            +
                end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                class << self
         | 
| 13 | 
            +
                  def from(url, attributes = {})
         | 
| 14 | 
            +
                    attributes[:http_fetcher] ||= GoApiClient::HttpFetcher.new
         | 
| 15 | 
            +
                    doc = Nokogiri::XML(attributes[:http_fetcher].get_response_body(url))
         | 
| 16 | 
            +
                    self.new(doc.root, attributes).parse!
         | 
| 17 | 
            +
                  end
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                def stages
         | 
| 21 | 
            +
                  @stages ||= []
         | 
| 9 22 | 
             
                end
         | 
| 10 23 |  | 
| 11 | 
            -
                def  | 
| 12 | 
            -
                   | 
| 13 | 
            -
                   | 
| 14 | 
            -
                   | 
| 15 | 
            -
                   | 
| 24 | 
            +
                def parse!
         | 
| 25 | 
            +
                  self.name       = @root.attributes["name"].value
         | 
| 26 | 
            +
                  self.label      = @root.attributes["label"].value
         | 
| 27 | 
            +
                  self.counter    = @root.attributes["counter"].value.to_i
         | 
| 28 | 
            +
                  self.url        = href_from(@root.xpath("./link[@rel='self']"))
         | 
| 29 | 
            +
                  self.identifier = @root.xpath("./id").first.content
         | 
| 30 | 
            +
                  self.schedule_time = Time.parse(@root.xpath('./scheduleTime').first.content).utc
         | 
| 31 | 
            +
                  self.commits    = @root.xpath('./materials/material[@type = "GitMaterial"]/modifications/changeset').collect do |changeset|
         | 
| 32 | 
            +
                    Commit.new(changeset).parse!
         | 
| 33 | 
            +
                  end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                  @root = nil
         | 
| 16 36 | 
             
                  self
         | 
| 17 37 | 
             
                end
         | 
| 18 38 |  | 
| 19 39 | 
             
                def authors
         | 
| 20 | 
            -
                  authors  | 
| 21 | 
            -
             | 
| 40 | 
            +
                  @authors ||= stages.first.authors
         | 
| 41 | 
            +
                end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                private
         | 
| 44 | 
            +
                def href_from(xml)
         | 
| 45 | 
            +
                  xml.first.attribute('href').value unless xml.empty?
         | 
| 22 46 | 
             
                end
         | 
| 23 47 |  | 
| 24 48 | 
             
              end
         | 
    
        data/lib/go_api_client/stage.rb
    CHANGED
    
    | @@ -1,28 +1,57 @@ | |
| 1 | 
            +
            require 'time'
         | 
| 1 2 | 
             
            module GoApiClient
         | 
| 2 3 | 
             
              class Stage
         | 
| 3 | 
            -
                attr_accessor :authors, : | 
| 4 | 
            +
                attr_accessor :authors, :url, :name, :result, :jobs, :pipeline, :completed_at, :pipeline_cache, :http_fetcher, :counter, :identifier
         | 
| 4 5 |  | 
| 5 | 
            -
                 | 
| 6 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
                  @ | 
| 6 | 
            +
                include GoApiClient::Helpers::SimpleAttributesSupport
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                def initialize(root, attributes={})
         | 
| 9 | 
            +
                  @root = root
         | 
| 10 | 
            +
                  super(attributes)
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                class << self
         | 
| 14 | 
            +
                  def from(url, attributes = {})
         | 
| 15 | 
            +
                    attributes[:http_fetcher] ||= GoApiClient::HttpFetcher.new
         | 
| 16 | 
            +
                    doc = Nokogiri::XML(attributes[:http_fetcher].get_response_body(url))
         | 
| 17 | 
            +
                    self.new(doc.root, attributes).parse!
         | 
| 18 | 
            +
                  end
         | 
| 9 19 | 
             
                end
         | 
| 10 20 |  | 
| 11 | 
            -
                def  | 
| 12 | 
            -
                   | 
| 13 | 
            -
                   | 
| 14 | 
            -
                   | 
| 15 | 
            -
                   | 
| 16 | 
            -
                   | 
| 21 | 
            +
                def parse!
         | 
| 22 | 
            +
                  self.name         = @root.attributes['name'].value
         | 
| 23 | 
            +
                  self.counter      = @root.attributes['counter'].value.to_i
         | 
| 24 | 
            +
                  self.url          = href_from(@root.xpath("./link[@rel='self']"))
         | 
| 25 | 
            +
                  self.result       = @root.xpath("./result").first.content
         | 
| 26 | 
            +
                  self.completed_at = Time.parse(@root.xpath("./updated").first.content).utc
         | 
| 27 | 
            +
                  self.jobs         = @root.xpath("./jobs/job").collect do |job_element|
         | 
| 28 | 
            +
                                        Job.from(job_element.attributes["href"].value, :http_fetcher => http_fetcher)
         | 
| 29 | 
            +
                                      end
         | 
| 30 | 
            +
                  self.identifier   = @root.xpath('./id').first.content
         | 
| 17 31 |  | 
| 18 | 
            -
                  pipeline_link | 
| 32 | 
            +
                  pipeline_link     = @root.xpath("./pipeline").first.attributes["href"].value
         | 
| 19 33 |  | 
| 20 | 
            -
                  pipeline = @ | 
| 34 | 
            +
                  pipeline = @pipeline_cache[pipeline_link] || Pipeline.from(pipeline_link, :http_fetcher => http_fetcher)
         | 
| 21 35 | 
             
                  pipeline.stages << self
         | 
| 22 36 |  | 
| 23 | 
            -
                   | 
| 37 | 
            +
                  self.pipeline_cache[pipeline_link] ||= pipeline
         | 
| 38 | 
            +
                  @root = nil
         | 
| 24 39 | 
             
                  self
         | 
| 25 40 | 
             
                end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                def failed?
         | 
| 43 | 
            +
                  "Failed" == @result
         | 
| 44 | 
            +
                end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                def passed?
         | 
| 47 | 
            +
                  !failed?
         | 
| 48 | 
            +
                end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                private
         | 
| 51 | 
            +
                def href_from(xml)
         | 
| 52 | 
            +
                  xml.first.attribute('href').value unless xml.empty?
         | 
| 53 | 
            +
                end
         | 
| 54 | 
            +
             | 
| 26 55 | 
             
              end
         | 
| 27 56 | 
             
            end
         | 
| 28 57 |  | 
| @@ -0,0 +1,36 @@ | |
| 1 | 
            +
            module GoApiClient
         | 
| 2 | 
            +
              class User
         | 
| 3 | 
            +
             | 
| 4 | 
            +
                attr_accessor :name, :email
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                def initialize(name, email)
         | 
| 7 | 
            +
                  @name  = name
         | 
| 8 | 
            +
                  @email = email
         | 
| 9 | 
            +
                end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                def ==(other)
         | 
| 12 | 
            +
                  other && self.class.equal?(other.class) &&
         | 
| 13 | 
            +
                  name == other.name &&
         | 
| 14 | 
            +
                  email == other.email
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                def hash
         | 
| 18 | 
            +
                  self.class.hash ^ name.hash ^ email.hash
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                def to_s
         | 
| 22 | 
            +
                  "#{name} <#{email}>"
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                def inspect
         | 
| 26 | 
            +
                  "User(#{to_s})"
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                class << self
         | 
| 30 | 
            +
                  def parse(str)
         | 
| 31 | 
            +
                    _, name, email = *str.match(/(.*) <(.+?)>/)
         | 
| 32 | 
            +
                    self.new(name.strip, email.strip)
         | 
| 33 | 
            +
                  end
         | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
              end
         | 
| 36 | 
            +
            end
         |