instagramp 0.1.4
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/instagramp.rb +35 -0
 - data/lib/instagramp/account.rb +25 -0
 - data/lib/instagramp/auth.rb +24 -0
 - data/lib/instagramp/config.rb +14 -0
 - data/lib/instagramp/ids.rb +28 -0
 - data/lib/instagramp/link.rb +5 -0
 - data/lib/instagramp/publish.rb +23 -0
 - data/lib/instagramp/scope.rb +4 -0
 - data/lib/instagramp/token.rb +30 -0
 - data/lib/instagramp/token_link.rb +5 -0
 - metadata +53 -0
 
    
        checksums.yaml
    ADDED
    
    | 
         @@ -0,0 +1,7 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ---
         
     | 
| 
      
 2 
     | 
    
         
            +
            SHA256:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 2be736b91efd8843c6c85a778e9ef62c1d59efc6e5e27be5f7446fd87c784c55
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: ff7f1cb82fc23cc9c4d325d4f88087c05c226f35ed8be18d5c21dfbd1f65c877
         
     | 
| 
      
 5 
     | 
    
         
            +
            SHA512:
         
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: f9c203a92670909ce712ab41b377addd82c6323a294d00f9cf1b79a227982cc232c1ab0d18b8dd79c849ee1ad48611af4b70f4690a9ab16d977d6a13a1294a9f
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 3c3c652ac8ce2fbcad13281c54724eddb0ff178eb7b70f79113c29a2e132abd8d0b3490fedde5ffe9053ce337dfbf344a6061b4249211bc3a91796110ec20828
         
     | 
    
        data/lib/instagramp.rb
    ADDED
    
    | 
         @@ -0,0 +1,35 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
            require "instagramp/auth"
         
     | 
| 
      
 3 
     | 
    
         
            +
            require "instagramp/token"
         
     | 
| 
      
 4 
     | 
    
         
            +
            require "instagramp/ids"
         
     | 
| 
      
 5 
     | 
    
         
            +
            require "instagramp/publish"
         
     | 
| 
      
 6 
     | 
    
         
            +
            require "instagramp/account"
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            class Send
         
     | 
| 
      
 9 
     | 
    
         
            +
              def initialize(image_url, caption, config, request)
         
     | 
| 
      
 10 
     | 
    
         
            +
                @image_url = image_url
         
     | 
| 
      
 11 
     | 
    
         
            +
                @caption  = caption
         
     | 
| 
      
 12 
     | 
    
         
            +
                @config = config
         
     | 
| 
      
 13 
     | 
    
         
            +
                @request = request
         
     | 
| 
      
 14 
     | 
    
         
            +
              end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
              def generate_token
         
     | 
| 
      
 17 
     | 
    
         
            +
                Instagram::Post::Token.get_access_token(@config, request)[:token]
         
     | 
| 
      
 18 
     | 
    
         
            +
              end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
              def post
         
     | 
| 
      
 21 
     | 
    
         
            +
                token = generate_token
         
     | 
| 
      
 22 
     | 
    
         
            +
                ids = Instagram::Post::Account.new(@config, token).generate_id(@image_url, @caption)
         
     | 
| 
      
 23 
     | 
    
         
            +
                ids.each do |id|
         
     | 
| 
      
 24 
     | 
    
         
            +
                  HTTParty.post("https://graph.facebook.com/id/media_publish?access_token=#{token}",
         
     | 
| 
      
 25 
     | 
    
         
            +
                                :body => {
         
     | 
| 
      
 26 
     | 
    
         
            +
                                  creation_id: id
         
     | 
| 
      
 27 
     | 
    
         
            +
                                }
         
     | 
| 
      
 28 
     | 
    
         
            +
                               )
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
      
 30 
     | 
    
         
            +
              end
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
              def self.post(image_url, caption, config, request)
         
     | 
| 
      
 33 
     | 
    
         
            +
                new(image_url, caption, config, request).post
         
     | 
| 
      
 34 
     | 
    
         
            +
              end
         
     | 
| 
      
 35 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,25 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module Instagramp
         
     | 
| 
      
 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,24 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'instagramp/link'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'instagramp/scope'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'instagramp/config'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'httparty'
         
     | 
| 
      
 6 
     | 
    
         
            +
            module Instagramp
         
     | 
| 
      
 7 
     | 
    
         
            +
              # GET Auth Link Facebook
         
     | 
| 
      
 8 
     | 
    
         
            +
                class Auth
         
     | 
| 
      
 9 
     | 
    
         
            +
                  class NotFoundConfigFile < StandardError; end
         
     | 
| 
      
 10 
     | 
    
         
            +
                  class ForceUseRails < StandardError; end
         
     | 
| 
      
 11 
     | 
    
         
            +
                def call(config)
         
     | 
| 
      
 12 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 13 
     | 
    
         
            +
                    link          = "#{Instagram::Post::LINK}client_id=#{config[:client_id]}&redirect_uri=#{config[:redirect_uri]}&scope=#{config[:scope]}"
         
     | 
| 
      
 14 
     | 
    
         
            +
                  rescue
         
     | 
| 
      
 15 
     | 
    
         
            +
                    NotFoundConfigFile.new('Please set config file in initialize path.')
         
     | 
| 
      
 16 
     | 
    
         
            +
                  end
         
     | 
| 
      
 17 
     | 
    
         
            +
                end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                def self.link(config)
         
     | 
| 
      
 21 
     | 
    
         
            +
                  new.call(config)
         
     | 
| 
      
 22 
     | 
    
         
            +
                end
         
     | 
| 
      
 23 
     | 
    
         
            +
              end
         
     | 
| 
      
 24 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,14 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module Instagramp
         
     | 
| 
      
 4 
     | 
    
         
            +
                class Config
         
     | 
| 
      
 5 
     | 
    
         
            +
                  attr_accessor :client_id, :app_secret, :redirect_uri, :scope
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                  def self.config
         
     | 
| 
      
 8 
     | 
    
         
            +
                    conf    = Config.new
         
     | 
| 
      
 9 
     | 
    
         
            +
                    conf.scope = 'email,public_profile,pages_show_list,instagram_basic,instagram_content_publish,pages_show_list'
         
     | 
| 
      
 10 
     | 
    
         
            +
                    yield conf
         
     | 
| 
      
 11 
     | 
    
         
            +
                    {client_id: conf.client_id, app_secret: conf.app_secret, redirect_uri: conf.redirect_uri, scope: conf.scope}
         
     | 
| 
      
 12 
     | 
    
         
            +
                  end
         
     | 
| 
      
 13 
     | 
    
         
            +
                end
         
     | 
| 
      
 14 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,28 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # lib/account_details.rb
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'instagramp/token.rb'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'httparty'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'addressable'
         
     | 
| 
      
 5 
     | 
    
         
            +
            module Instagramp
         
     | 
| 
      
 6 
     | 
    
         
            +
                LINKACCOUNTS = 'https://graph.facebook.com/v11.0/me/accounts?'
         
     | 
| 
      
 7 
     | 
    
         
            +
                class Ids
         
     | 
| 
      
 8 
     | 
    
         
            +
                  def initialize(config, token)
         
     | 
| 
      
 9 
     | 
    
         
            +
                    @config                  = config
         
     | 
| 
      
 10 
     | 
    
         
            +
                    @token                   = token
         
     | 
| 
      
 11 
     | 
    
         
            +
                  end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                  def accounts
         
     | 
| 
      
 14 
     | 
    
         
            +
                    ids = []
         
     | 
| 
      
 15 
     | 
    
         
            +
                    accounts               = HTTParty.get("#{Instagram::Post::LINKACCOUNTS}access_token=#{@token}")
         
     | 
| 
      
 16 
     | 
    
         
            +
                     get_id_ig_instagram   = JSON.parse(accounts.body)["data"]
         
     | 
| 
      
 17 
     | 
    
         
            +
                     get_id_ig_instagram.each do |ig|
         
     | 
| 
      
 18 
     | 
    
         
            +
                       ids.push ig["id"]
         
     | 
| 
      
 19 
     | 
    
         
            +
                     end
         
     | 
| 
      
 20 
     | 
    
         
            +
                     ids
         
     | 
| 
      
 21 
     | 
    
         
            +
                  end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                  def self.accounts(config, token)
         
     | 
| 
      
 25 
     | 
    
         
            +
                    new(config, token).accounts
         
     | 
| 
      
 26 
     | 
    
         
            +
                  end
         
     | 
| 
      
 27 
     | 
    
         
            +
              end
         
     | 
| 
      
 28 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,23 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module Instagramp
         
     | 
| 
      
 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,30 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'instagramp/link'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'instagramp/config'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'httparty'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'addressable'
         
     | 
| 
      
 6 
     | 
    
         
            +
            require 'redis'
         
     | 
| 
      
 7 
     | 
    
         
            +
            module Instagramp
         
     | 
| 
      
 8 
     | 
    
         
            +
                TOKENLINK    = 'https://graph.facebook.com/v11.0/oauth/access_token?'
         
     | 
| 
      
 9 
     | 
    
         
            +
              # GET User Access Token
         
     | 
| 
      
 10 
     | 
    
         
            +
                class Token
         
     | 
| 
      
 11 
     | 
    
         
            +
                  def initialize(config, request)
         
     | 
| 
      
 12 
     | 
    
         
            +
                    @config  = config
         
     | 
| 
      
 13 
     | 
    
         
            +
                    @request    = request
         
     | 
| 
      
 14 
     | 
    
         
            +
                  end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                  def get_access_token
         
     | 
| 
      
 17 
     | 
    
         
            +
                    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']}")
         
     | 
| 
      
 18 
     | 
    
         
            +
                    code = JSON.parse(token.body)["access_token"]
         
     | 
| 
      
 19 
     | 
    
         
            +
                    user_id = HTTParty.get("https://graph.facebook.com/me?access_token=#{code}")
         
     | 
| 
      
 20 
     | 
    
         
            +
                    user_id = JSON.parse(user_id.body)
         
     | 
| 
      
 21 
     | 
    
         
            +
                    {token: token, id: user_id}
         
     | 
| 
      
 22 
     | 
    
         
            +
                    #yield user_id if block_given?
         
     | 
| 
      
 23 
     | 
    
         
            +
                    #Redis.new(local: 'localhost').setex(user_id["id"], 100000, token)
         
     | 
| 
      
 24 
     | 
    
         
            +
                  end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                  def self.get(config, request)
         
     | 
| 
      
 27 
     | 
    
         
            +
                    new(config, request).get_access_token
         
     | 
| 
      
 28 
     | 
    
         
            +
                  end
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
      
 30 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,53 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: instagramp
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.4
         
     | 
| 
      
 5 
     | 
    
         
            +
            platform: ruby
         
     | 
| 
      
 6 
     | 
    
         
            +
            authors:
         
     | 
| 
      
 7 
     | 
    
         
            +
            - paymaan.kazemi
         
     | 
| 
      
 8 
     | 
    
         
            +
            autorequire: 
         
     | 
| 
      
 9 
     | 
    
         
            +
            bindir: bin
         
     | 
| 
      
 10 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2021-08-10 00:00:00.000000000 Z
         
     | 
| 
      
 12 
     | 
    
         
            +
            dependencies: []
         
     | 
| 
      
 13 
     | 
    
         
            +
            description: This gem for post move instagram.
         
     | 
| 
      
 14 
     | 
    
         
            +
            email:
         
     | 
| 
      
 15 
     | 
    
         
            +
            - payman_kazemi@yahoo.com
         
     | 
| 
      
 16 
     | 
    
         
            +
            executables: []
         
     | 
| 
      
 17 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 18 
     | 
    
         
            +
            extra_rdoc_files: []
         
     | 
| 
      
 19 
     | 
    
         
            +
            files:
         
     | 
| 
      
 20 
     | 
    
         
            +
            - lib/instagramp.rb
         
     | 
| 
      
 21 
     | 
    
         
            +
            - lib/instagramp/account.rb
         
     | 
| 
      
 22 
     | 
    
         
            +
            - lib/instagramp/auth.rb
         
     | 
| 
      
 23 
     | 
    
         
            +
            - lib/instagramp/config.rb
         
     | 
| 
      
 24 
     | 
    
         
            +
            - lib/instagramp/ids.rb
         
     | 
| 
      
 25 
     | 
    
         
            +
            - lib/instagramp/link.rb
         
     | 
| 
      
 26 
     | 
    
         
            +
            - lib/instagramp/publish.rb
         
     | 
| 
      
 27 
     | 
    
         
            +
            - lib/instagramp/scope.rb
         
     | 
| 
      
 28 
     | 
    
         
            +
            - lib/instagramp/token.rb
         
     | 
| 
      
 29 
     | 
    
         
            +
            - lib/instagramp/token_link.rb
         
     | 
| 
      
 30 
     | 
    
         
            +
            homepage: https://www.rubygems.com
         
     | 
| 
      
 31 
     | 
    
         
            +
            licenses:
         
     | 
| 
      
 32 
     | 
    
         
            +
            - MIT
         
     | 
| 
      
 33 
     | 
    
         
            +
            metadata: {}
         
     | 
| 
      
 34 
     | 
    
         
            +
            post_install_message: 
         
     | 
| 
      
 35 
     | 
    
         
            +
            rdoc_options: []
         
     | 
| 
      
 36 
     | 
    
         
            +
            require_paths:
         
     | 
| 
      
 37 
     | 
    
         
            +
            - lib
         
     | 
| 
      
 38 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 39 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 40 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 41 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 42 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 43 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 44 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 45 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 46 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 47 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 48 
     | 
    
         
            +
            requirements: []
         
     | 
| 
      
 49 
     | 
    
         
            +
            rubygems_version: 3.1.4
         
     | 
| 
      
 50 
     | 
    
         
            +
            signing_key: 
         
     | 
| 
      
 51 
     | 
    
         
            +
            specification_version: 4
         
     | 
| 
      
 52 
     | 
    
         
            +
            summary: instagramp
         
     | 
| 
      
 53 
     | 
    
         
            +
            test_files: []
         
     |