-
-
Notifications
You must be signed in to change notification settings - Fork 108
Support Facebook API in Statistics::Aggregation #164
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 all commits
9a845a2
16c8169
f246a2e
78347bf
3344ffe
e0b2147
9589fab
213320c
59022ea
4f1b20d
f82cfa5
4591b46
fdf0956
9d5736f
39b3fd5
de9841c
a7da867
cca2f3a
829a0e6
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
class DojoEventService < ApplicationRecord | ||
belongs_to :dojo | ||
enum name: %i( connpass doorkeeper ) | ||
enum name: %i( connpass doorkeeper facebook ) | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class IntegerToStringOnGroupIdInDojoEventServices < ActiveRecord::Migration[5.0] | ||
def up | ||
change_column :dojo_event_services, :group_id, :string, null: false | ||
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. facebookのgroup idが15桁なのでintegerからstringに変更した。 |
||
end | ||
|
||
def down | ||
change_column :dojo_event_services, :group_id, :integer, null: false | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class IntegerToStringOnServiceGroupIdAndEventIdInEventHistories < ActiveRecord::Migration[5.0] | ||
def up | ||
change_column :event_histories, :service_group_id, :string, null: false | ||
change_column :event_histories, :event_id, :string, null: false | ||
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. ditto |
||
end | ||
|
||
def down | ||
change_column :event_histories, :service_group_id, :integer, null: false | ||
change_column :event_histories, :event_id, :integer, null: false | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,11 @@ class << self | |
def run(date:) | ||
cnps_dojos = Dojo.joins(:dojo_event_service).where(dojo_event_services: { name: :connpass }).to_a | ||
drkp_dojos = Dojo.joins(:dojo_event_service).where(dojo_event_services: { name: :doorkeeper }).to_a | ||
fsbk_dojos = Dojo.joins(:dojo_event_service).where(dojo_event_services: { name: :facebook }).to_a | ||
|
||
Connpass.run(cnps_dojos, date) | ||
Doorkeeper.run(drkp_dojos, date) | ||
Facebook.run(fsbk_dojos, date) | ||
end | ||
end | ||
|
||
|
@@ -20,7 +22,7 @@ def run(dojos, date) | |
|
||
dojos.each do |dojo| | ||
cnps.fetch_events(params.merge(series_id: dojo.dojo_event_service.group_id)).each do |e| | ||
next unless e.dig('series', 'id') == dojo.dojo_event_service.group_id | ||
next unless e.dig('series', 'id').to_s == dojo.dojo_event_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. カラムの型変更に伴い |
||
|
||
EventHistory.create!(dojo_id: dojo.id, | ||
dojo_name: dojo.name, | ||
|
@@ -47,7 +49,7 @@ def run(dojos, date) | |
|
||
dojos.each do |dojo| | ||
drkp.fetch_events(params.merge(group_id: dojo.dojo_event_service.group_id)).each do |e| | ||
next unless e['group'] == dojo.dojo_event_service.group_id | ||
next unless e['group'].to_s == dojo.dojo_event_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. ditto |
||
|
||
EventHistory.create!(dojo_id: dojo.id, | ||
dojo_name: dojo.name, | ||
|
@@ -62,5 +64,32 @@ def run(dojos, date) | |
end | ||
end | ||
end | ||
|
||
class Facebook | ||
class << self | ||
def run(dojos, date) | ||
fsbk = Client::Facebook.new | ||
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. ローカル変数なので雑に省略しています😅 |
||
params = { | ||
since_at: date.beginning_of_month, | ||
until_at: date.end_of_month | ||
} | ||
|
||
dojos.each do |dojo| | ||
fsbk.fetch_events(params.merge(group_id: dojo.dojo_event_service.group_id)).each do |e| | ||
next unless e.dig('owner', 'id') == dojo.dojo_event_service.group_id | ||
|
||
EventHistory.create!(dojo_id: dojo.id, | ||
dojo_name: dojo.name, | ||
service_name: dojo.dojo_event_service.name, | ||
service_group_id: dojo.dojo_event_service.group_id, | ||
event_id: e['id'], | ||
event_url: "https://www.facebook.com/events/#{e['id']}", | ||
participants: e['attending_count'], | ||
evented_at: Time.zone.parse(e['start_time'])) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace :oauth do | ||
desc 'Facebookのaccess tokenを取得します' | ||
task :facebook_access_token, [:app_id, :app_secret] => :environment do |_tasks, args| | ||
puts 'Access Token: ' + Koala::Facebook::OAuth.new(args[:app_id], args[:app_secret]).get_app_access_token | ||
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. Facebookのapp_idとapp_secretでaccess tokenを取得するRake task |
||
end | ||
end |
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.
facebookサポートにより追加