Skip to content

Commit c8c60e5

Browse files
authored
Refactor Ruby classes into separate files (#726)
1 parent 47e2824 commit c8c60e5

11 files changed

+221
-200
lines changed

Rakefile

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
#!/usr/bin/env rake
2-
require 'yaml'
3-
require 'date'
4-
require './data_file_validator'
5-
require './meetup_client'
2+
3+
require "yaml"
4+
require "date"
5+
require "ostruct"
6+
7+
require "./src/data_file_validator"
8+
require "./src/static"
9+
require "./src/meetup_client"
610

711
desc "Build Jekyll site"
812
task :build do
@@ -108,6 +112,10 @@ task :fetch_meetups do
108112
puts "pull_request_title: #{pull_request_title}"
109113
File.write("./pull_request_title.txt", pull_request_title)
110114

115+
Rake::Task["sort_meetups"].invoke
116+
end
117+
118+
task :sort_meetups do
111119
events = YAML.load_file("./_data/meetups.yml", permitted_classes: [Date])
112120

113121
events.sort_by! { |event| [event["date"], event["name"]] }

_data/meetups.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,7 @@
14291429
end_time: 20:00:00 EDT
14301430
url: https://lu.ma/af2n3jwa
14311431

1432-
- name: "Austin.rb - Visualizing Problems: From Abstract to Concrete"
1432+
- name: 'Austin.rb - Visualizing Problems: From Abstract to Concrete'
14331433
location: Austin, TX
14341434
date: 2024-09-10
14351435
start_time: 18:30:00 CDT

meetup_client.rb

-195
This file was deleted.
File renamed without changes.

src/meetup_client.rb

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
require "pathname"
2+
3+
require "graphql/client"
4+
require "graphql/client/http"
5+
6+
module MeetupClient
7+
BASE = "https://api.meetup.com/gql".freeze
8+
HTTP = GraphQL::Client::HTTP.new(BASE) do
9+
def headers(context)
10+
{
11+
Authorization: "Bearer #{ENV["MEETUP_API_TOKEN"]}",
12+
"Content-Type": "application/json",
13+
}
14+
end
15+
end
16+
17+
Schema = GraphQL::Client.load_schema("./src/meetup_graphql_schema.json")
18+
Client = GraphQL::Client.new(schema: Schema, execute: HTTP)
19+
end
File renamed without changes.

src/queries/events_query.rb

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
require_relative "../meetup_client"
2+
3+
EventsQuery = MeetupClient::Client.parse(<<-GRAPHQL
4+
query ($groupId: String!) {
5+
groupByUrlname(urlname: $groupId) {
6+
id
7+
logo {
8+
id
9+
baseUrl
10+
preview
11+
source
12+
}
13+
name
14+
country
15+
state
16+
city
17+
unifiedEvents(sortOrder: ASC) {
18+
count
19+
edges {
20+
cursor
21+
node {
22+
id
23+
title
24+
eventUrl
25+
shortDescription
26+
description
27+
onlineVenue {
28+
type
29+
url
30+
}
31+
venue {
32+
address
33+
city
34+
state
35+
country
36+
}
37+
host {
38+
id
39+
name
40+
email
41+
}
42+
status
43+
dateTime
44+
endTime
45+
duration
46+
timezone
47+
createdAt
48+
eventType
49+
isOnline
50+
group {
51+
id
52+
name
53+
country
54+
state
55+
city
56+
}
57+
}
58+
}
59+
}
60+
}
61+
}
62+
GRAPHQL
63+
)

src/static.rb

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module Static
2+
end
3+
4+
require "frozen_record"
5+
6+
FrozenRecord::Base.auto_reloading = true
7+
FrozenRecord::Base.base_path = "./_data"
8+
9+
require_relative "./static/conference"
10+
require_relative "./static/meetup"
11+
require_relative "./static/meetup_group"

src/static/conference.rb

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
require_relative "../static"
2+
3+
class Conference < FrozenRecord::Base
4+
end

src/static/meetup.rb

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require_relative "../static"
2+
3+
class Meetup < FrozenRecord::Base
4+
def service_id
5+
if url.start_with?("https://www.meetup.com/") || url.start_with?("https://meetup.com/")
6+
url.split("/").last
7+
end
8+
end
9+
end

0 commit comments

Comments
 (0)