Class: Codeowners::Import::Client
- Inherits:
-
Object
- Object
- Codeowners::Import::Client
- Defined in:
- lib/codeowners/import/client.rb
Instance Method Summary collapse
-
#initialize(token, out, base_url = BASE_URL, user_agent = USER_AGENT, client = Excon, sleep_time: 3) ⇒ Client
constructor
A new instance of Client.
- #org(login, debug = false) ⇒ Object
- #org_members(org, debug = false) ⇒ Object
- #team_members(org, teams, debug = false) ⇒ Object
- #teams(org, debug = false) ⇒ Object
- #users(users, debug) ⇒ Object
Constructor Details
#initialize(token, out, base_url = BASE_URL, user_agent = USER_AGENT, client = Excon, sleep_time: 3) ⇒ Client
Returns a new instance of Client.
15 16 17 18 19 20 21 22 |
# File 'lib/codeowners/import/client.rb', line 15 def initialize(token, out, base_url = BASE_URL, user_agent = USER_AGENT, client = Excon, sleep_time: 3) @base_url = base_url @user_agent = user_agent @token = token @client = client @out = out @sleep_time = sleep_time end |
Instance Method Details
#org(login, debug = false) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/codeowners/import/client.rb', line 24 def org(login, debug = false) result = get("/orgs/#{login}", debug: debug) { id: result.fetch("id"), login: result.fetch("login") } end |
#org_members(org, debug = false) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/codeowners/import/client.rb', line 33 def org_members(org, debug = false) result = get_paginated("/orgs/#{org.fetch(:login)}/members", debug: debug) result.map do |user| { id: user.fetch("id"), login: user.fetch("login") } end end |
#team_members(org, teams, debug = false) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/codeowners/import/client.rb', line 55 def team_members(org, teams, debug = false) teams.each_with_object([]) do |team, memo| result = get_paginated("/orgs/#{org.fetch(:login)}/teams/#{team.fetch(:slug)}/members", debug: debug) result.each do |member| team_id = team.fetch(:id) user_id = member.fetch("id") memo << { id: [team_id, user_id], team_id: team_id, user_id: user_id } end sleep_for_a_while end end |
#teams(org, debug = false) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/codeowners/import/client.rb', line 43 def teams(org, debug = false) result = get_paginated("/orgs/#{org.fetch(:login)}/teams", debug: debug) result.map do |team| { id: team.fetch("id"), org_id: org.fetch(:id), name: team.fetch("name"), slug: team.fetch("slug") } end end |
#users(users, debug) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/codeowners/import/client.rb', line 73 def users(users, debug) users.each do |user| remote_user = get("/users/#{user.fetch(:login)}", debug: debug) user.merge!( name: remote_user.fetch("name"), email: remote_user.fetch("email") ) sleep_for_a_while end end |