Compare commits

...
4 changed files with 11 additions and 4 deletions
@@ -38,7 +38,7 @@ module InstagramConcern
end
def fetch_instagram_user_details(access_token)
endpoint = 'https://graph.instagram.com/v22.0/me'
endpoint = "https://graph.instagram.com/#{GlobalConfigService.load('INSTAGRAM_API_VERSION', 'v22.0')}/me"
params = {
fields: 'id,username,user_id,name,profile_picture_url,account_type',
access_token: access_token
+8 -2
View File
@@ -45,7 +45,7 @@ class Channel::Instagram < ApplicationRecord
def subscribe
# ref https://developers.facebook.com/docs/instagram-platform/webhooks#enable-subscriptions
HTTParty.post(
"https://graph.instagram.com/v22.0/#{instagram_id}/subscribed_apps",
"#{base_uri}/#{instagram_id}/subscribed_apps",
query: {
subscribed_fields: %w[messages message_reactions messaging_seen],
access_token: access_token
@@ -58,7 +58,7 @@ class Channel::Instagram < ApplicationRecord
def unsubscribe
HTTParty.delete(
"https://graph.instagram.com/v22.0/#{instagram_id}/subscribed_apps",
"#{base_uri}/#{instagram_id}/subscribed_apps",
query: {
access_token: access_token
}
@@ -72,4 +72,10 @@ class Channel::Instagram < ApplicationRecord
def access_token
Instagram::RefreshOauthTokenService.new(channel: self).access_token
end
private
def base_uri
"https://graph.instagram.com/#{GlobalConfigService.load('INSTAGRAM_API_VERSION', 'v22.0')}"
end
end
@@ -13,7 +13,7 @@ class Instagram::SendOnInstagramService < Instagram::BaseSendService
instagram_id = channel.instagram_id.presence || 'me'
response = HTTParty.post(
"https://graph.instagram.com/v22.0/#{instagram_id}/messages",
"https://graph.instagram.com/#{GlobalConfigService.load('INSTAGRAM_API_VERSION', 'v22.0')}/#{instagram_id}/messages",
body: message_content,
query: query
)
@@ -12,6 +12,7 @@ RSpec.describe InstagramConcern do
before do
allow(GlobalConfigService).to receive(:load).with('INSTAGRAM_APP_ID', nil).and_return(client_id)
allow(GlobalConfigService).to receive(:load).with('INSTAGRAM_APP_SECRET', nil).and_return(client_secret)
allow(GlobalConfigService).to receive(:load).with('INSTAGRAM_API_VERSION', 'v22.0').and_return('v22.0')
allow(Rails.logger).to receive(:error)
end