Class: Octopussy::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/octopussy/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(auth = {}) ⇒ Client

:login => ‘pengwynn’, :token => ‘your_github_api_key’



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/octopussy/client.rb', line 11

def initialize(auth={})
  if auth[:password].nil?
    @login = auth[:login]
    @token = auth[:token]
    self.class.basic_auth(nil, nil)
  else
    @login = auth[:login]
    self.class.basic_auth(@login, auth[:password])
  end
  
end

Instance Attribute Details

#loginObject (readonly)

Returns the value of attribute login.



8
9
10
# File 'lib/octopussy/client.rb', line 8

def 
  @login
end

#tokenObject (readonly)

Returns the value of attribute token.



8
9
10
# File 'lib/octopussy/client.rb', line 8

def token
  @token
end

Instance Method Details

#add_collaborator(repo, collaborator) ⇒ Object



281
282
283
284
285
# File 'lib/octopussy/client.rb', line 281

def add_collaborator(repo, collaborator)
  repo = Repo.new(repo)
  response = self.class.post("/repos/collaborators/#{repo.name}/add/#{collaborator}", :query => auth_params)
  Hashie::Mash.new(response).collaborators
end

#add_comment(repo, number, comment) ⇒ Object



165
166
167
168
169
# File 'lib/octopussy/client.rb', line 165

def add_comment(repo, number, comment)
  repo = Repo.new(repo)
  response = self.class.post("/issues/comment/#{repo.username}/#{repo.name}/#{number}", :body => {:comment => comment})
  Hashie::Mash.new(response).comment
end

#add_deploy_key(repo, key, title = '') ⇒ Object



231
232
233
234
235
# File 'lib/octopussy/client.rb', line 231

def add_deploy_key(repo, key, title='')
  repo = Repo.new(repo)
  response = self.class.post("/repos/key/#{repo.name}/add", :query => auth_params, :body => {:title => title, :key => key})
  Hashie::Mash.new(response).public_keys
end

#add_email(email) ⇒ Object



78
79
80
81
# File 'lib/octopussy/client.rb', line 78

def add_email(email)
  response = self.class.post("/user/email/add", :query => auth_params, :body => {:email => email})
  Hashie::Mash.new(response).emails
end

#add_key(title, key) ⇒ Object



93
94
95
96
# File 'lib/octopussy/client.rb', line 93

def add_key(title, key)
  response = self.class.post("/user/key/add", :query => auth_params, :body => {:title => title, :key => key})
  Hashie::Mash.new(response).public_keys
end

#add_label(repo, number, label) ⇒ Object



153
154
155
156
157
# File 'lib/octopussy/client.rb', line 153

def add_label(repo, number, label)
  repo = Repo.new(repo)
  response = self.class.post("/issues/label/add/#{repo.username}/#{repo.name}/#{label}/#{number}")
  Hashie::Mash.new(response).labels
end

#blob(repo, sha, path) ⇒ Object



339
340
341
342
343
# File 'lib/octopussy/client.rb', line 339

def blob(repo, sha, path)
  repo = Repo.new(repo)
  response = self.class.get("http://github.com/api/v2/json/blob/show/#{repo.username}/#{repo.name}/#{sha}/#{path}", :query => auth_params)
  Hashie::Mash.new(response).blob
end

#branches(repo) ⇒ Object



311
312
313
314
315
# File 'lib/octopussy/client.rb', line 311

def branches(repo)
  repo = Repo.new(repo)
  response = self.class.get("/repos/show/#{repo.username}/#{repo.name}/branches", :query => auth_params)
  Hashie::Mash.new(response).branches
end

#close_issue(repo, number) ⇒ Object



129
130
131
132
133
# File 'lib/octopussy/client.rb', line 129

def close_issue(repo, number)
  repo = Repo.new(repo)
  response = self.class.post("/issues/close/#{repo.username}/#{repo.name}/#{number}")
  Hashie::Mash.new(response).issue
end

#collaborators(repo) ⇒ Object



243
244
245
246
247
# File 'lib/octopussy/client.rb', line 243

def collaborators(repo)
  repo = Repo.new(repo)
  response = self.class.post("/repos/show/#{repo.username}/#{repo.name}/collaborators", :query => auth_params)
  Hashie::Mash.new(response).collaborators
end

#commit(repo, sha) ⇒ Object



359
360
361
362
363
# File 'lib/octopussy/client.rb', line 359

def commit(repo, sha)
  repo = Repo.new(repo)
  response = self.class.get("http://github.com/api/v2/json/commits/show/#{repo.username}/#{repo.name}/#{sha}")
  Hashie::Mash.new(response).commit
end

#confirm_delete(repo, delete_token) ⇒ Object



209
210
211
# File 'lib/octopussy/client.rb', line 209

def confirm_delete(repo, delete_token)
  delete(repo, delete_token)
end

#contributors(repo) ⇒ Object



249
250
251
252
253
# File 'lib/octopussy/client.rb', line 249

def contributors(repo)
  repo = Repo.new(repo)
  response = self.class.get("/repos/show/#{repo.username}/#{repo.name}/contributors")
  Hashie::Mash.new(response).contributors
end

#create(options) ⇒ Object

:name, :description, :homepage, :public



198
199
200
201
# File 'lib/octopussy/client.rb', line 198

def create(options)
  response = self.class.post("/repos/create", :query => auth_params, :body => options)
  Hashie::Mash.new(response).repository
end

#delete(repo, delete_token = {}) ⇒ Object



203
204
205
206
207
# File 'lib/octopussy/client.rb', line 203

def delete(repo, delete_token={})
  repo = Repo.new(repo)
  response = self.class.post("/repos/delete/#{repo.name}", :query => auth_params, :body => {:delete_token => delete_token})
  Hashie::Mash.new(response)
end

#deploy_keys(repo) ⇒ Object



225
226
227
228
229
# File 'lib/octopussy/client.rb', line 225

def deploy_keys(repo)
  repo = Repo.new(repo)
  response = self.class.get("/repos/keys/#{repo.name}", :query => auth_params)
  Hashie::Mash.new(response).public_keys
end

#emailsObject



73
74
75
76
# File 'lib/octopussy/client.rb', line 73

def emails
  response = self.class.get("/user/emails", :query => auth_params)
  Hashie::Mash.new(response).emails
end

#follow!(username) ⇒ Object



50
51
52
53
# File 'lib/octopussy/client.rb', line 50

def follow!(username)
  response = self.class.post("/user/follow/#{username}", :query => auth_params)
  Hashie::Mash.new(response).users
end

#followers(login = self.login) ⇒ Object



40
41
42
43
# File 'lib/octopussy/client.rb', line 40

def followers(=self.)
  response = self.class.get("/user/show/#{}/followers")
  Hashie::Mash.new(response).users
end

#following(login = self.login) ⇒ Object



45
46
47
48
# File 'lib/octopussy/client.rb', line 45

def following(=self.)
  response = self.class.get("/user/show/#{}/following")
  Hashie::Mash.new(response).users
end

#follows?(*args) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
63
64
65
66
# File 'lib/octopussy/client.rb', line 60

def follows?(*args)
  target = args.pop
  username = args.first 
  username ||= self.
  return if username.nil?
  self.following(username).include?(target)
end

#fork(repo) ⇒ Object



191
192
193
194
195
# File 'lib/octopussy/client.rb', line 191

def fork(repo)
  repo = Repo.new(repo)
  response = self.class.post("/repos/fork/#{repo.username}/#{repo.name}", :query => auth_params)
  Hashie::Mash.new(response).repository
end

#issue(repo, id) ⇒ Object



117
118
119
120
121
# File 'lib/octopussy/client.rb', line 117

def issue(repo, id)
  repo = Repo.new(repo)
  response = self.class.get("/issues/show/#{repo.username}/#{repo.name}/#{id}")
  Hashie::Mash.new(response).issue
end

#issues(repo, state) ⇒ Object



111
112
113
114
115
# File 'lib/octopussy/client.rb', line 111

def issues(repo, state)
  repo = Repo.new(repo)
  response = self.class.get("/issues/list/#{repo.username}/#{repo.name}/#{state}")
  Hashie::Mash.new(response).issues
end

#keysObject



88
89
90
91
# File 'lib/octopussy/client.rb', line 88

def keys
  response = self.class.get("/user/keys", :query => auth_params)
  Hashie::Mash.new(response).public_keys
end

#labels(repo) ⇒ Object



147
148
149
150
151
# File 'lib/octopussy/client.rb', line 147

def labels(repo)
  repo = Repo.new(repo)
  response = self.class.get("/issues/labels/#{repo.username}/#{repo.name}")
  Hashie::Mash.new(response).labels
end

#languages(repo) ⇒ Object



299
300
301
302
303
# File 'lib/octopussy/client.rb', line 299

def languages(repo)
  repo = Repo.new(repo)
  response = self.class.get("/repos/show/#{repo.username}/#{repo.name}/languages")
  Hashie::Mash.new(response).languages
end

#list_commits(repo, branch = "master") ⇒ Object

Commits



353
354
355
356
357
# File 'lib/octopussy/client.rb', line 353

def list_commits(repo, branch="master")
  repo = Repo.new(repo)
  response = self.class.get("http://github.com/api/v2/json/commits/list/#{repo.username}/#{repo.name}/#{branch}")
  Hashie::Mash.new(response).commits
end

#list_repos(username = nil) ⇒ Object



271
272
273
274
275
276
277
278
279
# File 'lib/octopussy/client.rb', line 271

def list_repos(username = nil)
  if username.nil? && !@login.nil?
    username = 
  elsif username.nil?
    raise ArgumentError, 'you must provide a username'
  end
  response = self.class.get("/repos/show/#{username}", :query => auth_params)
  Hashie::Mash.new(response).repositories
end

#network(repo) ⇒ Object



293
294
295
296
297
# File 'lib/octopussy/client.rb', line 293

def network(repo)
  repo = Repo.new(repo)
  response = self.class.get("/repos/show/#{repo.username}/#{repo.name}/network")
  Hashie::Mash.new(response).network
end

#network_data(repo, nethash) ⇒ Object



325
326
327
328
329
# File 'lib/octopussy/client.rb', line 325

def network_data(repo, nethash)
  repo = Repo.new(repo)
  response = self.class.get("http://github.com/#{repo.username}/#{repo.name}/network_data_chunk", :query => {:nethash => nethash})
  Hashie::Mash.new(response).commits
end

#network_meta(repo) ⇒ Object

Network



319
320
321
322
323
# File 'lib/octopussy/client.rb', line 319

def network_meta(repo)
  repo = Repo.new(repo)
  response = self.class.get("http://github.com/#{repo.username}/#{repo.name}/network_meta")
  Hashie::Mash.new(response)
end

#open_issue(repo, title, body) ⇒ Object



123
124
125
126
127
# File 'lib/octopussy/client.rb', line 123

def open_issue(repo, title, body)
  repo = Repo.new(repo)
  response = self.class.post("/issues/open/#{repo.username}/#{repo.name}", :body => {:title => title, :body => body})
  Hashie::Mash.new(response).issue
end

#public_timeline(username = nil) ⇒ Object



365
366
367
368
369
370
371
372
373
374
# File 'lib/octopussy/client.rb', line 365

def public_timeline(username = nil)
  username ||= @login
  if username.nil?
    path = "http://github.com/timeline.json"
  else 
    path = "http://github.com/#{username}.json"
  end
  response = self.class.get(path)
  response.map{|item| Hashie::Mash.new(item)}
end

#raw(repo, sha) ⇒ Object



345
346
347
348
349
# File 'lib/octopussy/client.rb', line 345

def raw(repo, sha)
  repo = Repo.new(repo)
  response = self.class.get("http://github.com/api/v2/yaml/blob/show/#{repo.username}/#{repo.name}/#{sha}", :query => auth_params)
  response.body
end

#remove_collaborator(repo, collaborator) ⇒ Object



287
288
289
290
291
# File 'lib/octopussy/client.rb', line 287

def remove_collaborator(repo, collaborator)
  repo = Repo.new(repo)
  response = self.class.post("/repos/collaborators/#{repo.name}/remove/#{collaborator}", :query => auth_params)
  Hashie::Mash.new(response).collaborators
end

#remove_deploy_key(repo, id) ⇒ Object



237
238
239
240
241
# File 'lib/octopussy/client.rb', line 237

def remove_deploy_key(repo, id)
  repo = Repo.new(repo)
  response = self.class.post("/repos/key/#{repo.name}/remove", :query => auth_params, :body => {:id => id})
  Hashie::Mash.new(response).public_keys
end

#remove_email(email) ⇒ Object



83
84
85
86
# File 'lib/octopussy/client.rb', line 83

def remove_email(email)
  response = self.class.post("/user/email/remove", :query => auth_params, :body => {:email => email})
  Hashie::Mash.new(response).emails
end

#remove_key(id) ⇒ Object



98
99
100
101
# File 'lib/octopussy/client.rb', line 98

def remove_key(id)
  response = self.class.post("/user/key/remove", :query => auth_params, :body => {:id => id})
  Hashie::Mash.new(response).public_keys
end

#remove_label(repo, number, label) ⇒ Object



159
160
161
162
163
# File 'lib/octopussy/client.rb', line 159

def remove_label(repo, number, label)
  repo = Repo.new(repo)
  response = self.class.post("/issues/label/remove/#{repo.username}/#{repo.name}/#{label}/#{number}")
  Hashie::Mash.new(response).labels
end

#reopen_issue(repo, number) ⇒ Object



135
136
137
138
139
# File 'lib/octopussy/client.rb', line 135

def reopen_issue(repo, number)
  repo = Repo.new(repo)
  response = self.class.post("/issues/reopen/#{repo.username}/#{repo.name}/#{number}")
  Hashie::Mash.new(response).issue
end

#repo(repo) ⇒ Object



255
256
257
258
259
# File 'lib/octopussy/client.rb', line 255

def repo(repo)
  repo = Repo.new(repo)
  response = self.class.get("/repos/show/#{repo.username}/#{repo.name}", :query => auth_params)
  Hashie::Mash.new(response).repository
end

#search_issues(repo, state, q) ⇒ Object

Issues



105
106
107
108
109
# File 'lib/octopussy/client.rb', line 105

def search_issues(repo, state, q)
  repo = Repo.new(repo)
  response = self.class.get("/issues/search/#{repo.username}/#{repo.name}/#{state}/#{q}")
  Hashie::Mash.new(response).issues
end

#search_repos(q) ⇒ Object

Repos



173
174
175
176
177
# File 'lib/octopussy/client.rb', line 173

def search_repos(q)
  q = CGI.escape(q)
  response = self.class.get("/repos/search/#{q}")
  Hashie::Mash.new(response).repositories
end

#search_users(q) ⇒ Object



23
24
25
26
27
# File 'lib/octopussy/client.rb', line 23

def search_users(q)
  q = CGI.escape(q)
  response = self.class.get("/user/search/#{q}")
  Hashie::Mash.new(response).users
end

#set_private(repo) ⇒ Object



213
214
215
216
217
# File 'lib/octopussy/client.rb', line 213

def set_private(repo)
  repo = Repo.new(repo)
  response = self.class.post("/repos/set/private/#{repo.name}", :query => auth_params)
  Hashie::Mash.new(response).repository
end

#set_public(repo) ⇒ Object



219
220
221
222
223
# File 'lib/octopussy/client.rb', line 219

def set_public(repo)
  repo = Repo.new(repo)
  response = self.class.post("/repos/set/public/#{repo.name}", :query => auth_params)
  Hashie::Mash.new(response).repository
end

#set_repo_info(repo, options) ⇒ Object

pass options without the “values” descriped in the API docs:

set_repo_info('user/repo', :description => "hey!", :has_wiki => false)


263
264
265
266
267
268
269
# File 'lib/octopussy/client.rb', line 263

def set_repo_info(repo, options)
  repo = Repo.new(repo)
  # post body needs to be "values[has_wiki]=false"
  response = self.class.post("/repos/show/#{repo.username}/#{repo.name}",
    :body => options.keys.reduce({}) { |a,v| a["values[#{v}]"] = options[v]; a }.merge(auth_params))
  Hashie::Mash.new(response).repository
end

#tags(repo) ⇒ Object



305
306
307
308
309
# File 'lib/octopussy/client.rb', line 305

def tags(repo)
  repo = Repo.new(repo)
  response = self.class.get("/repos/show/#{repo.username}/#{repo.name}/tags")
  Hashie::Mash.new(response).tags
end

#timelineObject



376
377
378
379
# File 'lib/octopussy/client.rb', line 376

def timeline
  response = self.class.get("http://github.com/#{@login}.private.json", :query => auth_params)
  response.map{|item| Hashie::Mash.new(item)}
end

#tree(repo, sha) ⇒ Object

Trees



333
334
335
336
337
# File 'lib/octopussy/client.rb', line 333

def tree(repo, sha)
  repo = Repo.new(repo)
  response = self.class.get("http://github.com/api/v2/json/tree/show/#{repo.username}/#{repo.name}/#{sha}", :query => auth_params)
  Hashie::Mash.new(response).tree
end

#unfollow!(username) ⇒ Object



55
56
57
58
# File 'lib/octopussy/client.rb', line 55

def unfollow!(username)
  response = self.class.post("/user/unfollow/#{username}", :query => auth_params)
  Hashie::Mash.new(response).users
end

#unwatch(repo) ⇒ Object



185
186
187
188
189
# File 'lib/octopussy/client.rb', line 185

def unwatch(repo)
  repo = Repo.new(repo)
  response = self.class.post("/repos/unwatch/#{repo.username}/#{repo.name}", :query => auth_params)
  Hashie::Mash.new(response).repository
end

#update_issue(repo, number, title, body) ⇒ Object



141
142
143
144
145
# File 'lib/octopussy/client.rb', line 141

def update_issue(repo, number, title, body)
  repo = Repo.new(repo)
  response = self.class.post("/issues/edit/#{repo.username}/#{repo.name}/#{number}", :body => {:title => title, :body => body})
  Hashie::Mash.new(response).issue
end

#update_user(values = {}) ⇒ Object



35
36
37
38
# File 'lib/octopussy/client.rb', line 35

def update_user(values={})
  response = self.class.post("/user/show/#{self.}", :query => auth_params, :body => {:values => values})
  Hashie::Mash.new(response).user
end

#user(login = self.login) ⇒ Object



29
30
31
32
# File 'lib/octopussy/client.rb', line 29

def user(=self.)
  response = self.class.get("/user/show/#{}", :query => auth_params)
  Hashie::Mash.new(response).user
end

#watch(repo) ⇒ Object



179
180
181
182
183
# File 'lib/octopussy/client.rb', line 179

def watch(repo)
  repo = Repo.new(repo)
  response = self.class.post("/repos/watch/#{repo.username}/#{repo.name}", :query => auth_params)
  Hashie::Mash.new(response).repository
end

#watched(login = self.login) ⇒ Object



68
69
70
71
# File 'lib/octopussy/client.rb', line 68

def watched(=self.)
  response = self.class.get("/repos/watched/#{}")
  Hashie::Mash.new(response).repositories
end