devver-octopi 0.2.8

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