Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: benstein/ruby-pivotal-tracker
base: master
...
head fork: mcommons/ruby-pivotal-tracker
compare: master
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 3 files changed
  • 0 commit comments
  • 2 contributors
Commits on Dec 16, 2008
@benstein add the license c61a938
Commits on Dec 19, 2008
@benstein remove broken tests dfeb119
Commits on Jan 28, 2009
Kaspar Schiess + More complete conversion of stories to nested hashes. 13dd7b7
Showing with 63 additions and 77 deletions.
  1. +20 −0 MIT-LICENSE
  2. +43 −20 pivotal_tracker.rb
  3. +0 −57 pivotal_tracker_test.rb
View
20 MIT-LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2008 Mobile Commons
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
63 pivotal_tracker.rb
@@ -44,11 +44,7 @@ def stories
@stories = []
doc.search('stories > story').each do |story|
- @stories << {
- :id => story.at('id').innerHTML.to_i,
- :type => story.at('story_type').innerHTML,
- :name => story.at('name').innerHTML
- }
+ @stories << story_to_hash(story)
end
@stories
end
@@ -74,11 +70,7 @@ def find(filters = {})
@stories = []
doc.search('stories > story').each do |story|
- @stories << {
- :id => story.at('id').innerHTML.to_i,
- :type => story.at('story_type').innerHTML,
- :name => story.at('name').innerHTML
- }
+ @stories << story_to_hash(story)
end
@stories
end
@@ -159,23 +151,54 @@ def remove_xml_tags(xml)
def net_http(uri)
h = Net::HTTP.new(uri.host, uri.port)
h.use_ssl = @ssl
+ h.verify_mode = OpenSSL::SSL::VERIFY_NONE
h
end
def story_xml_to_hash(xml)
doc = Hpricot(xml).at('story')
- { :id => doc.at('id').innerHTML.to_i,
- :story_type => doc.at('story_type').innerHTML,
- :name => doc.at('name').innerHTML,
- :estimate => doc.at('estimate').innerHTML,
- :current_state => doc.at('current_state').innerHTML,
- :description => doc.at('description').innerHTML,
- :url => doc.at('url').innerHTML
- :requested_by => doc.at('requested_by').innerHTML.to_i,
- :created_at => doc.at('created_at').innerHTML.to_i
- }
+ story_to_hash(doc)
end
+ # Converts a story xml element to a hash.
+ #
+ def story_to_hash(story)
+ container_list_to_hash(story.containers)
+ end
+
+ # Converts a list of hpricot containers to either :key => value pairs or
+ # to :key => { ... } pairs, depending on whether elements are leaf nodes.
+ #
+ def container_list_to_hash(containers)
+ hash = {}
+ containers.each do |container|
+ value = nil
+
+ if container.containers.empty?
+ # terminal element, add to hash
+ value = cast(container['type'], container.innerHTML)
+ else
+ # recurse
+ value = container_list_to_hash(container.containers)
+ end
+
+ name = container.name
+ hash[name.to_sym] = value
+ end
+
+ hash
+ end
+
+ # Casts xml type to ruby type.
+ #
+ def cast(type, value)
+ case type
+ when 'integer'
+ Integer(value)
+ else
+ value
+ end
+ end
end
class TrackerException < Exception
View
57 pivotal_tracker_test.rb
@@ -1,57 +0,0 @@
-require 'pivotal_tracker'
-require 'test/unit'
-
-class PivotalTrackerTest < Test::Unit::TestCase
-
- def setup
- @tracker = Tracker.new
- end
-
- def test_assert_stories_return
- assert_equal 3, @tracker.stories.size
- end
-
- def test_assert_project_response
- project = @tracker.project
- assert_equal "Factory Test", project[:name]
- assert_equal "1", project[:iteration_length]
- end
-
- def test_find_without_filters
- result = @tracker.find
- assert_equal @tracker.stories.size, result.size
- end
-
- def test_find_with_filters
- result = @tracker.find :name => 'Create another one'
- assert_equal result[0][:name], 'Create another one'
- end
-
- def test_assert_story_creation
- current_size = @tracker.stories.size
- story = {
- :name => 'Create another one',
- :story_type => "feature",
- :requested_by => "Justin Smestad"
- }
- @tracker.create_story(story)
- assert_equal (current_size + 1), @tracker.stories.size
- end
-
- def test_story_updates
- story = {
- :id => 272626,
- :name => 'This has changed'
- }
- @tracker.update_story(story)
- assert_equal @tracker.find_story(story[:id])[:name], story[:name]
- end
-
- def test_story_deletion
- current_size = @tracker.stories.size
- id = @tracker.stories[0][:id]
- @tracker.delete_story(id)
- assert_equal (current_size - 1), @tracker.stories.size
- end
-
-end

No commit comments for this range

Something went wrong with that request. Please try again.