dcuddeback-octopi 0.2.8

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 (58) hide show
  1. data/.gitignore +4 -0
  2. data/.yardoc +0 -0
  3. data/CHANGELOG.md +9 -0
  4. data/LICENSE +20 -0
  5. data/README.markdown +144 -0
  6. data/Rakefile +94 -0
  7. data/VERSION.yml +4 -0
  8. data/contrib/backup.rb +100 -0
  9. data/dcuddeback-octopi.gemspec +108 -0
  10. data/examples/authenticated.rb +20 -0
  11. data/examples/issues.rb +18 -0
  12. data/examples/overall.rb +50 -0
  13. data/lib/ext/string_ext.rb +5 -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/deploy_key.rb +27 -0
  22. data/lib/octopi/deploy_key_set.rb +18 -0
  23. data/lib/octopi/error.rb +35 -0
  24. data/lib/octopi/file_object.rb +16 -0
  25. data/lib/octopi/gist.rb +28 -0
  26. data/lib/octopi/issue.rb +111 -0
  27. data/lib/octopi/issue_comment.rb +7 -0
  28. data/lib/octopi/issue_set.rb +21 -0
  29. data/lib/octopi/key.rb +25 -0
  30. data/lib/octopi/key_set.rb +14 -0
  31. data/lib/octopi/plan.rb +5 -0
  32. data/lib/octopi/repository.rb +136 -0
  33. data/lib/octopi/repository_set.rb +9 -0
  34. data/lib/octopi/resource.rb +70 -0
  35. data/lib/octopi/self.rb +33 -0
  36. data/lib/octopi/tag.rb +23 -0
  37. data/lib/octopi/user.rb +131 -0
  38. data/lib/octopi.rb +135 -0
  39. data/test/api_test.rb +58 -0
  40. data/test/authenticated_test.rb +39 -0
  41. data/test/base_test.rb +20 -0
  42. data/test/blob_test.rb +23 -0
  43. data/test/branch_test.rb +20 -0
  44. data/test/commit_test.rb +82 -0
  45. data/test/file_object_test.rb +39 -0
  46. data/test/gist_test.rb +16 -0
  47. data/test/issue_comment.rb +19 -0
  48. data/test/issue_set_test.rb +33 -0
  49. data/test/issue_test.rb +120 -0
  50. data/test/key_set_test.rb +29 -0
  51. data/test/key_test.rb +35 -0
  52. data/test/repository_set_test.rb +23 -0
  53. data/test/repository_test.rb +151 -0
  54. data/test/stubs/commits/fcoury/octopi/octopi.rb +818 -0
  55. data/test/tag_test.rb +20 -0
  56. data/test/test_helper.rb +246 -0
  57. data/test/user_test.rb +92 -0
  58. metadata +151 -0
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
@@ -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
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 ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dcuddeback-octopi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.8
5
+ platform: ruby
6
+ authors:
7
+ - Felipe Coury
8
+ - David Cuddeback
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2010-06-21 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: nokogiri
18
+ type: :runtime
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 1.3.1
25
+ version:
26
+ - !ruby/object:Gem::Dependency
27
+ name: httparty
28
+ type: :runtime
29
+ version_requirement:
30
+ version_requirements: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 0.4.5
35
+ version:
36
+ - !ruby/object:Gem::Dependency
37
+ name: mechanize
38
+ type: :runtime
39
+ version_requirement:
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: 0.9.3
45
+ version:
46
+ - !ruby/object:Gem::Dependency
47
+ name: api_cache
48
+ type: :runtime
49
+ version_requirement:
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ description:
57
+ email: david.cuddeback@gmail.com
58
+ executables: []
59
+
60
+ extensions: []
61
+
62
+ extra_rdoc_files:
63
+ - LICENSE
64
+ - README.markdown
65
+ files:
66
+ - .gitignore
67
+ - .yardoc
68
+ - CHANGELOG.md
69
+ - LICENSE
70
+ - README.markdown
71
+ - Rakefile
72
+ - VERSION.yml
73
+ - contrib/backup.rb
74
+ - dcuddeback-octopi.gemspec
75
+ - lib/ext/string_ext.rb
76
+ - lib/octopi.rb
77
+ - lib/octopi/api.rb
78
+ - lib/octopi/base.rb
79
+ - lib/octopi/blob.rb
80
+ - lib/octopi/branch.rb
81
+ - lib/octopi/branch_set.rb
82
+ - lib/octopi/comment.rb
83
+ - lib/octopi/commit.rb
84
+ - lib/octopi/deploy_key.rb
85
+ - lib/octopi/deploy_key_set.rb
86
+ - lib/octopi/error.rb
87
+ - lib/octopi/file_object.rb
88
+ - lib/octopi/gist.rb
89
+ - lib/octopi/issue.rb
90
+ - lib/octopi/issue_comment.rb
91
+ - lib/octopi/issue_set.rb
92
+ - lib/octopi/key.rb
93
+ - lib/octopi/key_set.rb
94
+ - lib/octopi/plan.rb
95
+ - lib/octopi/repository.rb
96
+ - lib/octopi/repository_set.rb
97
+ - lib/octopi/resource.rb
98
+ - lib/octopi/self.rb
99
+ - lib/octopi/tag.rb
100
+ - lib/octopi/user.rb
101
+ has_rdoc: true
102
+ homepage: http://github.com/dcuddeback/octopi
103
+ licenses: []
104
+
105
+ post_install_message:
106
+ rdoc_options:
107
+ - --charset=UTF-8
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: "0"
115
+ version:
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: "0"
121
+ version:
122
+ requirements: []
123
+
124
+ rubyforge_project: dcuddeback-octopi
125
+ rubygems_version: 1.3.5
126
+ signing_key:
127
+ specification_version: 3
128
+ summary: A Ruby interface to GitHub API v2
129
+ test_files:
130
+ - test/api_test.rb
131
+ - test/authenticated_test.rb
132
+ - test/base_test.rb
133
+ - test/blob_test.rb
134
+ - test/branch_test.rb
135
+ - test/commit_test.rb
136
+ - test/file_object_test.rb
137
+ - test/gist_test.rb
138
+ - test/issue_comment.rb
139
+ - test/issue_set_test.rb
140
+ - test/issue_test.rb
141
+ - test/key_set_test.rb
142
+ - test/key_test.rb
143
+ - test/repository_set_test.rb
144
+ - test/repository_test.rb
145
+ - test/stubs/commits/fcoury/octopi/octopi.rb
146
+ - test/tag_test.rb
147
+ - test/test_helper.rb
148
+ - test/user_test.rb
149
+ - examples/authenticated.rb
150
+ - examples/issues.rb
151
+ - examples/overall.rb