octopi 0.1.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/.gitignore +2 -1
  2. data/.yardoc +0 -0
  3. data/README.rdoc +16 -41
  4. data/Rakefile +9 -0
  5. data/VERSION.yml +2 -2
  6. data/examples/overall.rb +1 -1
  7. data/lib/ext/hash_ext.rb +5 -0
  8. data/lib/ext/string_ext.rb +5 -0
  9. data/lib/octopi.rb +101 -202
  10. data/lib/octopi/api.rb +209 -0
  11. data/lib/octopi/base.rb +42 -38
  12. data/lib/octopi/blob.rb +12 -8
  13. data/lib/octopi/branch.rb +20 -7
  14. data/lib/octopi/branch_set.rb +11 -0
  15. data/lib/octopi/comment.rb +20 -0
  16. data/lib/octopi/commit.rb +39 -35
  17. data/lib/octopi/error.rb +17 -5
  18. data/lib/octopi/file_object.rb +6 -5
  19. data/lib/octopi/gist.rb +28 -0
  20. data/lib/octopi/issue.rb +49 -40
  21. data/lib/octopi/issue_comment.rb +7 -0
  22. data/lib/octopi/issue_set.rb +21 -0
  23. data/lib/octopi/key.rb +14 -7
  24. data/lib/octopi/key_set.rb +14 -0
  25. data/lib/octopi/plan.rb +5 -0
  26. data/lib/octopi/repository.rb +66 -45
  27. data/lib/octopi/repository_set.rb +9 -0
  28. data/lib/octopi/resource.rb +11 -16
  29. data/lib/octopi/self.rb +33 -0
  30. data/lib/octopi/tag.rb +12 -6
  31. data/lib/octopi/user.rb +62 -38
  32. data/octopi.gemspec +43 -12
  33. data/test/api_test.rb +58 -0
  34. data/test/authenticated_test.rb +39 -0
  35. data/test/blob_test.rb +23 -0
  36. data/test/branch_test.rb +20 -0
  37. data/test/commit_test.rb +82 -0
  38. data/test/file_object_test.rb +39 -0
  39. data/test/gist_test.rb +16 -0
  40. data/test/issue_comment.rb +19 -0
  41. data/test/issue_set_test.rb +33 -0
  42. data/test/issue_test.rb +120 -0
  43. data/test/key_set_test.rb +29 -0
  44. data/test/key_test.rb +35 -0
  45. data/test/repository_set_test.rb +23 -0
  46. data/test/repository_test.rb +141 -0
  47. data/test/stubs/commits/fcoury/octopi/octopi.rb +818 -0
  48. data/test/tag_test.rb +20 -0
  49. data/test/test_helper.rb +236 -0
  50. data/test/user_test.rb +92 -0
  51. metadata +54 -12
  52. data/examples/github.yml.example +0 -14
  53. data/test/octopi_test.rb +0 -46
data/test/tag_test.rb ADDED
@@ -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
data/test/test_helper.rb CHANGED
@@ -1,10 +1,246 @@
1
1
  require 'rubygems'
2
2
  require 'test/unit'
3
3
  require 'shoulda'
4
+ require 'fakeweb'
4
5
 
5
6
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
7
  $LOAD_PATH.unshift(File.dirname(__FILE__))
7
8
  require 'octopi'
8
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
+
9
244
  class Test::Unit::TestCase
245
+
10
246
  end
data/test/user_test.rb ADDED
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octopi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felipe Coury
@@ -9,10 +9,29 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-21 00:00:00 -03:00
12
+ date: 2009-11-10 00:00:00 +10:00
13
13
  default_executable:
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: nokogiri
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.3.1
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: httparty
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.4.5
34
+ version:
16
35
  description:
17
36
  email: felipe.coury@gmail.com
18
37
  executables: []
@@ -24,31 +43,38 @@ extra_rdoc_files:
24
43
  - README.rdoc
25
44
  files:
26
45
  - .gitignore
46
+ - .yardoc
27
47
  - LICENSE
28
48
  - README.rdoc
29
49
  - Rakefile
30
50
  - VERSION.yml
31
51
  - contrib/backup.rb
32
- - examples/authenticated.rb
33
- - examples/github.yml.example
34
- - examples/issues.rb
35
- - examples/overall.rb
52
+ - lib/ext/hash_ext.rb
53
+ - lib/ext/string_ext.rb
36
54
  - lib/octopi.rb
55
+ - lib/octopi/api.rb
37
56
  - lib/octopi/base.rb
38
57
  - lib/octopi/blob.rb
39
58
  - lib/octopi/branch.rb
59
+ - lib/octopi/branch_set.rb
60
+ - lib/octopi/comment.rb
40
61
  - lib/octopi/commit.rb
41
62
  - lib/octopi/error.rb
42
63
  - lib/octopi/file_object.rb
64
+ - lib/octopi/gist.rb
43
65
  - lib/octopi/issue.rb
66
+ - lib/octopi/issue_comment.rb
67
+ - lib/octopi/issue_set.rb
44
68
  - lib/octopi/key.rb
69
+ - lib/octopi/key_set.rb
70
+ - lib/octopi/plan.rb
45
71
  - lib/octopi/repository.rb
72
+ - lib/octopi/repository_set.rb
46
73
  - lib/octopi/resource.rb
74
+ - lib/octopi/self.rb
47
75
  - lib/octopi/tag.rb
48
76
  - lib/octopi/user.rb
49
77
  - octopi.gemspec
50
- - test/octopi_test.rb
51
- - test/test_helper.rb
52
78
  has_rdoc: true
53
79
  homepage: http://github.com/fcoury/octopi
54
80
  licenses: []
@@ -73,13 +99,29 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
99
  requirements: []
74
100
 
75
101
  rubyforge_project: octopi
76
- rubygems_version: 1.3.2
102
+ rubygems_version: 1.3.5
77
103
  signing_key:
78
104
  specification_version: 3
79
105
  summary: A Ruby interface to GitHub API v2
80
106
  test_files:
81
- - test/octopi_test.rb
107
+ - test/api_test.rb
108
+ - test/authenticated_test.rb
109
+ - test/blob_test.rb
110
+ - test/branch_test.rb
111
+ - test/commit_test.rb
112
+ - test/file_object_test.rb
113
+ - test/gist_test.rb
114
+ - test/issue_comment.rb
115
+ - test/issue_set_test.rb
116
+ - test/issue_test.rb
117
+ - test/key_set_test.rb
118
+ - test/key_test.rb
119
+ - test/repository_set_test.rb
120
+ - test/repository_test.rb
121
+ - test/stubs/commits/fcoury/octopi/octopi.rb
122
+ - test/tag_test.rb
82
123
  - test/test_helper.rb
124
+ - test/user_test.rb
83
125
  - examples/authenticated.rb
84
126
  - examples/issues.rb
85
127
  - examples/overall.rb