-
-
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
Closed
AnaTofuZ
wants to merge
21
commits into
coderdojo-japan:master
from
AnaTofuZ:create_recent_events_table
Closed
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
c02f95c
touch events.html.haml and add static_pages_controller_spec test
AnaTofuZ 2a0529a
modofied namespace statiscs/providers/ to providers/
AnaTofuZ 1a03b3c
remove module Statistics namespace for lib/providers/*.rb
AnaTofuZ cb0a915
Merge branch 'add_events_pages' of ssh://github.com/AnaTofuZ/coderdoj…
AnaTofuZ 4b8f227
lib/statistics.rbでの `providers` の名前空間からstatisticsを外した
AnaTofuZ ec1f07b
名前空間の変更に伴うlib/tasks/statistics.rakeでのStatistics::Providersの名前修正
AnaTofuZ 1e412e4
git mv spec/lib/statistics/providers -> spec/lib/providers/*
AnaTofuZ 4721898
spec/lib/providers* でのテスト対象の名前空間の修正
AnaTofuZ 6219af4
rm `/events` components
AnaTofuZ f341803
remove spec/controller/static_pages_controller_spec for /evens
AnaTofuZ f609b2d
git mv providers/* -> eventservice/providers/*
AnaTofuZ b30cdbd
move providers.rb to eventservice/providers.rb and new eventservice.r…
AnaTofuZ fd426de
add eventservice name space for lib/**/*.rb
AnaTofuZ d044d00
modified lib/eventservice/providers/*.rb indents
AnaTofuZ a20eac9
git mv spec/lib/providers -> spec/lib/eventservice/providers
AnaTofuZ 0fd4ef8
modofied spec/lib/eventservice/providers use Providers -> EventServic…
AnaTofuZ 4fc5347
modofied lib/task/statistics use Providers -> EventService::Providers
AnaTofuZ 5e052ab
use Everything namespace for lib/statistics/tasks/*.rb
AnaTofuZ 1482972
generate migration create_recent_events_table
AnaTofuZ 2fe30dc
create recently_events table and migrateion
AnaTofuZ c03a16b
remove dojo_id for recently_events schema
AnaTofuZ File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class CreateRecentlyEvents < ActiveRecord::Migration[5.1] | ||
def change | ||
create_table :recently_events do |t| | ||
t.integer :dojo_event_service_id, null: false | ||
t.string :event_id, null: false | ||
t.string :event_url, null: false | ||
t.datetime :event_at, null: false | ||
|
||
t.index ["dojo_event_service_id"], name: "index_recently_events_on_dojo_event_service_id" | ||
t.index ["event_at"], name: "index_recently_events_on_event_at" | ||
end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module EventService; end | ||
|
||
require_relative 'eventservice/providers' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module Statistics | ||
module EventService | ||
module Providers | ||
end | ||
end | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
でやってみようかなと思います