-
-
Notifications
You must be signed in to change notification settings - Fork 108
Create recent events table #277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 20 commits
c02f95c
2a0529a
1a03b3c
cb0a915
4b8f227
ec1f07b
1e412e4
4721898
6219af4
f341803
f609b2d
b30cdbd
fd426de
d044d00
a20eac9
0fd4ef8
4fc5347
5e052ab
1482972
2fe30dc
c03a16b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class CreateRecentlyEvents < ActiveRecord::Migration[5.1] | ||
def change | ||
create_table :recently_events do |t| | ||
t.integer :dojo_id, null: false | ||
t.string :dojo_name, null: false | ||
t.string :service_name, null: false | ||
t.string :service_group_id | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dojo_event_service.idをdojo_event_service_idとして持てば There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. コメントありがとうございます! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
はい、その通りです。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (あ、 #278 があったんですね。コメントする場所間違えちゃいましたかね😅) |
||
t.string :event_id, null: false | ||
t.string :event_url, null: false | ||
t.datetime :event_at, null: false | ||
|
||
t.index ["dojo_id"], name: "index_recently_events_on_dojo_id" | ||
t.index ["event_at"], name: "index_recently_events_on_event_at" | ||
t.index ["event_at", "dojo_id"], name: "index_recently_events_on_event_at_and_dojo_id" | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module EventService; end | ||
|
||
require_relative 'eventservice/providers' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module Statistics | ||
module EventService | ||
module Providers | ||
end | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
module EventService | ||
module Providers | ||
class Connpass | ||
ENDPOINT = 'https://connpass.com/api/v1'.freeze | ||
|
||
def initialize | ||
@client = Statistics::Client.new(ENDPOINT) | ||
end | ||
|
||
def search(keyword:) | ||
@client.get('event/', { keyword: keyword, count: 100 }) | ||
end | ||
|
||
def fetch_events(series_id:, yyyymm: nil, yyyymmdd: nil) | ||
params = { | ||
series_id: series_id, | ||
start: 1, | ||
count: 100 | ||
} | ||
params[:ym] = yyyymm if yyyymm | ||
params[:ymd] = yyyymmdd if yyyymmdd | ||
events = [] | ||
|
||
loop do | ||
part = @client.get('event/', params) | ||
|
||
break if part['results_returned'].zero? | ||
|
||
events.push(*part.fetch('events')) | ||
|
||
break if part.size < params[:count] | ||
|
||
break if params[:start] + params[:count] > part['results_available'] | ||
|
||
params[:start] += params[:count] | ||
end | ||
|
||
events | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
module EventService | ||
module Providers | ||
class Doorkeeper | ||
ENDPOINT = 'https://api.doorkeeper.jp'.freeze | ||
|
||
def initialize | ||
@client = Statistics::Client.new(ENDPOINT) do |c| | ||
c.authorization(:Bearer, ENV.fetch('DOORKEEPER_API_TOKEN')) | ||
end | ||
@default_since = Time.zone.parse('2010-07-01') | ||
@default_until = Time.zone.now.end_of_day | ||
end | ||
|
||
def search(keyword:) | ||
@client.get('events', q: keyword, since: @default_since, expand: 'group') | ||
end | ||
|
||
def fetch_events(group_id:, since_at: @default_since, until_at: @default_until) | ||
begin | ||
params = { | ||
page: 1, | ||
since: since_at, | ||
until: until_at | ||
} | ||
events = [] | ||
|
||
loop do | ||
part = @client.get("groups/#{group_id}/events", params) | ||
|
||
break if part.size.zero? | ||
|
||
events.push(*part.map { |e| e['event'] }) | ||
|
||
break if part.size < 25 # 25 items / 1 request | ||
|
||
params[:page] += 1 | ||
end | ||
|
||
events | ||
rescue Faraday::ClientError => e | ||
raise e unless e.response[:status] == 429 | ||
|
||
puts 'API rate limit exceeded.' | ||
puts "This task will retry in 60 seconds from now(#{Time.zone.now})." | ||
sleep 60 | ||
retry | ||
end | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
module EventService | ||
module Providers | ||
class Facebook | ||
class_attribute :access_token | ||
|
||
def initialize | ||
@client = Koala::Facebook::API.new(self.access_token) | ||
end | ||
|
||
def fetch_events(group_id:, since_at: nil, until_at: nil) | ||
params = { | ||
fields: %i(attending_count start_time owner), | ||
limit: 100 | ||
}.tap do |h| | ||
# @note FacebookのGraph APIはPDTがタイムゾーンとなっており、 | ||
# JST<->PDTのオフセット8時間を追加した時刻をパラメータとする必要がある | ||
# @see https://github.com/coderdojo-japan/coderdojo.jp/pull/182#discussion_r148935458 | ||
h[:since] = since_at.since(8.hours).to_i if since_at | ||
h[:until] = until_at.since(8.hours).to_i if until_at | ||
end | ||
|
||
events = [] | ||
|
||
collection = @client.get_object("#{group_id}/events", params) | ||
events.push(*collection.to_a) | ||
while !collection.empty? && collection.paging['next'] do | ||
events.push(*collection.next_page.to_a) | ||
end | ||
|
||
events | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module EventService | ||
module Providers | ||
class StaticYaml | ||
YAML_FILE = Rails.root.join('db', 'static_event_histories.yaml') | ||
|
||
def fetch_events | ||
YAML.load_file(YAML_FILE) || [] | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module Statistics; end | ||
|
||
require_relative 'statistics/client' | ||
require_relative 'statistics/providers' | ||
require_relative 'statistics/tasks' | ||
require_relative 'statistics/aggregation' | ||
require_relative 'eventservice' |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
recentlyって「過去」なイメージなのですがどうでしょうか?
「(近い)未来」を意味する単語の方が良かったりしますかね?
/cc @yasulab
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
recently
だと確かに過去だったのでfuature
でやってみようかなと思います