instagram-post 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/instagram/post.rb +36 -0
- data/lib/instagram/post/account.rb +25 -0
- data/lib/instagram/post/auth.rb +27 -0
- data/lib/instagram/post/config.rb +16 -0
- data/lib/instagram/post/ids.rb +31 -0
- data/lib/instagram/post/link.rb +7 -0
- data/lib/instagram/post/publish.rb +23 -0
- data/lib/instagram/post/scope.rb +6 -0
- data/lib/instagram/post/token.rb +32 -0
- data/lib/instagram/post/token_link.rb +7 -0
- data/lib/instagram/post/version.rb +6 -0
- metadata +54 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 9088beadf3f26b36cca4d9c60e2ecd71554482ea4e7b9c66379159a5fcf269a2
|
|
4
|
+
data.tar.gz: 554885d1710a05e79a911d580f4c9a5dfe0bbaf57ba46fab2507a89fb47930c4
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 4478e7093c086a1da6ce5bfa01f483772250c1e53c5f7cc7bf9d4f417932f6aa55e22e3451c4e43d72b24b41ccd440a82fe5cac2e5f3e205b84078167ee09f2c
|
|
7
|
+
data.tar.gz: cb7bc38f5eb26027222e6742d05b12c792cce8244b2b015c77163719a9e9b2309beb17a5362371595e95364ea45f939d9d79416d312ab9c664c20e5f00dfe663
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require "instagram/post/version"
|
|
3
|
+
require "instagram/post/auth"
|
|
4
|
+
require "instagram/post/token"
|
|
5
|
+
require "instagram/post/ids"
|
|
6
|
+
require "instagram/post/publish"
|
|
7
|
+
require "instagram/post/account"
|
|
8
|
+
|
|
9
|
+
class Send
|
|
10
|
+
def initialize(image_url, caption, config, request)
|
|
11
|
+
@image_url = image_url
|
|
12
|
+
@caption = caption
|
|
13
|
+
@config = config
|
|
14
|
+
@request = request
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def generate_token
|
|
18
|
+
Instagram::Post::Token.get_access_token(@config, request)[:token]
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def post
|
|
22
|
+
token = generate_token
|
|
23
|
+
ids = Instagram::Post::Account.new(@config, token).generate_id(@image_url, @caption)
|
|
24
|
+
ids.each do |id|
|
|
25
|
+
HTTParty.post("https://graph.facebook.com/id/media_publish?access_token=#{token}",
|
|
26
|
+
:body => {
|
|
27
|
+
creation_id: id
|
|
28
|
+
}
|
|
29
|
+
)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.post(image_url, caption, config, request)
|
|
34
|
+
new(image_url, caption, config, request).post
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Instagram::Post
|
|
4
|
+
class Account
|
|
5
|
+
def initialize(config, token)
|
|
6
|
+
@config = config
|
|
7
|
+
@token = token
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def generate_id(image_url, caption)
|
|
11
|
+
ids = []
|
|
12
|
+
published_id = Instagram::Post::Publish.new(@config, @token).published_id
|
|
13
|
+
published_id.each do |id|
|
|
14
|
+
post_published_id = HTTParty.post("https://graph.facebook.com/#{id}/media?access_token=#{token}",
|
|
15
|
+
:body => {
|
|
16
|
+
image_url: image_url,
|
|
17
|
+
caption: caption
|
|
18
|
+
}
|
|
19
|
+
)
|
|
20
|
+
ids.push(JSON.parse(post_published_id.body)["id"])
|
|
21
|
+
end
|
|
22
|
+
ids
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'instagram/post/link'
|
|
3
|
+
require 'instagram/post/scope'
|
|
4
|
+
require 'instagram/post/config'
|
|
5
|
+
require 'httparty'
|
|
6
|
+
module Instagram
|
|
7
|
+
module Post
|
|
8
|
+
# GET Auth Link Facebook
|
|
9
|
+
class Auth
|
|
10
|
+
class NotFoundConfigFile < StandardError; end
|
|
11
|
+
class ForceUseRails < StandardError; end
|
|
12
|
+
def call(config)
|
|
13
|
+
begin
|
|
14
|
+
link = "#{Instagram::Post::LINK}client_id=#{config[:client_id]}&redirect_uri=#{config[:redirect_uri]}&scope=#{config[:scope]}"
|
|
15
|
+
rescue
|
|
16
|
+
NotFoundConfigFile.new('Please set config file in initialize path.')
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def self.link(config)
|
|
22
|
+
new.call(config)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Instagram
|
|
4
|
+
module Post
|
|
5
|
+
class Config
|
|
6
|
+
attr_accessor :client_id, :app_secret, :redirect_uri, :scope
|
|
7
|
+
|
|
8
|
+
def self.config
|
|
9
|
+
conf = Config.new
|
|
10
|
+
conf.scope = 'email,public_profile,pages_show_list,instagram_basic,instagram_content_publish,pages_show_list'
|
|
11
|
+
yield conf
|
|
12
|
+
{client_id: conf.client_id, app_secret: conf.app_secret, redirect_uri: conf.redirect_uri, scope: conf.scope}
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# lib/account_details.rb
|
|
2
|
+
require 'instagram/post/token.rb'
|
|
3
|
+
require 'httparty'
|
|
4
|
+
require 'addressable'
|
|
5
|
+
module Instagram
|
|
6
|
+
module Post
|
|
7
|
+
LINKACCOUNTS = 'https://graph.facebook.com/v11.0/me/accounts?'
|
|
8
|
+
class Ids
|
|
9
|
+
def initialize(config, token)
|
|
10
|
+
@config = config
|
|
11
|
+
@token = token
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def accounts
|
|
15
|
+
ids = []
|
|
16
|
+
accounts = HTTParty.get("#{Instagram::Post::LINKACCOUNTS}access_token=#{@token}")
|
|
17
|
+
get_id_ig_instagram = JSON.parse(accounts.body)["data"]
|
|
18
|
+
get_id_ig_instagram.each do |ig|
|
|
19
|
+
ids.push ig["id"]
|
|
20
|
+
end
|
|
21
|
+
ids
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def self.accounts(config, token)
|
|
26
|
+
new(config, token).accounts
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Instagram::Post
|
|
4
|
+
class Publish
|
|
5
|
+
attr_accessor :token
|
|
6
|
+
def initialize(config, token)
|
|
7
|
+
@config = config
|
|
8
|
+
@token = token
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def published_id
|
|
12
|
+
instagram_business_id = []
|
|
13
|
+
ids = Instagram::Post::Ids(@config, @token)
|
|
14
|
+
ids.each do |id|
|
|
15
|
+
account = HTTParty.get("https://graph.facebook.com/v11.0/#{id}?fields=instagram_business_account&access_token=#{@token}")
|
|
16
|
+
if JSON.parse(account.body)["instagram_business_account"]["id"]
|
|
17
|
+
instagram_business_id.push(JSON.parse(account.body)["instagram_business_account"]["id"])
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
instagram_business_id
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'instagram/post/link'
|
|
3
|
+
require 'instagram/post/config'
|
|
4
|
+
require 'httparty'
|
|
5
|
+
require 'addressable'
|
|
6
|
+
require 'redis'
|
|
7
|
+
module Instagram
|
|
8
|
+
module Post
|
|
9
|
+
TOKENLINK = 'https://graph.facebook.com/v11.0/oauth/access_token?'
|
|
10
|
+
# GET User Access Token
|
|
11
|
+
class Token
|
|
12
|
+
def initialize(config, request)
|
|
13
|
+
@config = config
|
|
14
|
+
@request = request
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def get_access_token
|
|
18
|
+
token = HTTParty.get("#{Instagram::Post::TOKENLINK}client_id=#{@config[:client_id]}&redirect_uri=#{@config[:redirect_uri]}&client_secret=#{@config[:app_secret]}&code=#{Addressable::URI.parse(@request.url).query_values['code']}")
|
|
19
|
+
code = JSON.parse(token.body)["access_token"]
|
|
20
|
+
user_id = HTTParty.get("https://graph.facebook.com/me?access_token=#{code}")
|
|
21
|
+
user_id = JSON.parse(user_id.body)
|
|
22
|
+
{token: token, id: user_id}
|
|
23
|
+
#yield user_id if block_given?
|
|
24
|
+
#Redis.new(local: 'localhost').setex(user_id["id"], 100000, token)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def self.get(config, request)
|
|
28
|
+
new(config, request).get_access_token
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: instagram-post
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- PaymaanKazemi
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2021-08-10 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: send post publish photo to page instagram
|
|
14
|
+
email:
|
|
15
|
+
- paymankazemipymkz@gamil.com
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- lib/instagram/post.rb
|
|
21
|
+
- lib/instagram/post/account.rb
|
|
22
|
+
- lib/instagram/post/auth.rb
|
|
23
|
+
- lib/instagram/post/config.rb
|
|
24
|
+
- lib/instagram/post/ids.rb
|
|
25
|
+
- lib/instagram/post/link.rb
|
|
26
|
+
- lib/instagram/post/publish.rb
|
|
27
|
+
- lib/instagram/post/scope.rb
|
|
28
|
+
- lib/instagram/post/token.rb
|
|
29
|
+
- lib/instagram/post/token_link.rb
|
|
30
|
+
- lib/instagram/post/version.rb
|
|
31
|
+
homepage: https://github.com/paymaan73/instagram-post
|
|
32
|
+
licenses:
|
|
33
|
+
- MIT
|
|
34
|
+
metadata: {}
|
|
35
|
+
post_install_message:
|
|
36
|
+
rdoc_options: []
|
|
37
|
+
require_paths:
|
|
38
|
+
- lib
|
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
40
|
+
requirements:
|
|
41
|
+
- - ">="
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: 2.3.0
|
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
|
+
requirements:
|
|
46
|
+
- - ">="
|
|
47
|
+
- !ruby/object:Gem::Version
|
|
48
|
+
version: '0'
|
|
49
|
+
requirements: []
|
|
50
|
+
rubygems_version: 3.1.4
|
|
51
|
+
signing_key:
|
|
52
|
+
specification_version: 4
|
|
53
|
+
summary: instagram-post
|
|
54
|
+
test_files: []
|