Sha256: 9b27cf27282ea6c8d59de6b278cfc777bd0707762a6e04bd59b50b1e1d913fb8

Contents?: true

Size: 1.9 KB

Versions: 2

Compression:

Stored size: 1.9 KB

Contents

# frozen_string_literal: true

require "dotenv/load"
require "net/http"
require "json"

# Create a client to log Meetup activities in your Orbit workspace
# Credentials can either be passed in to the instance or be loaded
# from environment variables
#
# @example
#   client = MeetupOrbit::Client.new
#
# @option params [String] :orbit_api_key
#   The API key for the Orbit API
#
# @option params [String] :orbit_workspace
#   The workspace ID for the Orbit workspace
#
# @option params [String] :meetup_urlname
#   The URL identifier of your Meetup
#
# @option params [Boolean] :historical_import
#   Whether to do an import of all Meetup interactions ignoring latest
#   activity already in the Orbit workspace.
#   Default is false.
#
# @param [Hash] params
#
# @return [MeetupOrbit::Client]
#
module MeetupOrbit
  class Client
    attr_accessor :orbit_api_key, :orbit_workspace, :meetup_urlname, :historical_import

    def initialize(params = {})
      @orbit_api_key = params.fetch(:orbit_api_key, ENV["ORBIT_API_KEY"])
      @orbit_workspace = params.fetch(:orbit_workspace, ENV["ORBIT_WORKSPACE_ID"])
      @meetup_urlname = check_urlname(params.fetch(:meetup_urlname, ENV["MEETUP_URLNAME"]))
      @historical_import = params.fetch(:historical_import, false)
    end

    def event_rsvps
      MeetupOrbit::Meetup.new(
        meetup_urlname: @meetup_urlname,
        orbit_api_key: @orbit_api_key,
        orbit_workspace: @orbit_workspace,
        historical_import: @historical_import
      ).process_event_rsvps
    end

    private

    def check_urlname(urlname)
      if urlname.start_with?("http://") || urlname.start_with?("https://") || urlname.start_with?("www") || urlname.start_with?("meetup.com")
        raise ArgumentError,
              "'meetup_urlname' parameter must only be the unique identifier of your meetup not the entire URL. Please refer to the README for more details."
      end

      urlname
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
meetup_orbit-0.1.1 lib/meetup_orbit/client.rb
meetup_orbit-0.1.0 lib/meetup_orbit/client.rb