tpitale-octopi 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/.gitignore +5 -0
  2. data/.yardoc +0 -0
  3. data/CHANGELOG.md +9 -0
  4. data/LICENSE +20 -0
  5. data/README.markdown +137 -0
  6. data/Rakefile +91 -0
  7. data/VERSION.yml +4 -0
  8. data/contrib/backup.rb +100 -0
  9. data/examples/authenticated.rb +20 -0
  10. data/examples/issues.rb +18 -0
  11. data/examples/overall.rb +50 -0
  12. data/lib/ext/string_ext.rb +5 -0
  13. data/lib/octopi.rb +92 -0
  14. data/lib/octopi/api.rb +213 -0
  15. data/lib/octopi/base.rb +115 -0
  16. data/lib/octopi/blob.rb +25 -0
  17. data/lib/octopi/branch.rb +31 -0
  18. data/lib/octopi/branch_set.rb +11 -0
  19. data/lib/octopi/comment.rb +20 -0
  20. data/lib/octopi/commit.rb +69 -0
  21. data/lib/octopi/error.rb +35 -0
  22. data/lib/octopi/file_object.rb +16 -0
  23. data/lib/octopi/gist.rb +28 -0
  24. data/lib/octopi/issue.rb +111 -0
  25. data/lib/octopi/issue_comment.rb +7 -0
  26. data/lib/octopi/issue_set.rb +21 -0
  27. data/lib/octopi/key.rb +25 -0
  28. data/lib/octopi/key_set.rb +14 -0
  29. data/lib/octopi/plan.rb +5 -0
  30. data/lib/octopi/repository.rb +130 -0
  31. data/lib/octopi/repository_set.rb +9 -0
  32. data/lib/octopi/resource.rb +70 -0
  33. data/lib/octopi/self.rb +33 -0
  34. data/lib/octopi/tag.rb +23 -0
  35. data/lib/octopi/user.rb +131 -0
  36. data/test/api_test.rb +58 -0
  37. data/test/authenticated_test.rb +38 -0
  38. data/test/base_test.rb +20 -0
  39. data/test/blob_test.rb +23 -0
  40. data/test/branch_test.rb +20 -0
  41. data/test/commit_test.rb +82 -0
  42. data/test/file_object_test.rb +39 -0
  43. data/test/gist_test.rb +16 -0
  44. data/test/issue_comment.rb +19 -0
  45. data/test/issue_set_test.rb +33 -0
  46. data/test/issue_test.rb +120 -0
  47. data/test/key_set_test.rb +29 -0
  48. data/test/key_test.rb +35 -0
  49. data/test/repository_set_test.rb +23 -0
  50. data/test/repository_test.rb +151 -0
  51. data/test/stubs/commits/fcoury/octopi/octopi.rb +818 -0
  52. data/test/tag_test.rb +20 -0
  53. data/test/test_helper.rb +246 -0
  54. data/test/user_test.rb +92 -0
  55. data/tpitale-octopi.gemspec +99 -0
  56. metadata +142 -0
@@ -0,0 +1,20 @@
1
+ # Tests for octopi core functionality go here.
2
+ require File.join(File.dirname(__FILE__), 'test_helper')
3
+
4
+ class TagTest < Test::Unit::TestCase
5
+ include Octopi
6
+
7
+ def setup
8
+ fake_everything
9
+ end
10
+
11
+ context Tag do
12
+ should "be able to find all tags" do
13
+ tags = Tag.all(:user => "fcoury", :repository => "octopi")
14
+ assert_not_nil tags
15
+ assert 12, tags.size
16
+ assert tags.first.is_a?(Tag)
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,246 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'fakeweb'
5
+
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
8
+ require 'octopi'
9
+
10
+ ENV['HOME'] = File.dirname(__FILE__)
11
+ FakeWeb.allow_net_connect = false
12
+
13
+ @the_repo = ["fcoury", "octopi"]
14
+
15
+ def stub_file(*path)
16
+ File.join(File.dirname(__FILE__), "stubs", path)
17
+ end
18
+
19
+ def commits(*args)
20
+ File.join("commits", "fcoury", "octopi", args)
21
+ end
22
+
23
+ def issues(*args)
24
+ File.join("issues", "fcoury", "octopi", args)
25
+ end
26
+
27
+ def repos(*args)
28
+ File.join("repos", "fcoury", "octopi", args)
29
+ end
30
+
31
+ def users(*args)
32
+ File.join("users", args)
33
+ end
34
+
35
+ def auth(&block)
36
+ authenticated_with(:login => "fcoury", :token => "8f700e0d7747826f3e56ee13651414bd") do
37
+ yield
38
+ end
39
+ end
40
+
41
+ # Methodized so it can be used in tests, an instance would do also.
42
+ def yaml_api
43
+ "github.com/api/v2/yaml"
44
+ end
45
+
46
+ def fake_everything
47
+ FakeWeb.clean_registry
48
+ # helper variables to make things shorter.
49
+ sha = "f6609209c3ac0badd004512d318bfaa508ea10ae"
50
+ fake_sha = "ea3cd978650417470535f3a4725b6b5042a6ab59"
51
+
52
+ plain_api = "github.com:80/api/v2/plain"
53
+
54
+ # Public stuff
55
+ fakes = {
56
+ "blob/show/fcoury/octopi/#{sha}" => File.join("blob", "fcoury", "octopi", "plain", sha),
57
+
58
+ "commits/list/fcoury/octopi/master" => commits("master"),
59
+ "commits/list/fcoury/octopi/master/lib/octopi.rb" => commits("octopi.rb"),
60
+ "commits/list/fcoury/octopi/lazy" => commits("lazy"),
61
+ "commits/show/fcoury/octopi/#{sha}" => commits(sha),
62
+
63
+ "issues/list/fcoury/octopi/open" => issues("open"),
64
+ "issues/list/fcoury/octopi/closed" => issues("closed"),
65
+
66
+ "issues/search/fcoury/octopi/open/test" => issues("search"),
67
+
68
+ # Closed issue
69
+ "issues/show/fcoury/octopi/27" => issues("27"),
70
+ # Open issue
71
+ "issues/show/fcoury/octopi/28" => issues("28"),
72
+
73
+ "repos/show/fcoury/octopi/collaborators" => File.join("repos", "fcoury", "octopi", "collaborators"),
74
+ "repos/show/fcoury" => File.join("repos", "show", "fcoury"),
75
+ "repos/search/ruby+testing" => File.join("repos", "search"),
76
+ "repos/show/fcoury/octopi" => repos("master"),
77
+ "repos/show/fcoury/octopi/branches" => repos("branches"),
78
+ "repos/show/fcoury/octopi/tags" => repos("tags"),
79
+ "repos/watched/radar" => File.join("users", "watched-repos"),
80
+
81
+ "tree/show/fcoury/octopi/#{sha}" => File.join("tree", "fcoury", "octopi", sha),
82
+
83
+ "user/show/fcoury" => users("fcoury"),
84
+
85
+ "user/show/fcoury/followers" => File.join("users", "followers"),
86
+ "user/show/fcoury/following" => File.join("users", "following"),
87
+ "user/search/radar" => File.join("users", "search-radar")
88
+
89
+
90
+ }
91
+
92
+ # I follow the following people:
93
+ ["Caged",
94
+ "FooBarWidget",
95
+ "aslakhellesoy",
96
+ "augustl",
97
+ "benaskins",
98
+ "benhoskings",
99
+ "bjeanes",
100
+ "cldwalker",
101
+ "dchelimsky",
102
+ "defunkt",
103
+ "diy",
104
+ "documentcloud",
105
+ "drnic",
106
+ "eladmeidar",
107
+ "entp",
108
+ "fcoury",
109
+ "giraffesoft",
110
+ "hashrocket",
111
+ "hcatlin",
112
+ "jamis",
113
+ "jnicklas",
114
+ "jnunemaker",
115
+ "kballard",
116
+ "knewter",
117
+ "lachie",
118
+ "lachlanhardy",
119
+ "lenary",
120
+ "lifo",
121
+ "maccman",
122
+ "markgandolfo",
123
+ "mbleigh",
124
+ "mhodgson",
125
+ "mocra",
126
+ "mojombo",
127
+ "newbamboo",
128
+ "notahat",
129
+ "opscode",
130
+ "pvande",
131
+ "rack",
132
+ "radar",
133
+ "rails",
134
+ "railscampau",
135
+ "redinger",
136
+ "shuber",
137
+ "softprops",
138
+ "svenfuchs",
139
+ "technoweenie",
140
+ "thoughtbot",
141
+ "tobi",
142
+ "webbynode",
143
+ "wvanbergen",
144
+ "wycats"].each do |name|
145
+ fakes["user/show/#{name}"] = users(name);
146
+ end
147
+
148
+ fakes.each do |key, value|
149
+ FakeWeb.register_uri(:get, "http://#{yaml_api}/" + key, :response => stub_file(value))
150
+ end
151
+
152
+ gist_fakes = {
153
+ "159579" => File.join("gists", "159579")
154
+ }
155
+
156
+
157
+ gist_fakes.each do |key, value|
158
+ FakeWeb.register_uri(:get, "http://gist.github.com/api/v1/yaml/#{key}", :response => stub_file(value))
159
+ end
160
+ ["augustl", "bcalloway", "danlucraft", "dcrec1", "derencius", "dustin", "elliottcable", "gwoliveira", "hashrocket", "jruby", "kchris", "paulorv", "radar", "remi", "shanesveller", "superfeedr", "taylorrf", "tgraham", "tmm1", "tpope", "webbynode"].each do |followee|
161
+ FakeWeb.register_uri(:get, "http://#{yaml_api}/user/show/#{followee}", :response => stub_file("users/#{followee}") )
162
+ end
163
+
164
+
165
+ fake_posts = {
166
+ "issues/label/add/fcoury/octopi/one-point-oh/28" => issues("labels", "28-one-point-oh"),
167
+ "issues/label/add/fcoury/octopi/maybe-two-point-oh/28" => issues("labels", "28-maybe-two-point-oh"),
168
+ "issues/label/remove/fcoury/octopi/one-point-oh/28" => issues("labels", "28-remove-one-point-oh"),
169
+ "issues/label/remove/fcoury/octopi/maybe-two-point-oh/28" => issues("labels", "28-remove-maybe-two-point-oh"),
170
+ "issues/reopen/fcoury/octopi/27" => issues("27-reopened"),
171
+ "issues/open/fcoury/octopi" => issues("new"),
172
+ "issues/close/fcoury/octopi/28" => issues("28-closed"),
173
+ "issues/edit/fcoury/octopi/28" => issues("28-edited"),
174
+ "issues/reopen/fcoury/octopi/27" => issues("27-reopened"),
175
+ "issues/comment/fcoury/octopi/28" => issues("comment", "28-comment")
176
+ }.each do |key, value|
177
+ FakeWeb.register_uri(:post, "http://#{yaml_api}/" + key, :response => stub_file(value))
178
+ end
179
+
180
+ # # rboard is a private repository
181
+ FakeWeb.register_uri(:get, "http://#{yaml_api}/repos/show/fcoury/rboard", :response => stub_file("errors", "repository", "not_found"))
182
+
183
+ # nothere is obviously an invalid sha
184
+ FakeWeb.register_uri(:get, "http://#{yaml_api}/commits/show/fcoury/octopi/nothere", :status => ["404", "Not Found"])
185
+ # not-a-number is obviously not a *number*
186
+ FakeWeb.register_uri(:get, "http://#{yaml_api}/issues/show/fcoury/octopi/not-a-number", :status => ["404", "Not Found"])
187
+ # is an invalid hash
188
+ FakeWeb.register_uri(:get, "http://#{yaml_api}/tree/show/fcoury/octopi/#{fake_sha}", :status => ["404", "Not Found"])
189
+ # is not a user
190
+ FakeWeb.register_uri(:get, "http://#{yaml_api}/user/show/i-am-most-probably-a-user-that-does-not-exist", :status => ["404", "Not Found"])
191
+
192
+
193
+ FakeWeb.register_uri(:get, "http://github.com/login", :response => stub_file("login"))
194
+ FakeWeb.register_uri(:post, "http://github.com/session", :response => stub_file("dashboard"))
195
+ FakeWeb.register_uri(:get, "http://github.com/account", :response => stub_file("account"))
196
+
197
+ # Personal & Private stuff
198
+
199
+ # To authenticate with the API
200
+ # Methodized as it is used also in key_tests
201
+ def auth_query
202
+ "?login=fcoury&token=8f700e0d7747826f3e56ee13651414bd"
203
+ end
204
+
205
+ secure_fakes = {
206
+
207
+ "commits/list/fcoury/rboard/master" => File.join("commits", "fcoury", "rboard", "master"),
208
+
209
+ "repos/show/fcoury" => File.join("repos", "show", "fcoury-private"),
210
+ "repos/show/fcoury/octopi" => File.join("repos", "fcoury", "octopi", "master"),
211
+ "repos/show/fcoury/rboard" => File.join("repos", "fcoury", "rboard", "master"),
212
+
213
+ "user/keys" => File.join("users", "keys"),
214
+ "user/show/fcoury" => File.join("users", "fcoury-private")
215
+ }
216
+
217
+ secure_fakes.each do |key, value|
218
+ FakeWeb.register_uri(:get, "https://#{yaml_api}/" + key + auth_query, :response => stub_file(value))
219
+ end
220
+
221
+ secure_post_fakes = {
222
+ "user/key/add" => File.join("users", "key-added"),
223
+ "user/key/remove" => File.join("users", "key-removed"),
224
+ "user/follow/rails" => File.join("users", "follow-rails"),
225
+ "user/unfollow/rails" => File.join("users", "unfollow-rails"),
226
+ "repos/create" => File.join("repos", "fcoury", "octopus", "main"),
227
+ "repos/delete/octopi" => File.join("repos", "fcoury", "octopi", "delete-token")
228
+ }
229
+
230
+ secure_post_fakes.each do |key, value|
231
+ FakeWeb.register_uri(:post, "https://#{yaml_api}/" + key + auth_query, :response => stub_file(value))
232
+ end
233
+
234
+
235
+ # And the plain fakes
236
+ FakeWeb.register_uri(:get, "http://#{plain_api}/blob/show/fcoury/octopi/#{sha}",
237
+ :response => stub_file(File.join("blob", "fcoury", "octopi", "plain", sha)))
238
+
239
+
240
+ FakeWeb.register_uri(:get, "http://github.com/fcoury/octopi/comments.atom", :response => stub_file("comments", "fcoury", "octopi", "comments.atom"))
241
+ end
242
+
243
+
244
+ class Test::Unit::TestCase
245
+
246
+ end
@@ -0,0 +1,92 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class UserTest < Test::Unit::TestCase
4
+ include Octopi
5
+
6
+ def setup
7
+ fake_everything
8
+ @user = User.find("fcoury")
9
+ end
10
+
11
+ should "be able to find a user" do
12
+ assert_not_nil User.find("fcoury")
13
+ end
14
+
15
+ should "not be able to find a user that doesn't exist" do
16
+ exception = assert_raise NotFound do
17
+ User.find("i-am-most-probably-a-user-that-does-not-exist")
18
+ end
19
+
20
+ assert_equal "The User you were looking for could not be found, or is private.", exception.message
21
+ end
22
+
23
+ should "be able to look for a user, using find_all" do
24
+ users = User.find_all("radar")
25
+ assert_not_nil users
26
+ end
27
+
28
+ should "be able to search for a user" do
29
+ users = User.search("radar")
30
+ assert_not_nil users
31
+ end
32
+
33
+ context "authenticated" do
34
+ should "return all user information" do
35
+ authenticated do
36
+ user = Api.api.user
37
+ assert_not_nil user
38
+ fields = [:company, :name, :following_count, :blog, :public_repo_count,
39
+ :public_gist_count, :id, :login, :followers_count, :created_at,
40
+ :email, :location, :disk_usage, :private_gist_count, :plan,
41
+ :owned_private_repo_count, :total_private_repo_count]
42
+ fields.each do |f|
43
+ assert_not_nil user.send(f)
44
+ end
45
+
46
+ plan_fields = [:name, :collaborators, :space, :private_repos]
47
+ plan_fields.each do |f|
48
+ assert_not_nil user.plan.send(f)
49
+ end
50
+ end
51
+ end
52
+
53
+ context "return a list of followers" do
54
+
55
+ should "in string format" do
56
+ users = @user.followers
57
+ assert_not_nil users
58
+ assert users.first.is_a?(String)
59
+ end
60
+
61
+ should "in object format" do
62
+ users = @user.followers!
63
+ assert_not_nil users
64
+ assert users.first.is_a?(User)
65
+ end
66
+ end
67
+
68
+ context "return a list of people who they are following" do
69
+ should "in string format" do
70
+ users = @user.following
71
+ assert_not_nil users
72
+ assert users.first.is_a?(String)
73
+ end
74
+
75
+ should "in object format" do
76
+ users = @user.following!
77
+ assert_not_nil users
78
+ assert users.first.is_a?(User)
79
+ end
80
+ end
81
+
82
+ context "return a list of watched repositories" do
83
+ should "in an array" do
84
+ @user = User.find("radar")
85
+ repos = @user.watching
86
+ assert_not_nil repos
87
+ assert repos.first.is_a?(Repository)
88
+ end
89
+ end
90
+
91
+ end
92
+ end
@@ -0,0 +1,99 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{tpitale-octopi}
8
+ s.version = "0.3.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Felipe Coury", "Tony Pitale"]
12
+ s.date = %q{2010-03-31}
13
+ s.email = %q{tpitale@gmail.com}
14
+ s.extra_rdoc_files = [
15
+ "LICENSE",
16
+ "README.markdown"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ ".yardoc",
21
+ "CHANGELOG.md",
22
+ "LICENSE",
23
+ "README.markdown",
24
+ "Rakefile",
25
+ "VERSION.yml",
26
+ "contrib/backup.rb",
27
+ "lib/ext/string_ext.rb",
28
+ "lib/octopi.rb",
29
+ "lib/octopi/api.rb",
30
+ "lib/octopi/base.rb",
31
+ "lib/octopi/blob.rb",
32
+ "lib/octopi/branch.rb",
33
+ "lib/octopi/branch_set.rb",
34
+ "lib/octopi/comment.rb",
35
+ "lib/octopi/commit.rb",
36
+ "lib/octopi/error.rb",
37
+ "lib/octopi/file_object.rb",
38
+ "lib/octopi/gist.rb",
39
+ "lib/octopi/issue.rb",
40
+ "lib/octopi/issue_comment.rb",
41
+ "lib/octopi/issue_set.rb",
42
+ "lib/octopi/key.rb",
43
+ "lib/octopi/key_set.rb",
44
+ "lib/octopi/plan.rb",
45
+ "lib/octopi/repository.rb",
46
+ "lib/octopi/repository_set.rb",
47
+ "lib/octopi/resource.rb",
48
+ "lib/octopi/self.rb",
49
+ "lib/octopi/tag.rb",
50
+ "lib/octopi/user.rb",
51
+ "tpitale-octopi.gemspec"
52
+ ]
53
+ s.homepage = %q{http://github.com/tpitale/octopi}
54
+ s.rdoc_options = ["--charset=UTF-8"]
55
+ s.require_paths = ["lib"]
56
+ s.rubygems_version = %q{1.3.6}
57
+ s.summary = %q{A Ruby interface to GitHub API v2}
58
+ s.test_files = [
59
+ "test/api_test.rb",
60
+ "test/authenticated_test.rb",
61
+ "test/base_test.rb",
62
+ "test/blob_test.rb",
63
+ "test/branch_test.rb",
64
+ "test/commit_test.rb",
65
+ "test/file_object_test.rb",
66
+ "test/gist_test.rb",
67
+ "test/issue_comment.rb",
68
+ "test/issue_set_test.rb",
69
+ "test/issue_test.rb",
70
+ "test/key_set_test.rb",
71
+ "test/key_test.rb",
72
+ "test/repository_set_test.rb",
73
+ "test/repository_test.rb",
74
+ "test/stubs/commits/fcoury/octopi/octopi.rb",
75
+ "test/tag_test.rb",
76
+ "test/test_helper.rb",
77
+ "test/user_test.rb",
78
+ "examples/authenticated.rb",
79
+ "examples/issues.rb",
80
+ "examples/overall.rb"
81
+ ]
82
+
83
+ if s.respond_to? :specification_version then
84
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
85
+ s.specification_version = 3
86
+
87
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
88
+ s.add_runtime_dependency(%q<httparty>, [">= 0.5.2"])
89
+ s.add_runtime_dependency(%q<api_cache>, [">= 0"])
90
+ else
91
+ s.add_dependency(%q<httparty>, [">= 0.5.2"])
92
+ s.add_dependency(%q<api_cache>, [">= 0"])
93
+ end
94
+ else
95
+ s.add_dependency(%q<httparty>, [">= 0.5.2"])
96
+ s.add_dependency(%q<api_cache>, [">= 0"])
97
+ end
98
+ end
99
+