Class: Ossy::Github::Client
- Inherits:
-
Object
- Object
- Ossy::Github::Client
- Defined in:
- lib/ossy/github/client.rb
Direct Known Subclasses
Constant Summary collapse
- BASE_URL =
"https://api.github.com"
Instance Method Summary collapse
- #get(path, opts = {}) ⇒ Object
- #headers ⇒ Object
- #http ⇒ Object
- #member(name, org:) ⇒ Object
- #membership?(username, org:, team:) ⇒ Boolean
- #post(path, input) ⇒ Object
- #request(meth, path, opts = {}) ⇒ Object
- #tagger(repo:, tag:) ⇒ Object
- #user(login) ⇒ Object
Instance Method Details
#get(path, opts = {}) ⇒ Object
68 69 70 |
# File 'lib/ossy/github/client.rb', line 68 def get(path, opts = {}) request(:get, path, params: opts) end |
#headers ⇒ Object
82 83 84 85 |
# File 'lib/ossy/github/client.rb', line 82 def headers { "Content-Type" => "application/json", "Accept" => "application/vnd.github.everest-preview+json" } end |
#http ⇒ Object
76 77 78 79 80 |
# File 'lib/ossy/github/client.rb', line 76 def http @http ||= Faraday.new(url: BASE_URL, headers: headers) do |conn| conn.request(:basic_auth, settings.github_login, settings.github_token) end end |
#member(name, org:) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ossy/github/client.rb', line 44 def member(name, org:) path = "orgs/#{org}/members" resp = get(path) return nil unless resp.status.equal?(200) JSON.parse(resp.body) .map { |member| user(member["login"]) } .detect { |user| user["name"].eql?(name) } end |
#membership?(username, org:, team:) ⇒ Boolean
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ossy/github/client.rb', line 15 def membership?(username, org:, team:) path = "orgs/#{org}/teams/#{team}/memberships/#{username}" resp = get(path) return false unless resp.status.equal?(200) json = JSON.parse(resp.body) json["state"].eql?("active") end |
#post(path, input) ⇒ Object
72 73 74 |
# File 'lib/ossy/github/client.rb', line 72 def post(path, input) request(:post, path, JSON.dump(input)) end |
#request(meth, path, opts = {}) ⇒ Object
64 65 66 |
# File 'lib/ossy/github/client.rb', line 64 def request(meth, path, opts = {}) http.public_send(meth, path, opts) end |
#tagger(repo:, tag:) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ossy/github/client.rb', line 26 def tagger(repo:, tag:) path = "repos/#{repo}/git/ref/tags/#{tag}" resp = get(path) return false unless resp.status.equal?(200) sha = JSON.parse(resp.body)["object"]["sha"] path = "repos/#{repo}/git/tags/#{sha}" resp = get(path) return false unless resp.status.equal?(200) json = JSON.parse(resp.body) { tagger: json["tagger"], verified: json["verification"]["verified"] } end |
#user(login) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/ossy/github/client.rb', line 55 def user(login) path = "users/#{login}" resp = get(path) return nil unless resp.status.equal?(200) JSON.parse(resp.body) end |