pivit 0.1.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 (42) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +30 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +94 -0
  6. data/Rakefile +1 -0
  7. data/lib/pivit.rb +20 -0
  8. data/lib/pivit/authentication.rb +22 -0
  9. data/lib/pivit/client.rb +40 -0
  10. data/lib/pivit/client/activity.rb +34 -0
  11. data/lib/pivit/client/iteration.rb +88 -0
  12. data/lib/pivit/client/membership.rb +92 -0
  13. data/lib/pivit/client/note.rb +47 -0
  14. data/lib/pivit/client/project.rb +58 -0
  15. data/lib/pivit/client/story.rb +177 -0
  16. data/lib/pivit/client/task.rb +112 -0
  17. data/lib/pivit/configuration.rb +29 -0
  18. data/lib/pivit/connection.rb +24 -0
  19. data/lib/pivit/error.rb +6 -0
  20. data/lib/pivit/request.rb +56 -0
  21. data/lib/pivit/version.rb +3 -0
  22. data/pivit.gemspec +37 -0
  23. data/spec/fixtures/authentications.yml.sample +11 -0
  24. data/spec/fixtures/stubs/iteration.xml +77 -0
  25. data/spec/fixtures/stubs/membership.xml +15 -0
  26. data/spec/fixtures/stubs/note.xml +7 -0
  27. data/spec/fixtures/stubs/project/project.xml +29 -0
  28. data/spec/fixtures/stubs/story/delete_story.xml +13 -0
  29. data/spec/fixtures/stubs/task.xml +8 -0
  30. data/spec/fixtures/stubs/task_update.xml +8 -0
  31. data/spec/fixtures/test.png +0 -0
  32. data/spec/pivit/client/activity_spec.rb +26 -0
  33. data/spec/pivit/client/iteration_spec.rb +104 -0
  34. data/spec/pivit/client/membership_spec.rb +91 -0
  35. data/spec/pivit/client/note_spec.rb +48 -0
  36. data/spec/pivit/client/project_spec.rb +64 -0
  37. data/spec/pivit/client/story_spec.rb +156 -0
  38. data/spec/pivit/client/task_spec.rb +124 -0
  39. data/spec/pivit/client_spec.rb +47 -0
  40. data/spec/pivit/configuration_spec.rb +29 -0
  41. data/spec/spec_helper.rb +54 -0
  42. metadata +314 -0
@@ -0,0 +1,47 @@
1
+ # notes
2
+
3
+ module Pivit
4
+ class Client
5
+ # Note management
6
+ #
7
+ # @see http://www.pivotaltracker.com/help/api?version=v3#getting_notes
8
+ module Note
9
+ # Retrieve all notes for a story
10
+ #
11
+ # @param [Integer] project_id the id of the project that contains the notes
12
+ # @param [Integer] story_id the id of the story that contains the notes
13
+ #
14
+ # @return [Hashie::Mash] notes response
15
+ #
16
+ # @example
17
+ # Pivit::Client.notes(1111111, 222222)
18
+ #
19
+ # @author Jason Truluck
20
+ def notes(project_id, story_id, options = {})
21
+ get("projects/#{project_id}/stories/#{story_id}/notes", options).notes
22
+ end
23
+
24
+ # Create a note
25
+ #
26
+ # Provide the parameters you want to use for the note via the options
27
+ # hash
28
+ #
29
+ # @see http://www.pivotaltracker.com/help/api?version=v3#add_note
30
+ #
31
+ # @param [Integer] project_id the id of the project that contains the story
32
+ # @param [Integer] story_id the id of the story that contains the note
33
+ # @param [String] text the text that the story note will contain
34
+ #
35
+ # @return [Hashie::Mash] note created response
36
+ #
37
+ # @example
38
+ # Pivit::Client.create_note(111111, 222222, "some not text")
39
+ #
40
+ # @author Jason Truluck
41
+ def create_note(project_id, story_id, text, options = {})
42
+ options = { :note => options.merge!(:text => text) }
43
+ post("projects/#{project_id}/stories", options).note
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,58 @@
1
+ module Pivit
2
+ class Client
3
+ # Project management
4
+ #
5
+ # @see http://www.pivotaltracker.com/help/api?version=v3#getting_projects
6
+ module Project
7
+ # Retrieve a single project from your account
8
+ #
9
+ # @see http://www.pivotaltracker.com/help/api?version=v3#getting_projects
10
+ #
11
+ # @param [Integer] project_id the id of the project that you want to
12
+ # retrieve
13
+ #
14
+ # @return [Hashie::Mash] project response
15
+ #
16
+ # @example
17
+ # Pivit::Client.project(123456)
18
+ #
19
+ # @author Jason Truluck
20
+ def project(project_id, options = {})
21
+ get("projects/#{project_id}", options).project
22
+ end
23
+
24
+ # Retrieve all projects from your account
25
+ #
26
+ # @see http://www.pivotaltracker.com/help/api?version=v3#getting_projects
27
+ #
28
+ # @return [Hashie::Mash] projects response
29
+ #
30
+ # @example
31
+ # Pivit::Client.project
32
+ #
33
+ # @author Jason Truluck
34
+ def projects(options = {})
35
+ get("projects", options).projects
36
+ end
37
+
38
+ # Create a Project
39
+ #
40
+ # Provide the parameters you wantt to use for the project via the options
41
+ # hash
42
+ #
43
+ # @see http://www.pivotaltracker.com/help/api?version=v3#create_project
44
+ #
45
+ # @return [Hashie::Mash] project created response
46
+ #
47
+ # @example
48
+ # Pivit::Client.create_project({:name => "Test Project", :iteration_length
49
+ # => "2"})
50
+ #
51
+ # @author Jason Truluck
52
+ def create_project(options = {})
53
+ options = { :project => options }
54
+ post("projects", options).project
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,177 @@
1
+ # Stories
2
+
3
+ module Pivit
4
+ class Client
5
+ # Story management
6
+ #
7
+ # @see http://www.pivotaltracker.com/help/api?version=v3#getting_stories
8
+ module Story
9
+ # Retrieve a single story from your account
10
+ #
11
+ # @see http://www.pivotaltracker.com/help/api?version=v3#getting_stories
12
+ #
13
+ # @param [Integer] project_id the id of the project that you want to
14
+ # retrieve stories from
15
+ # @param [Integer] story_id the id of the story that you want to
16
+ # retrieve
17
+ #
18
+ # @param [Integer] project_id the id of the project that contains the
19
+ # story
20
+ #
21
+ # @return [Hashie::Mash] story response
22
+ #
23
+ # @example
24
+ # Pivit::Client.story(1111111, 123456)
25
+ #
26
+ # @author Jason Truluck
27
+ def story(project_id, story_id, options = {})
28
+ get("projects/#{project_id}/stories/#{story_id}", options).story
29
+ end
30
+
31
+ # Retrieve all stories from your account
32
+ #
33
+ # @see http://www.pivotaltracker.com/help/api?version=v3#getting_stories
34
+ #
35
+ # @param [Integer] project_id the id of the project that contains the
36
+ #stories
37
+ #
38
+ # @return [Hashie::Mash] stories response
39
+ #
40
+ # @example
41
+ # Pivit::Client.stories(1111111)
42
+ #
43
+ # @author Jason Truluck
44
+ def stories(project_id, options = {})
45
+ get("projects/#{project_id}/stories/", options).stories
46
+ end
47
+
48
+ # Create a story
49
+ #
50
+ # Provide the parameters you want to use for the story via the options
51
+ # hash
52
+ #
53
+ # @see http://www.pivotaltracker.com/help/api?version=v3#add_story
54
+ #
55
+ # @param [Integer] project_id the id of the project that contains the
56
+ # story
57
+ #
58
+ # @return [Hashie::Mash] story created response
59
+ #
60
+ # @example
61
+ # Pivit::Client.create_story_type=> "feature", :name => "Story"})
62
+ #
63
+ # @author Jason Truluck
64
+ def create_story(project_id, options = {})
65
+ options = { :story => options }
66
+ post("projects/#{project_id}/stories", options).story
67
+ end
68
+
69
+ # Update a story
70
+ #
71
+ # Provide the parameters you want to use for the story via the options
72
+ # hash
73
+ #
74
+ # @see http://www.pivotaltracker.com/help/api?version=v3#update_story
75
+ #
76
+ # @param [Integer] project_id the id of the project that contains the
77
+ # story
78
+ # @param [Integer] story_id the id of the story that is getting updated
79
+ #
80
+ # @return [Hashie::Mash] story updated response
81
+ #
82
+ # @example
83
+ # Pivit::Client.update_story(12345, 11111, { :name => "awesome new story name"})
84
+ #
85
+ # @author Jason Truluck
86
+ def update_story(project_id, story_id, options = {})
87
+ options = { :story => options }
88
+ put("projects/#{project_id}/stories/#{story_id}", options).story
89
+ end
90
+
91
+ # Delete a story
92
+ #
93
+ #
94
+ # @see http://www.pivotaltracker.com/help/api?version=v3#delete_story
95
+ #
96
+ # @param [Integer] project_id the id of the project that contains the
97
+ # story
98
+ # @param [Integer] story_id the id of the story that is getting deleted
99
+ #
100
+ # @return [Hashie::Mash] story deleted response
101
+ #
102
+ # @example
103
+ # Pivit::Client.update_story(12345, 11111)
104
+ ##
105
+ # @author Jason Truluck
106
+ def delete_story(project_id, story_id, options = {})
107
+ delete("projects/#{project_id}/stories/#{story_id}", options).story
108
+ end
109
+
110
+ # Move a story before another story
111
+ #
112
+ # @see http://www.pivotaltracker.com/help/api?version=v3#move_story
113
+ #
114
+ # @param [Integer] project_id the id of the project that contains the
115
+ # story
116
+ # @param [Integer] story_id the id of the story that is getting moved
117
+ # @param [Integer] story_target_id the id of the story that the other
118
+ # story is moving before
119
+ #
120
+ # @return [Hashie::Mash] story move response
121
+ #
122
+ # @example
123
+ # Pivit::Client.move_story_before(12345, 11111, 22222)
124
+ ##
125
+ # @author Jason Truluck
126
+ def move_story_before(project_id, story_id, story_target_id, options = {})
127
+ move_story(project_id, story_id, story_target_id, :before, options)
128
+ end
129
+
130
+ # Move a story after another story
131
+ #
132
+ # @see http://www.pivotaltracker.com/help/api?version=v3#move_story
133
+ #
134
+ # @param [Integer] project_id the id of the project that contains the
135
+ # story
136
+ # @param [Integer] story_id the id of the story that is getting moved
137
+ # @param [Integer] story_target_id the id of the story that the other
138
+ # story is moving after
139
+ #
140
+ # @return [Hashie::Mash] story move response
141
+ #
142
+ # @example
143
+ # Pivit::Client.move_story_after(12345, 11111, 22222)
144
+ ##
145
+ # @author Jason Truluck
146
+ def move_story_after(project_id, story_id, story_target_id, options = {})
147
+ move_story(project_id, story_id, story_target_id, :after, options)
148
+ end
149
+
150
+ # Add an attachement to a story
151
+ #
152
+ # @see http://www.pivotaltracker.com/help/api?version=v3#attachements
153
+ #
154
+ # @param [Integer] project_id the id of the project that contains the story
155
+ # @param [Integer] story_id the id of the story that is getting moved
156
+ # @param [String] file the location of the file to be attached
157
+ #
158
+ # @return [Hashie::Mash] story attachement response
159
+ #
160
+ # @example
161
+ # Pivit::Client.add_attachment(12345, 111111, "test.txt")
162
+ ##
163
+ # @author Jason Truluck
164
+ def add_attachment(project_id, story_id, file, options = {})
165
+ options.merge!(:payload => file)
166
+ post("projects/#{project_id}/stories/#{story_id}/attachments", options).attachment
167
+ end
168
+
169
+
170
+ private
171
+ def move_story(project_id, story_id, story_target_id, direction, options = {})
172
+ options.merge!("move\[move\]" => direction, "move\[target\]" => story_target_id)
173
+ post("projects/#{project_id}/stories/#{story_id}/moves", options).story
174
+ end
175
+ end
176
+ end
177
+ end
@@ -0,0 +1,112 @@
1
+ # Tasks
2
+
3
+ module Pivit
4
+ class Client
5
+ # Task management
6
+ #
7
+ # @see http://www.pivotaltracker.com/help/api?version=v3#getting_stories
8
+ module Task
9
+ # Retrieve a single task from your account
10
+ #
11
+ # @see http://www.pivotaltracker.com/help/api?version=v3#getting_stories
12
+ #
13
+ # @param [Integer] project_id the id of the project that you want to
14
+ # retrieve stories from
15
+ # @param [Integer] story_id the id of the story that you want to
16
+ # retrieve
17
+ # @param [Integer] task_id the id of the task that you want to
18
+ # retrieve
19
+ #
20
+ # @param [Integer] project_id the id of the project that contains the
21
+ # task
22
+ #
23
+ # @return [Hashie::Mash] task response
24
+ #
25
+ # @example
26
+ # Pivit::Client.task(1111111, 123456, 67890)
27
+ #
28
+ # @author Jason Truluck
29
+ def task(project_id, story_id, task_id, options = {})
30
+ get("projects/#{project_id}/stories/#{story_id}/tasks/#{task_id}", options).task
31
+ end
32
+
33
+ # Retrieve all tasks from a story
34
+ #
35
+ # @see http://www.pivotaltracker.com/help/api?version=v3#getting_tasks
36
+ #
37
+ # @param [Integer] project_id the id of the project that contains the stories
38
+ # @param [Integer] stroy_id the id of the story that contains the tasks
39
+ #
40
+ # @return [Hashie::Mash] tasks response
41
+ #
42
+ # @example
43
+ # Pivit::Client.tasks(1111111, 123456)
44
+ #
45
+ # @author Jason Truluck
46
+ def tasks(project_id, story_id, options = {})
47
+ get("projects/#{project_id}/stories/#{story_id}/tasks", options).tasks
48
+ end
49
+
50
+ # Create a task
51
+ #
52
+ # Provide the parameters you want to use for the task via the options
53
+ # hash
54
+ #
55
+ # @see http://www.pivotaltracker.com/help/api?version=v3#add_task
56
+ #
57
+ # @param [Integer] project_id the id of the project that contains the task
58
+ # @param [Integer] story_id the id of the story that contains the task
59
+ #
60
+ # @return [Hashie::Mash] task created response
61
+ #
62
+ # @example
63
+ # Pivit::Client.create_task_type=> "feature", :name => "Task"})
64
+ #
65
+ # @author Jason Truluck
66
+ def create_task(project_id, story_id, options = {})
67
+ options = { :task => options }
68
+ post("projects/#{project_id}/stories/#{story_id}/tasks", options).task
69
+ end
70
+
71
+ # Update a task
72
+ #
73
+ # Provide the parameters you want to use for the task via the options
74
+ # hash
75
+ #
76
+ # @see http://www.pivotaltracker.com/help/api?version=v3#update_task
77
+ #
78
+ # @param [Integer] project_id the id of the project that contains the task
79
+ # @param [Integer] story_id the id of the story that contains the task
80
+ # @param [Integer] task_id the id of the task that is getting updated
81
+ #
82
+ # @return [Hashie::Mash] task updated response
83
+ #
84
+ # @example
85
+ # Pivit::Client.update_task(12345, 11111, 67890, { :name => "awesome new task name"})
86
+ #
87
+ # @author Jason Truluck
88
+ def update_task(project_id, story_id, task_id, options = {})
89
+ options = { :task => options }
90
+ put("projects/#{project_id}/stories/#{story_id}/tasks/#{task_id}", options).task
91
+ end
92
+
93
+ # Delete a task
94
+ #
95
+ # @see http://www.pivotaltracker.com/help/api?version=v3#delete_task
96
+ #
97
+ # @param [Integer] project_id the id of the project that contains the task
98
+ # @param [Integer] story_id the id of the story that contains the task
99
+ # @param [Integer] task_id the id of the task that is getting deleted
100
+ #
101
+ # @return [Hashie::Mash] task deleted response
102
+ #
103
+ # @example
104
+ # Pivit::Client.update_task(12345, 11111, 67890)
105
+ #
106
+ # @author Jason Truluck
107
+ def delete_task(project_id, story_id, task_id, options = {})
108
+ delete("projects/#{project_id}/stories/#{story_id}/tasks/#{task_id}", options).task
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,29 @@
1
+ #Configuration
2
+ module Pivit
3
+ module Configuration
4
+ VALID_OPTIONS_KEYS = [
5
+ :username,
6
+ :password,
7
+ :api_token,
8
+ :api_endpoint,
9
+ :ssl
10
+ ]
11
+
12
+ attr_accessor(*VALID_OPTIONS_KEYS)
13
+
14
+ def configure
15
+ yield self
16
+ end
17
+
18
+ def options
19
+ VALID_OPTIONS_KEYS.inject({}){|o,k| o.merge!(k => send(k)) }
20
+ end
21
+
22
+ def reset!
23
+ self.username = nil
24
+ self.password = nil
25
+ self.api_token = nil
26
+ self.ssl = true
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,24 @@
1
+ # Connection
2
+ require "faraday_middleware"
3
+
4
+ module Pivit
5
+ module Connection
6
+ def connection(options = {})
7
+ options = {
8
+ :ssl => { :verify => false }
9
+ }.merge(options)
10
+
11
+ connection = Faraday.new(options) do |build|
12
+ build.request :multipart
13
+ build.request :url_encoded
14
+ build.use FaradayMiddleware::Mashify
15
+ build.use FaradayMiddleware::ParseXml, :content_type => /\bxml$/
16
+ build.adapter Faraday.default_adapter
17
+ end
18
+
19
+ connection.headers["X-TrackerToken"] = api_token if self.authenticated?
20
+
21
+ connection
22
+ end
23
+ end
24
+ end