Class: MeetupOrbit::Meetup

Inherits:
Object
  • Object
show all
Defined in:
lib/meetup_orbit/meetup.rb

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Meetup

Returns a new instance of Meetup.



5
6
7
8
9
10
# File 'lib/meetup_orbit/meetup.rb', line 5

def initialize(params = {})
  @meetup_urlname = params.fetch(:meetup_urlname)
  @orbit_api_key = params.fetch(:orbit_api_key)
  @orbit_workspace = params.fetch(:orbit_workspace)
  @historical_import = params.fetch(:historical_import, false)
end

Instance Method Details

#get_eventsObject



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/meetup_orbit/meetup.rb', line 59

def get_events
  url = URI("https://api.meetup.com/#{@meetup_urlname}/events")

  https = Net::HTTP.new(url.host, url.port)
  https.use_ssl = true

  request = Net::HTTP::Get.new(url)

  response = https.request(request)

  response = JSON.parse(response.body)
end

#get_rsvps(event) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/meetup_orbit/meetup.rb', line 72

def get_rsvps(event)
  url = URI("https://api.meetup.com/#{@meetup_urlname}/events/#{event}/rsvps")

  https = Net::HTTP.new(url.host, url.port)
  https.use_ssl = true

  request = Net::HTTP::Get.new(url)

  response = https.request(request)

  response = JSON.parse(response.body)
end

#last_orbit_activity_timestampObject



85
86
87
88
89
90
91
92
93
# File 'lib/meetup_orbit/meetup.rb', line 85

def last_orbit_activity_timestamp
  @last_orbit_activity_timestamp ||= OrbitActivities::Request.new(
    api_key: @orbit_api_key,
    workspace_id: @orbit_workspace,
    user_agent: "community-ruby-meetup-orbit/#{MeetupOrbit::VERSION}",
    action: "latest_activity_timestamp",
    filters: { activity_type: "custom:meetup:rsvp" }
  ).response
end

#process_event_rsvpsObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/meetup_orbit/meetup.rb', line 12

def process_event_rsvps
  events = get_events

  times = 0
  events.each do |event|
    next if event["yes_rsvp_count"] <= 1 || event["yes_rsvp_count"].nil?

    rsvps = get_rsvps(event["id"])

    orbit_timestamp = last_orbit_activity_timestamp

    rsvps.drop(1).each do |rsvp| # skip first item which is event owner
        unless @historical_import && orbit_timestamp # rubocop:disable all
            next if Time.at(rsvp["created"] / 1000).utc.to_s < orbit_timestamp unless orbit_timestamp.nil? # rubocop:disable all
        end

        if orbit_timestamp && @historical_import == false
            next if Time.at(rsvp["created"] / 1000).utc.to_s < orbit_timestamp # rubocop:disable all
        end

        times += 1

        MeetupOrbit::Orbit.call(
          type: "event_rsvp",
          data: {
            rsvp: {
              event: rsvp["event"]["name"],
              group: rsvp["group"]["name"],
              member_id: rsvp["member"]["id"],
              member_name: rsvp["member"]["name"],
              occurred_at: Time.at(rsvp["created"] / 1000).utc.to_s,
              id: "#{rsvp["member"]["id"]}-#{rsvp["event"]["id"]}",
              link: "https://meetup.com/#{@meetup_urlname}/events/#{rsvp["event"]["id"]}",
              response: rsvp["response"]
            }
          },
          orbit_api_key: @orbit_api_key,
          orbit_workspace: @orbit_workspace
        )
    end
  end

  output = "Sent #{times} new RSVPs to your Orbit workspace"
  puts output
  output
end