-
Notifications
You must be signed in to change notification settings - Fork 0
/
gists.rb
94 lines (80 loc) · 2.18 KB
/
gists.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#---
# Excerpted from "Metaprogramming Ruby 2",
# published by The Pragmatic Bookshelf.
# Copyrights apply to this code. It may not be used to create training material,
# courses, books, articles, and the like. Contact us if you are in doubt.
# We make no guarantees that this code is fit for any purpose.
# Visit http://www.pragmaticprogrammer.com/titles/ppmetr2 for more book information.
#---
class Ghee
# API module encapsulates all of API endpoints
# implemented thus far
#
module API
# The Gists module handles all of the Github Gist
# API endpoints
#
module Gists
module Comments
class Proxy < ::Ghee::ResourceProxy
end
end
# Gists::Proxy inherits from Ghee::Proxy and
# enables defining methods on the proxy object
#
class Proxy < ::Ghee::ResourceProxy
def comments(id = nil)
prefix = id ? "#{path_prefix}/comments/#{id}" : "#{path_prefix}/comments"
return Ghee::API::Gists::Comments::Proxy.new connection, prefix
end
# Star a gist
#
# Returns true/false
#
def star
connection.put("#{path_prefix}/star").status == 204
end
# ...
# Unstar a gist
#
# Returns true/false
#
def unstar
connection.delete("#{path_prefix}/star").status == 204
end
# Returns whether gist is starred
#
# Returns true/false
#
def starred?
connection.get("#{path_prefix}/star").status == 204
end
# Get public gists
#
# Returns json
#
def public
connection.get("#{path_prefix}/public").body
end
# Get starred gists
#
# Returns json
#
def starred
connection.get("#{path_prefix}/starred").body
end
end
# Get gists
#
# id - String of gist id
#
# Returns json
#
def gists(id=nil, params={})
params = id if id.is_a?Hash
path_prefix = (!id.is_a?(Hash) and id) ? "/gists/#{id}" : '/gists'
Proxy.new(connection, path_prefix,params)
end
end
end
end