Class: Githu3::Client
- Inherits:
-
Object
- Object
- Githu3::Client
- Extended by:
- Forwardable
- Defined in:
- lib/githu3/client.rb
Constant Summary collapse
- BaseUrl =
"https://api.github.com"
Instance Attribute Summary collapse
-
#auth ⇒ Object
readonly
Returns the value of attribute auth.
-
#conn ⇒ Object
readonly
Returns the value of attribute conn.
Instance Method Summary collapse
- #authenticated? ⇒ Boolean
- #followers(params = {}) ⇒ Object
- #following(params = {}) ⇒ Object
- #following?(other_user) ⇒ Boolean
- #get(*args) ⇒ Object
-
#initialize(*args) ⇒ Client
constructor
A new instance of Client.
-
#me ⇒ Object
My stuf…
- #orgs(params = {}) ⇒ Object
- #repos(params = {}) ⇒ Object
- #teams ⇒ Object
Constructor Details
#initialize(*args) ⇒ Client
Returns a new instance of Client.
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/githu3/client.rb', line 20 def initialize(*args) opts = args. @conn = Githu3::Connection.new opts do |c| case args.length when 1 @auth = :token c.headers["Authorization"] = "token #{args.first}" when 2 @auth = :basic c.basic_auth(*args) end end end |
Instance Attribute Details
#auth ⇒ Object (readonly)
Returns the value of attribute auth.
18 19 20 |
# File 'lib/githu3/client.rb', line 18 def auth @auth end |
#conn ⇒ Object (readonly)
Returns the value of attribute conn.
18 19 20 |
# File 'lib/githu3/client.rb', line 18 def conn @conn end |
Instance Method Details
#authenticated? ⇒ Boolean
34 35 36 |
# File 'lib/githu3/client.rb', line 34 def authenticated? !!@auth end |
#followers(params = {}) ⇒ Object
76 77 78 79 |
# File 'lib/githu3/client.rb', line 76 def followers params={} require_auth Githu3::ResourceCollection.new(self, Githu3::User, "/user/followers", params) end |
#following(params = {}) ⇒ Object
81 82 83 84 |
# File 'lib/githu3/client.rb', line 81 def following params={} require_auth Githu3::ResourceCollection.new(self, Githu3::User, "/user/following", params) end |
#following?(other_user) ⇒ Boolean
86 87 88 89 90 91 92 93 |
# File 'lib/githu3/client.rb', line 86 def following?(other_user) require_auth begin get("/user/following/#{other_user}").status == 204 rescue Githu3::NotFound false end end |
#get(*args) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/githu3/client.rb', line 38 def get *args opts = args. uri = URI.parse(args.shift) uri.query = (opts[:params] || {}).stringify_keys.merge(Hash.from_url_params(uri.query || "")).to_url_params res = @conn.get(uri, opts[:headers]) res end |
#me ⇒ Object
My stuf…
56 57 58 59 |
# File 'lib/githu3/client.rb', line 56 def me require_auth Githu3::User.new "/user", self end |
#orgs(params = {}) ⇒ Object
61 62 63 64 |
# File 'lib/githu3/client.rb', line 61 def orgs params={} require_auth Githu3::ResourceCollection.new(self, Githu3::Org, "/user/orgs", params) end |
#repos(params = {}) ⇒ Object
66 67 68 69 |
# File 'lib/githu3/client.rb', line 66 def repos params={} require_auth Githu3::ResourceCollection.new(self, Githu3::Repo, "/user/repos", params) end |
#teams ⇒ Object
71 72 73 74 |
# File 'lib/githu3/client.rb', line 71 def teams require_auth Githu3::ResourceCollection.new(self, Githu3::Team, "/user/teams") end |