mwunsch-octocatnap 0.7.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.
- data/.gitignore +2 -0
- data/LICENSE +20 -0
- data/README.md +59 -0
- data/Rakefile +33 -0
- data/VERSION +1 -0
- data/examples/user_show.rb +6 -0
- data/examples/user_update.rb +6 -0
- data/lib/octocatnap.rb +15 -0
- data/lib/octocatnap/api.rb +22 -0
- data/lib/octocatnap/base.rb +342 -0
- data/spec/fixtures/config.yml +3 -0
- data/spec/octocatnap/api_spec.rb +21 -0
- data/spec/octocatnap/base_spec.rb +98 -0
- data/spec/octocatnap_spec.rb +5 -0
- data/spec/spec_helper.rb +5 -0
- metadata +82 -0
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Mark Wunsch
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# OctocatNap
|
2
|
+
|
3
|
+
OctocatNap is a Ruby interface to the [GitHub API v2](http://develop.github.com/).
|
4
|
+
|
5
|
+
The source of it's power is [Weary](http://github.com/mwunsch/weary/).
|
6
|
+
|
7
|
+
## Install
|
8
|
+
|
9
|
+
sudo gem sources -a http://gems.github.com # If you haven't done that already
|
10
|
+
sudo gem install mwunsch-octocatnap
|
11
|
+
|
12
|
+
_* Someday we can put this on Rubyforge_
|
13
|
+
|
14
|
+
### Requires
|
15
|
+
|
16
|
+
+ Weary >= 0.4.1
|
17
|
+
|
18
|
+
## Authenticating
|
19
|
+
|
20
|
+
When you instantiate OctocatNap, you can pass different types of arguments to pass your credentials to the methods.
|
21
|
+
|
22
|
+
#### Explicitly
|
23
|
+
|
24
|
+
gh = OctocatNap.new("mwunsch", "my-super-secret-token")
|
25
|
+
|
26
|
+
or
|
27
|
+
|
28
|
+
gh = OctocatNap.new(["mwunsch","my-super-secret-token"])
|
29
|
+
|
30
|
+
or
|
31
|
+
|
32
|
+
gh = OctocatNap.new({:login => "mwunsch", :token => "my-super-secret-token"})
|
33
|
+
|
34
|
+
#### YAML
|
35
|
+
|
36
|
+
If you provide just one string when you instantiate, OctocatNap thinks that's the path to a file.
|
37
|
+
|
38
|
+
gh = OctocatNap.new(File.join(File.dirname(__FILE__), '..', "config.yml"))
|
39
|
+
|
40
|
+
That file should look something like this:
|
41
|
+
|
42
|
+
login: mwunsch
|
43
|
+
token: my-super-secret-token
|
44
|
+
|
45
|
+
#### ~/.gitconfig
|
46
|
+
|
47
|
+
You can also get credentials from the global .gitconfig, as long as that is set up with your [GitHub credentials](http://github.com/guides/tell-git-your-user-name-and-email-address)
|
48
|
+
|
49
|
+
gh = OctocatNap.new(true)
|
50
|
+
|
51
|
+
This assumes your gitconfig is in a standard place, as detailed here: http://github.com/blog/180-local-github-config
|
52
|
+
|
53
|
+
## API and Documentation
|
54
|
+
|
55
|
+
Coming soon. Keep an eye on the [Wiki](http://wiki.github.com/mwunsch/octocatnap).
|
56
|
+
|
57
|
+
## License
|
58
|
+
|
59
|
+
Copyright (c) 2009 Mark Wunsch. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spec/rake/spectask'
|
3
|
+
|
4
|
+
task :default => :spec
|
5
|
+
|
6
|
+
require 'rake/rdoctask'
|
7
|
+
Rake::RDocTask.new do |rdoc|
|
8
|
+
rdoc.rdoc_dir = 'doc'
|
9
|
+
rdoc.title = 'octocatnap'
|
10
|
+
rdoc.main = 'README.md'
|
11
|
+
rdoc.rdoc_files.include('README.*', 'lib/**/*.rb', 'LICENSE')
|
12
|
+
rdoc.options << '--inline-source'
|
13
|
+
end
|
14
|
+
|
15
|
+
Spec::Rake::SpecTask.new do |t|
|
16
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
17
|
+
t.spec_opts = ['--color','--format nested']
|
18
|
+
end
|
19
|
+
|
20
|
+
begin
|
21
|
+
require 'jeweler'
|
22
|
+
Jeweler::Tasks.new do |gemspec|
|
23
|
+
gemspec.name = "octocatnap"
|
24
|
+
gemspec.summary = "The GitHub API, wrapped in a Weary blanket"
|
25
|
+
gemspec.email = "mark@markwunsch.com"
|
26
|
+
gemspec.homepage = "http://github.com/mwunsch/octocatnap"
|
27
|
+
gemspec.description = "OctocatNap is a Ruby interface to the GitHub API v2. It is powered by Weary"
|
28
|
+
gemspec.authors = "Mark Wunsch"
|
29
|
+
gemspec.add_dependency('weary', '>= 0.4.0')
|
30
|
+
end
|
31
|
+
rescue LoadError
|
32
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
33
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.7.0
|
data/lib/octocatnap.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__))
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'weary'
|
5
|
+
|
6
|
+
autoload :Yaml, 'yaml'
|
7
|
+
|
8
|
+
require 'octocatnap/api'
|
9
|
+
require 'octocatnap/base'
|
10
|
+
|
11
|
+
module OctocatNap
|
12
|
+
def self.new(login=nil,token=nil)
|
13
|
+
OctocatNap::Base.new(login,token)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module OctocatNap
|
2
|
+
class Api
|
3
|
+
extend Weary
|
4
|
+
|
5
|
+
attr_reader :credentials
|
6
|
+
|
7
|
+
def initialize(credentials)
|
8
|
+
@credentials = credentials
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
class User < Api; end
|
13
|
+
class Issues < Api; end
|
14
|
+
class Repository < Api; end
|
15
|
+
class Commit < Api; end
|
16
|
+
class Object < Api; end
|
17
|
+
class Network < Api
|
18
|
+
on_domain "http://github.com/"
|
19
|
+
as_format :json
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,342 @@
|
|
1
|
+
module OctocatNap
|
2
|
+
class Base
|
3
|
+
attr_accessor :format
|
4
|
+
attr_reader :login, :token, :credentials
|
5
|
+
|
6
|
+
def initialize(login=nil, token=nil)
|
7
|
+
case
|
8
|
+
when (login.is_a?(TrueClass))
|
9
|
+
@login = `git config --global github.user`.strip
|
10
|
+
@token = `git config --global github.token`.strip
|
11
|
+
raise ArgumentError, "Missing GitHub credentials. See: 'http://github.com/guides/tell-git-your-user-name-and-email-address'" if @login.empty?
|
12
|
+
when (login.is_a?(String) && token.nil?)
|
13
|
+
raise ArgumentError, "A YAML file could not be found at '#{login}" unless File.exist?(login)
|
14
|
+
credentials = File.open(login) { |yml|
|
15
|
+
YAML::load yml
|
16
|
+
}
|
17
|
+
raise ArgumentError, "Missing credentials in '#{login}' (expected a YAML file)" unless credentials
|
18
|
+
@login = credentials["login"].to_s
|
19
|
+
@token = credentials["token"].to_s
|
20
|
+
when (login.is_a?(Hash) && token.nil?)
|
21
|
+
@login = login[:login].to_s
|
22
|
+
@token = login[:token].to_s
|
23
|
+
when (login.is_a?(Array) && token.nil?)
|
24
|
+
@login = login[0].to_s
|
25
|
+
@token = login[1].to_s
|
26
|
+
when (!login.nil? && !token.nil?)
|
27
|
+
@login = login.to_s
|
28
|
+
@token = token.to_s
|
29
|
+
else
|
30
|
+
@login = nil
|
31
|
+
@token = nil
|
32
|
+
end
|
33
|
+
@credentials = unless (@login.nil? && @token.nil?)
|
34
|
+
{:login => @login, :token => @token}
|
35
|
+
else
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def format
|
41
|
+
@format ||= :json
|
42
|
+
end
|
43
|
+
|
44
|
+
def format=(type)
|
45
|
+
type = type.downcase if type.is_a?(String)
|
46
|
+
@format = case type
|
47
|
+
when *Weary::ContentTypes[:json]
|
48
|
+
:json
|
49
|
+
when *Weary::ContentTypes[:xml]
|
50
|
+
:xml
|
51
|
+
when *Weary::ContentTypes[:html]
|
52
|
+
:html
|
53
|
+
when *Weary::ContentTypes[:yaml]
|
54
|
+
:yaml
|
55
|
+
when *Weary::ContentTypes[:plain]
|
56
|
+
:plain
|
57
|
+
else
|
58
|
+
raise ArgumentError, "#{type} is not a recognized format."
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# http://develop.github.com/p/users.html
|
63
|
+
def user(query) #query = search term or username
|
64
|
+
u = OctocatNap::User
|
65
|
+
u.always_with @credentials
|
66
|
+
u = set_defaults(u, "user")
|
67
|
+
|
68
|
+
u.get "search" do |r|
|
69
|
+
r.url = "<domain>/<resource>/#{query}"
|
70
|
+
end
|
71
|
+
|
72
|
+
u.get "show" do |r|
|
73
|
+
r.url = "<domain>/<resource>/#{query}"
|
74
|
+
end
|
75
|
+
|
76
|
+
u.post "update" do |r|
|
77
|
+
raise "You need to authenticate to perform this method. Please enter your credentials." if @credentials.nil?
|
78
|
+
r.url = "<domain>/show/#{query}"
|
79
|
+
r.requires = [:login,:token]
|
80
|
+
r.with = @credentials.merge({"values[name]" => nil, "values[email]" => nil, "values[blog]" => nil, "values[company]" => nil, "values[location]" => nil})
|
81
|
+
end
|
82
|
+
|
83
|
+
u.get "followers" do |r|
|
84
|
+
r.url = "<domain>/show/#{query}/<resource>"
|
85
|
+
end
|
86
|
+
|
87
|
+
u.get "following" do |r|
|
88
|
+
r.url = "<domain>/show/#{query}/<resource>"
|
89
|
+
end
|
90
|
+
|
91
|
+
u.post "follow" do |r|
|
92
|
+
r.url = "<domain>/<resource>/#{query}"
|
93
|
+
r.requires = [:login,:token]
|
94
|
+
end
|
95
|
+
|
96
|
+
u.post "unfollow" do |r|
|
97
|
+
r.url = "<domain>/<resource>/#{query}"
|
98
|
+
r.requires = [:login,:token]
|
99
|
+
end
|
100
|
+
|
101
|
+
u.get "keys" do |r|
|
102
|
+
r.url = "<domain>/keys"
|
103
|
+
r.requires = [:login,:token]
|
104
|
+
end
|
105
|
+
|
106
|
+
u.post "add_keys" do |r|
|
107
|
+
r.url = "<domain>/key/add"
|
108
|
+
r.requires = [:login, :token, :name, :key]
|
109
|
+
end
|
110
|
+
|
111
|
+
u.post "remove_keys" do |r|
|
112
|
+
r.url = "<domain>/key/remove"
|
113
|
+
r.requires = [:login, :token, :id]
|
114
|
+
end
|
115
|
+
return u.new(@credentials)
|
116
|
+
end
|
117
|
+
|
118
|
+
# http://develop.github.com/p/issues.html
|
119
|
+
def issues(user,repo,state,search_term,label,number)
|
120
|
+
i = OctocatNap::Issues
|
121
|
+
i.always_with @credentials
|
122
|
+
i = set_defaults(i, "issues")
|
123
|
+
i.get "search" do |r|
|
124
|
+
r.url ="<domain>/<resource>/#{user}/#{repo}/#{state}/#{search_term}"
|
125
|
+
end
|
126
|
+
|
127
|
+
i.get "list" do |r|
|
128
|
+
r.url = "<domain>/<resource>/#{user}/#{repo}/#{state}"
|
129
|
+
end
|
130
|
+
|
131
|
+
i.get "show" do |r|
|
132
|
+
r.url = "<domain>/<resource>/#{user}/#{repo}/#{number}"
|
133
|
+
end
|
134
|
+
|
135
|
+
i.post "open" do |r|
|
136
|
+
r.url = "<domain>/<resource>/#{user}/#{repo}"
|
137
|
+
r.requires = [:login, :token, :title, :body]
|
138
|
+
end
|
139
|
+
|
140
|
+
i.post "close" do |r|
|
141
|
+
r.url = "<domain>/<resource>/#{user}/#{repo}/#{number}"
|
142
|
+
r.requires = [:login, :token]
|
143
|
+
end
|
144
|
+
|
145
|
+
i.post "reopen" do |r|
|
146
|
+
r.url = "<domain>/<resource>/#{user}/#{repo}/#{number}"
|
147
|
+
r.requires = [:login, :token]
|
148
|
+
end
|
149
|
+
|
150
|
+
i.post "edit" do |r|
|
151
|
+
raise "You need to authenticate to perform this method. Please enter your credentials." if @credentials.nil?
|
152
|
+
r.url = "<domain>/<resource>/#{user}/#{repo}/#{number}"
|
153
|
+
r.requires = [:login, :token]
|
154
|
+
r.with = @credentials.merge(:title => nil, :body => nil)
|
155
|
+
end
|
156
|
+
|
157
|
+
i.post "add_label" do |r|
|
158
|
+
r.url = "<domain>/label/add/#{user}/#{repo}/#{label}/#{number}"
|
159
|
+
r.requires = [:login, :token]
|
160
|
+
end
|
161
|
+
|
162
|
+
i.post "remove_label" do |r|
|
163
|
+
r.url = "<domain>/label/remove/#{user}/#{repo}/#{label}/#{number}"
|
164
|
+
r.requires = [:login, :token]
|
165
|
+
end
|
166
|
+
|
167
|
+
i.post "comment" do |r|
|
168
|
+
r.url = "<domain>/<resource>/#{user}/#{repo}/#{number}"
|
169
|
+
r.requires = [:login, :token, :comment]
|
170
|
+
end
|
171
|
+
return i.new(@credentials)
|
172
|
+
end
|
173
|
+
|
174
|
+
# the Network API is only available in JSON
|
175
|
+
# http://develop.github.com/p/network.html
|
176
|
+
def network(user,repo)
|
177
|
+
n = OctocatNap::Network
|
178
|
+
n.get "meta" do |r|
|
179
|
+
r.url = "<domain>#{user}/#{repo}/network_meta"
|
180
|
+
end
|
181
|
+
|
182
|
+
n.get "data" do |r|
|
183
|
+
r.url = "<domain>#{user}/#{repo}/network_data_chunk"
|
184
|
+
r.requires = [:nethash]
|
185
|
+
r.with = [:start, :end]
|
186
|
+
end
|
187
|
+
|
188
|
+
return n.new(@credentials)
|
189
|
+
end
|
190
|
+
|
191
|
+
def repository(query, repo) #query = search term or user name
|
192
|
+
r = OctocatNap::Repository
|
193
|
+
r.always_with @credentials
|
194
|
+
r = set_defaults(r, "repos")
|
195
|
+
|
196
|
+
r.get "search" do |x|
|
197
|
+
x.url = "<domain>/<resource>/#{query}"
|
198
|
+
end
|
199
|
+
|
200
|
+
r.get "show" do |x|
|
201
|
+
x.url = "<domain>/<resource>/#{query}/#{repo}"
|
202
|
+
end
|
203
|
+
|
204
|
+
r.get "list" do |x|
|
205
|
+
x.url = "<domain>/show/#{query}"
|
206
|
+
end
|
207
|
+
|
208
|
+
r.get "unwatch" do |x|
|
209
|
+
x.requires = [:login, :token]
|
210
|
+
x.url = "<domain>/<resource>/#{query}/#{repo}"
|
211
|
+
end
|
212
|
+
|
213
|
+
r.get "watch" do |x|
|
214
|
+
x.requires = [:login, :token]
|
215
|
+
x.url = "<domain>/<resource>/#{query}/#{repo}"
|
216
|
+
end
|
217
|
+
|
218
|
+
r.get "fork" do |x|
|
219
|
+
x.requires = [:login, :token]
|
220
|
+
x.url = "<domain>/<resource>/#{query}/#{repo}"
|
221
|
+
end
|
222
|
+
|
223
|
+
r.post "create" do |x|
|
224
|
+
raise "You need to authenticate to perform this method. Please enter your credentials." if @credentials.nil?
|
225
|
+
x.requires = [:login, :token, :name]
|
226
|
+
x.with = @credentials.merge({:description => nil, :homepage => nil, :public => nil})
|
227
|
+
x.url = "<domain>/<resource>"
|
228
|
+
end
|
229
|
+
|
230
|
+
r.post "delete" do |x|
|
231
|
+
raise "You need to authenticate to perform this method. Please enter your credentials." if @credentials.nil?
|
232
|
+
x.requires = [:login, :token]
|
233
|
+
x.with = @credentials.merge({:delete_token => nil})
|
234
|
+
x.url = "<domain>/<resource>/#{repo}"
|
235
|
+
end
|
236
|
+
|
237
|
+
r.post "set_private" do |x|
|
238
|
+
x.requires = [:login, :token]
|
239
|
+
x.url = "<domain>/set/private/#{repo}"
|
240
|
+
end
|
241
|
+
|
242
|
+
r.post "set_public" do |x|
|
243
|
+
x.requires = [:login, :token]
|
244
|
+
x.url = "<domain>/set/public/#{repo}"
|
245
|
+
end
|
246
|
+
|
247
|
+
r.get "keys" do |x|
|
248
|
+
x.requires = [:login, :token]
|
249
|
+
x.url = "<domain>/<resource>/#{repo}"
|
250
|
+
end
|
251
|
+
|
252
|
+
r.post "add_key" do |x|
|
253
|
+
x.requires = [:login, :token, :title, :key]
|
254
|
+
x.url = "<domain>/key/#{repo}/add"
|
255
|
+
end
|
256
|
+
|
257
|
+
r.post "remove_key" do |x|
|
258
|
+
x.requires = [:login, :token, :id]
|
259
|
+
x.url = "<domain>/key/#{repo}/remove"
|
260
|
+
end
|
261
|
+
|
262
|
+
r.get "collaborators" do |x|
|
263
|
+
x.url = "<domain>/show/#{query}/#{repo}/<resource>"
|
264
|
+
end
|
265
|
+
|
266
|
+
r.post "add_collaborators" do |x|
|
267
|
+
x.requires = [:login, :token]
|
268
|
+
x.url = "<domain>/collaborators/#{repo}/add/#{query}"
|
269
|
+
end
|
270
|
+
|
271
|
+
r.post "remove_collaborators" do |x|
|
272
|
+
x.requires = [:login, :token]
|
273
|
+
x.url = "<domain>/collaborators/#{repo}/remove/#{query}"
|
274
|
+
end
|
275
|
+
|
276
|
+
r.get "network" do |x|
|
277
|
+
x.url = "<domain>/show/#{query}/#{repo}/<resource>"
|
278
|
+
end
|
279
|
+
|
280
|
+
r.get "tags" do |x|
|
281
|
+
x.url = "<domain>/show/#{query}/#{repo}/<resource>"
|
282
|
+
end
|
283
|
+
|
284
|
+
r.get "branches" do |x|
|
285
|
+
x.url = "<domain>/show/#{query}/#{repo}/<resource>"
|
286
|
+
end
|
287
|
+
|
288
|
+
return r.new(@credentials)
|
289
|
+
end
|
290
|
+
|
291
|
+
def commit(user,repo,branch,query) #query = path or sha
|
292
|
+
c = OctocatNap::Commit
|
293
|
+
c = set_defaults(c, "commits")
|
294
|
+
|
295
|
+
c.get "list" do |r|
|
296
|
+
r.url = "<domain>/<resource>/#{user}/#{repo}/#{branch}"
|
297
|
+
end
|
298
|
+
|
299
|
+
c.get "file" do |r|
|
300
|
+
r.url = "<domain>/list/#{user}/#{repo}/#{branch}/#{query}"
|
301
|
+
end
|
302
|
+
|
303
|
+
c.get "show" do |r|
|
304
|
+
r.url = "<domain>/<resource>/#{user}/#{repo}/#{query}"
|
305
|
+
end
|
306
|
+
return c.new(@credentials)
|
307
|
+
end
|
308
|
+
|
309
|
+
def tree(user,repo,tree_sha)
|
310
|
+
t = OctocatNap::Object
|
311
|
+
t = set_defaults(t, "tree")
|
312
|
+
|
313
|
+
t.get "show" do |r|
|
314
|
+
r.url = "<domain>/<resource>/#{user}/#{repo}/#{tree_sha}"
|
315
|
+
end
|
316
|
+
|
317
|
+
return t.new(@credentials)
|
318
|
+
end
|
319
|
+
|
320
|
+
def blob(user,repo,sha,path)
|
321
|
+
b = OctocatNap::Object
|
322
|
+
b = set_defaults(t, "blob")
|
323
|
+
|
324
|
+
b.get "raw" do |r|
|
325
|
+
r.url = "<domain>/show/#{user}/#{repo}/#{sha}"
|
326
|
+
end
|
327
|
+
|
328
|
+
b.get "show" do |r|
|
329
|
+
r.url = "<domain>/<resource>/#{user}/#{repo}/#{sha}/#{path}"
|
330
|
+
end
|
331
|
+
|
332
|
+
return b.new(@credentials)
|
333
|
+
end
|
334
|
+
|
335
|
+
private
|
336
|
+
def set_defaults(klass, domain)
|
337
|
+
klass.as_format format
|
338
|
+
klass.on_domain "http://github.com/api/v2/#{format}/#{domain}"
|
339
|
+
klass
|
340
|
+
end
|
341
|
+
end
|
342
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
|
+
|
3
|
+
describe OctocatNap::Api do
|
4
|
+
before do
|
5
|
+
@test = OctocatNap::Api.new({:login => "github_username", :token => "github_token"})
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should set credentials" do
|
9
|
+
@test.credentials.should == {:login => "github_username", :token => "github_token"}
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should set the Weary default format" do
|
13
|
+
@test.class.as_format :json
|
14
|
+
@test.class.instance_variable_get(:@default_format).should == :json
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should set the Weary domain" do
|
18
|
+
@test.class.on_domain "http://github.com/api/v2/"
|
19
|
+
@test.class.domain.should == "http://github.com/api/v2/"
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
|
+
|
3
|
+
describe OctocatNap::Base do
|
4
|
+
describe "Authentication" do
|
5
|
+
it "should be instantiated with a user's login and token" do
|
6
|
+
test = OctocatNap.new("github_username",:github_token)
|
7
|
+
test.login.should == "github_username"
|
8
|
+
test.token.should == "github_token"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "credentials can be in an array" do
|
12
|
+
test = OctocatNap.new(["github_username",:github_token])
|
13
|
+
test.login.should == "github_username"
|
14
|
+
test.token.should == "github_token"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "credentials can also be in a hash" do
|
18
|
+
test = OctocatNap.new({:login => "github_username",:token => "github_token"})
|
19
|
+
test.login.should == "github_username"
|
20
|
+
test.token.should == "github_token"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should look for a yaml file with login and token if a file name is passed" do
|
24
|
+
test = OctocatNap.new(File.join(File.dirname(__FILE__), '..', 'fixtures', "config.yml"))
|
25
|
+
test.login.should == "github_username"
|
26
|
+
test.token.should == "github_token"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should look for login/token in git config" do
|
30
|
+
test = OctocatNap.new(true)
|
31
|
+
test.login.class.should == String
|
32
|
+
test.login.class.should == String
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should be quiet if no login and token are passed" do
|
36
|
+
test = OctocatNap.new
|
37
|
+
test.login.should == nil
|
38
|
+
test.token.should == nil
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should create a credentials hash" do
|
42
|
+
test = OctocatNap.new
|
43
|
+
test.credentials.should == nil
|
44
|
+
test = OctocatNap.new(true)
|
45
|
+
test.credentials.class.should == Hash
|
46
|
+
test.credentials.has_key?(:login).should == true
|
47
|
+
test.credentials.has_key?(:token).should == true
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "Default Format" do
|
52
|
+
before do
|
53
|
+
@test = OctocatNap.new
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should set a default format of JSON on initialization" do
|
57
|
+
@test.format.should == :json
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should be able to set another format using Weary's validation" do
|
61
|
+
@test.format = 'yaml'
|
62
|
+
@test.format.should == :yaml
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "An API" do
|
67
|
+
before do
|
68
|
+
@test = OctocatNap.new(true)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should set the defaults" do
|
72
|
+
t = @test.user("markwunsch")
|
73
|
+
t.class.domain.should == "http://github.com/api/v2/json/user"
|
74
|
+
t.class.instance_variable_get(:@default_format).should == :json
|
75
|
+
t.credentials.class.should == Hash
|
76
|
+
t.credentials.has_key?(:login).should == true
|
77
|
+
t.credentials.has_key?(:token).should == true
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should produce a series of resources" do
|
81
|
+
@test.format = :yaml
|
82
|
+
t = @test.user("markwunsch")
|
83
|
+
t.class.resources.is_a?(Array).should == true
|
84
|
+
end
|
85
|
+
describe "Network API" do
|
86
|
+
it "should be on domain 'http://github.com/'" do
|
87
|
+
t = @test.network("mwunsch","octocatnap")
|
88
|
+
t.class.domain.should == "http://github.com/"
|
89
|
+
end
|
90
|
+
it "should be in JSON" do
|
91
|
+
@test.format = :yaml
|
92
|
+
t = @test.network("mwunsch","octocatnap")
|
93
|
+
t.class.instance_variable_get(:@default_format).should == :json
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mwunsch-octocatnap
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.7.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mark Wunsch
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-06-29 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: weary
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.4.0
|
24
|
+
version:
|
25
|
+
description: OctocatNap is a Ruby interface to the GitHub API v2. It is powered by Weary
|
26
|
+
email: mark@markwunsch.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.md
|
34
|
+
files:
|
35
|
+
- .gitignore
|
36
|
+
- LICENSE
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- VERSION
|
40
|
+
- examples/user_show.rb
|
41
|
+
- examples/user_update.rb
|
42
|
+
- lib/octocatnap.rb
|
43
|
+
- lib/octocatnap/api.rb
|
44
|
+
- lib/octocatnap/base.rb
|
45
|
+
- spec/fixtures/config.yml
|
46
|
+
- spec/octocatnap/api_spec.rb
|
47
|
+
- spec/octocatnap/base_spec.rb
|
48
|
+
- spec/octocatnap_spec.rb
|
49
|
+
- spec/spec_helper.rb
|
50
|
+
has_rdoc: true
|
51
|
+
homepage: http://github.com/mwunsch/octocatnap
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options:
|
54
|
+
- --charset=UTF-8
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "0"
|
62
|
+
version:
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
version:
|
69
|
+
requirements: []
|
70
|
+
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.2.0
|
73
|
+
signing_key:
|
74
|
+
specification_version: 2
|
75
|
+
summary: The GitHub API, wrapped in a Weary blanket
|
76
|
+
test_files:
|
77
|
+
- spec/octocatnap/api_spec.rb
|
78
|
+
- spec/octocatnap/base_spec.rb
|
79
|
+
- spec/octocatnap_spec.rb
|
80
|
+
- spec/spec_helper.rb
|
81
|
+
- examples/user_show.rb
|
82
|
+
- examples/user_update.rb
|