Skip to content

Commit

Permalink
Merge pull request #16 from AlfonsoUceda/master
Browse files Browse the repository at this point in the history
Support post operation
  • Loading branch information
forest committed Nov 8, 2014
2 parents c7e606a + 12c3cdd commit 9abe8ba
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ project.stories # Get
project.stories(with_state: :unscheduled, limit: 10) # Get 10 unscheduled stories for a project
project.stories(filter: 'requester:OWK label:"jedi stuff"') # Get all stories that match the given filters
project.story(847762630) # Find a story with the given ID
project.create_story(name: 'Destroy death star') # Create a story with the name 'Destroy death star'

epics = project.epics # Get all epics for a project
epic = epics.first
Expand Down
9 changes: 9 additions & 0 deletions lib/tracker_api/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ def get(path, options = {})
request(:get, parse_query_and_convenience_headers(path, options))
end

# Make a HTTP POST request
#
# @param path [String] The path, relative to api endpoint
# @param options [Hash] Query and header params for request
# @return [Faraday::Response]
def post(path, options = {})
request(:post, parse_query_and_convenience_headers(path, options))
end

# Make one or more HTTP GET requests, optionally fetching
# the next page of results from information passed back in headers
# based on value in {#auto_paginate}.
Expand Down
6 changes: 6 additions & 0 deletions lib/tracker_api/endpoints/story.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ def get_story(story_id)

Resources::Story.new({ client: client }.merge(data))
end

def create(project_id, params={})
data = client.post("/projects/#{project_id}/stories", params: params).body

Resources::Story.new({ client: client }.merge(data))
end
end
end
end
6 changes: 6 additions & 0 deletions lib/tracker_api/resources/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ def memberships(params = {})
def story(story_id)
Endpoints::Story.new(client).get(id, story_id)
end

# @param [Hash] hash of attributes to create the story
# @return [Story] Story with given id
def create_story(params)
Endpoints::Story.new(client).create(id, params)
end
end
end
end
11 changes: 11 additions & 0 deletions test/project_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,16 @@
story.current_state.must_equal 'unscheduled'
end
end

it 'can create story' do
VCR.use_cassette('create story') do
story = project.create_story(name: 'Test story')

story.must_be_instance_of TrackerApi::Resources::Story
story.id.wont_be_nil
story.id.must_be :>, 0
story.name.must_equal 'Test story'
end
end
end
end

0 comments on commit 9abe8ba

Please sign in to comment.