Permalink
Browse files

creating the class who talks with jenkins

  • Loading branch information...
1 parent 8797db0 commit 76541588b06ad18c35994db6f11d066c92efdc02 @BrunoGrasselli committed Feb 5, 2012
Showing with 76 additions and 4 deletions.
  1. +1 −0 .gitignore
  2. +2 −3 ci_tray.gemspec
  3. +1 −1 lib/ci_tray.rb
  4. +32 −0 lib/ci_tray/jenkins.rb
  5. +38 −0 spec/jenkins_spec.rb
  6. +2 −0 spec/spec_helper.rb
View
@@ -2,3 +2,4 @@
.bundle
Gemfile.lock
pkg/*
+*.sw[op]
View
@@ -18,7 +18,6 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
- # specify any dependencies here; for example:
- s.add_development_dependency "rspec", "2.8.0"
- # s.add_runtime_dependency "rest-client"
+ s.add_development_dependency "rspec", "~>2.8.0"
+ s.add_development_dependency "webmock", "~>1.7.10"
end
View
@@ -1,5 +1,5 @@
require "ci_tray/version"
+require "ci_tray/jenkins"
module CiTray
- # Your code goes here...
end
@@ -0,0 +1,32 @@
+require 'open-uri'
+require 'json'
+
+class CiTray::Jenkins
+ def initialize(options)
+ @address = options[:address]
+ end
+
+ def jobs
+ jenkins_response['jobs'].map do |job|
+ simbolize_keys! job
+ end
+ end
+
+ private
+
+ def jenkins_response
+ response_body = open api_address
+ JSON.parse response_body.read
+ end
+
+ def simbolize_keys!(hash)
+ hash.keys.each do |key|
+ hash[key.to_sym] = hash.delete(key)
+ end
+ hash
+ end
+
+ def api_address
+ "#{@address}/api/json"
+ end
+end
View
@@ -0,0 +1,38 @@
+require 'spec_helper'
+
+describe CiTray::Jenkins do
+ describe "#jobs" do
+ before :each do
+ stub_request(:get, "http://test.jenkins.org/api/json").to_return :body => {
+ jobs: [
+ {
+ name: "job_one",
+ url: "http://test.jenkins.org/job/job_one/",
+ color: "red"
+ },
+ {
+ name: "job_two",
+ url: "http://test.jenkins.org/job/job_two/",
+ color: "blue"
+ }
+ ]
+ }.to_json
+ end
+
+ subject do
+ described_class.new(:address => "http://test.jenkins.org").jobs
+ end
+
+ it "should access jenkins api and return the job names" do
+ subject.map{|j| j[:name]}.should eq %w{job_one job_two}
+ end
+
+ it "should access jenkins api and return the job colors" do
+ subject.map{|j| j[:color]}.should eq %w{red blue}
+ end
+
+ it "should access jenkins api and return the job urls" do
+ subject.map{|j| j[:url]}.should eq %w{http://test.jenkins.org/job/job_one/ http://test.jenkins.org/job/job_two/}
+ end
+ end
+end
View
@@ -0,0 +1,2 @@
+require "ci_tray"
+require "webmock/rspec"

0 comments on commit 7654158

Please sign in to comment.