Sha256: 84c979b9c3bc44039430f1fbd5bb81534514483c0476e72558bf57f15a796c37

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

require "esa_piyo/version"
require "esa"
require "json"

module EsaPiyo
  class Error < StandardError; end

  class Client 
    def initialize(access_token: nil, current_team: nil)
      @client = Esa::Client.new(access_token: access_token, current_team: current_team)
    end

    def screen_name(email: nil)

      params = {
        page: 1,
        per_page: 100,
      }

      begin
        res = @client.members(params)
        body = res.body
        members = body["members"]

        members.each do |member| 
          if member["email"] == email then
            return member["screen_name"]
          end
        end

        params[:page] = body["next_page"]
      end until params[:page].nil?

      return 
    end

    def email(screen_name: nil)

      params = {
        page: 1,
        per_page: 100,
      }

      begin
        res = @client.members(params)
        body = res.body
        members = body["members"]

        members.each do |member| 
          if member["screen_name"] == screen_name then
            return member["email"]
          end
        end

        params[:page] = body["next_page"]
      end until params[:page].nil?

      return 
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
esa_piyo-0.1.0 lib/esa_piyo.rb