opossum 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 072b3d832b3017a8625ed6bd5c16740566eaf4bac7b79347c55834d99b085d90
4
+ data.tar.gz: 14faf920b01e184b49e434e7ea21e76f2eec76969cf44b6b44d25c37fe83010c
5
+ SHA512:
6
+ metadata.gz: 91125cac82c4d80569be8eb23ec46ebf66daf68b0abc3dfbfb4178ba4730c6889968cc5022578eb14267e58d66c27d50713b948258fea1139fe4065efc28f67e
7
+ data.tar.gz: 98c0a00e4909966db372da82f7177dc8fdb0d139bbe924f4d5366e5623b7bf98f2540bf76f83d8b5fcd299c6e90942def270d22b991f8e543752d2b1c49fa7e9
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.0
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
6
+
7
+ Style/StringLiteralsInInterpolation:
8
+ EnforcedStyle: double_quotes
data/CHANGELOG.md ADDED
@@ -0,0 +1,66 @@
1
+ ## [Unreleased]
2
+
3
+ ### Improved
4
+ - **Code Quality** - Minor code style improvements for better readability
5
+
6
+ ## [0.1.0] - 2025-07-31
7
+
8
+ ### Added
9
+
10
+ #### Core Architecture
11
+ - **Authenticator class** - OAuth authentication with Instagram Basic Display API
12
+ - Exchange authorization code for access token
13
+ - Support for client credentials and redirect URI configuration
14
+
15
+ - **Publisher class** - Complete media publishing functionality
16
+ - Single image publishing with optional captions
17
+ - Single video publishing (MP4, MOV) with optional captions
18
+ - Carousel publishing (multiple images) with optional captions
19
+ - Support for Instagram Reels and Stories
20
+ - Automatic media container creation and status monitoring
21
+ - Built-in waiting mechanism for media processing completion
22
+
23
+ - **UserDetails class** - User information and token management
24
+ - Retrieve user profile information with customizable fields
25
+ - Get long-lived access tokens (60-day validity)
26
+ - Refresh existing access tokens (extend for another 60 days)
27
+
28
+ - **BaseClient superclass** - Shared functionality for token-based classes
29
+ - Common constants (INSTAGRAM_GRAPH_API_ENDPOINT, GRAPH_API_VERSION)
30
+ - Standardized initialization with access_token parameter
31
+ - Inheritance support for consistent API design
32
+
33
+ - **ApiHelper module** - Centralized HTTP request handling
34
+ - Faraday wrapper with automatic error handling
35
+ - JSON and form-encoded request support
36
+ - Unified Instagram API error parsing and exception raising
37
+ - Configurable headers and parameters
38
+
39
+ #### Features
40
+ - **Caption Support** - Add text descriptions, hashtags, emojis, and mentions to all post types
41
+ - **Token Lifecycle Management** - Complete OAuth flow from short-lived to long-lived tokens
42
+ - **Error Handling** - Comprehensive error handling for HTTP, JSON, and Instagram API errors
43
+ - **Clean Architecture** - SOLID principles with separation of concerns
44
+ - **Modular Design** - Independent classes that can be used separately or together
45
+
46
+ #### Media Type Support
47
+ - **IMAGE** - JPEG, PNG images with captions
48
+ - **VIDEO** - MP4, MOV videos with captions
49
+ - **REELS** - Instagram Reels with captions
50
+ - **STORIES** - Instagram Stories with captions
51
+ - **CAROUSEL** - Multiple images in single post with captions
52
+
53
+ #### Developer Experience
54
+ - **Comprehensive Documentation** - Detailed README with usage examples
55
+ - **Ruby 3.0+ Support** - Modern Ruby version compatibility
56
+ - **MIT License** - Open source friendly licensing
57
+ - **RubyGems Ready** - Proper gemspec configuration for easy installation
58
+
59
+ ### Technical Details
60
+ - **Dependencies**: faraday (~> 2.0), json (~> 2.0)
61
+ - **Development Dependencies**: rake, rspec, rubocop
62
+ - **Minimum Ruby Version**: 3.0.0
63
+ - **Instagram Graph API Version**: v23.0
64
+
65
+ ### Limitations
66
+ - Carousel posts currently support images only (mixed media support planned for future versions)
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Vadym Kruchyna
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,165 @@
1
+ # OpossumInstagramPublisher
2
+
3
+ A Ruby gem for publishing media to Instagram using Instagram Basic Display API and Instagram Graph API. This gem provides a simple interface to authenticate users via Instagram Login and publish images, videos, and carousel posts to their Instagram accounts.
4
+
5
+ ## Prerequisites
6
+
7
+ Before using this gem, you need to:
8
+
9
+ 1. Create a Facebook App and configure Instagram Basic Display API
10
+ 2. Set up Instagram Basic Display API permissions
11
+ 3. Configure OAuth redirect URIs in your Facebook App settings
12
+ 4. Obtain your Instagram Business Account ID
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'instagram_publish_api_via_instagram_login'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ ```bash
25
+ bundle install
26
+ ```
27
+
28
+ Or install it yourself as:
29
+
30
+ ```bash
31
+ gem install instagram_publish_api_via_instagram_login
32
+ ```
33
+
34
+ ## Usage
35
+
36
+ This gem provides three independent classes for working with Instagram API:
37
+
38
+ ### Authentication
39
+
40
+ ```ruby
41
+ require 'instagram_publish_api_via_instagram_login'
42
+
43
+ # Create authenticator
44
+ authenticator = Opossum::Authenticator.new(
45
+ client_id: 'your_instagram_app_id',
46
+ client_secret: 'your_instagram_app_secret',
47
+ redirect_uri: 'your_redirect_uri'
48
+ )
49
+
50
+ # Exchange code for token
51
+ response = authenticator.exchange_code_for_token(authorization_code)
52
+ access_token = response['access_token']
53
+ ```
54
+
55
+ ### User Information
56
+
57
+ ```ruby
58
+ # Create user details instance
59
+ user_details = Opossum::UserDetails.new(
60
+ access_token: access_token
61
+ )
62
+
63
+ # Get user info
64
+ user_info = user_details.get_user_info(
65
+ fields: 'id,username,account_type'
66
+ )
67
+
68
+ # Get long-lived access token (60 days)
69
+ long_lived_token = user_details.get_long_lived_access_token(
70
+ client_secret: 'your_app_secret'
71
+ )
72
+
73
+ # Refresh access token (extends for another 60 days)
74
+ refreshed_token = user_details.refresh_access_token
75
+ ```
76
+
77
+ ### Publishing
78
+
79
+ ```ruby
80
+ # Create publisher with access token
81
+ publisher = Opossum::Publisher.new(
82
+ access_token: access_token
83
+ )
84
+
85
+ # Publish single image
86
+ result = publisher.publish_media(
87
+ ig_id: instagram_business_account_id,
88
+ media_url: 'https://example.com/image.jpg',
89
+ media_type: 'IMAGE'
90
+ )
91
+
92
+ # Publish image with caption
93
+ result = publisher.publish_media(
94
+ ig_id: instagram_business_account_id,
95
+ media_url: 'https://example.com/image.jpg',
96
+ media_type: 'IMAGE',
97
+ caption: 'Beautiful sunset! 🌅 #nature #photography'
98
+ )
99
+
100
+ # Publish carousel with caption
101
+ result = publisher.publish_media(
102
+ ig_id: instagram_business_account_id,
103
+ media_url: [
104
+ 'https://example.com/image1.jpg',
105
+ 'https://example.com/image2.jpg'
106
+ ],
107
+ media_type: 'CAROUSEL',
108
+ caption: 'Photo collection from my trip ✈️ #travel #memories'
109
+ )
110
+
111
+ # That's it! publish_media handles everything automatically:
112
+ # - Creates media container(s)
113
+ # - Waits for processing to complete
114
+ # - Publishes the media
115
+ ```
116
+
117
+
118
+
119
+ ## Error Handling
120
+
121
+ The gem includes comprehensive error handling for API responses:
122
+
123
+ ```ruby
124
+ begin
125
+ result = client.publish_media(
126
+ ig_id: instagram_business_account_id,
127
+ access_token: access_token,
128
+ media_url: 'https://example.com/image.jpg'
129
+ )
130
+ rescue Opossum::Error => e
131
+ puts "Error: #{e.message}"
132
+ end
133
+ ```
134
+
135
+ ## Supported Media Types
136
+
137
+ - **IMAGE** - Single images (JPEG, PNG) with optional caption
138
+ - **VIDEO** - Single videos (MP4, MOV) with optional caption
139
+ - **REELS** - Instagram Reels with optional caption
140
+ - **STORIES** - Instagram Stories with optional caption
141
+ - **CAROUSEL** - Multiple images in a single post with optional caption (automatically handled when passing an array of URLs)
142
+
143
+ **Features:**
144
+ - **Captions** - Add text descriptions, hashtags, and mentions to your posts
145
+ - **Token Management** - Get long-lived tokens and refresh existing tokens
146
+
147
+ **Note:** Currently, carousel posts support only images. Support for mixed media types (images + videos) in carousels will be added in future versions.
148
+
149
+ ## Development
150
+
151
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
152
+
153
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
154
+
155
+ ## Contributing
156
+
157
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ninjarender/instagram_publish_api_via_instagram_login. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/instagram_publish_api_via_instagram_login/blob/main/CODE_OF_CONDUCT.md).
158
+
159
+ ## License
160
+
161
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
162
+
163
+ ## Code of Conduct
164
+
165
+ Everyone interacting in the OpossumInstagramPublisher project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ninjarender/instagram_publish_api_via_instagram_login/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+ require "json"
5
+
6
+ module Opossum
7
+ # Helper for handling API requests and responses
8
+ class ApiHelper
9
+ def self.get(path:, params: {}, headers: {})
10
+ response = Faraday.get(path) do |req|
11
+ req.headers.merge!(default_headers.merge(headers))
12
+ req.params = params
13
+ end
14
+
15
+ handle_response(response)
16
+ end
17
+
18
+ def self.post(path:, body: {}, headers: {})
19
+ response = Faraday.post(path) do |req|
20
+ req.headers.merge!(default_headers.merge(headers))
21
+ req.body = if headers["Content-Type"] == "application/x-www-form-urlencoded"
22
+ URI.encode_www_form(body)
23
+ else
24
+ body.to_json
25
+ end
26
+ end
27
+
28
+ handle_response(response)
29
+ end
30
+
31
+ class << self
32
+ private
33
+
34
+ def default_headers
35
+ { "Content-Type" => "application/json" }
36
+ end
37
+
38
+ def handle_response(response)
39
+ raise Opossum::Error, "HTTP #{response.status}: #{response.body}" unless response.success?
40
+
41
+ parsed_response = parse_json(response.body)
42
+ check_api_errors(parsed_response)
43
+ parsed_response
44
+ rescue Faraday::Error => e
45
+ raise Opossum::Error, "HTTP Error: #{e.message}"
46
+ end
47
+
48
+ def parse_json(body)
49
+ JSON.parse(body)
50
+ rescue JSON::ParserError => e
51
+ raise Opossum::Error, "JSON Parse Error: #{e.message}"
52
+ end
53
+
54
+ def check_api_errors(parsed_response)
55
+ return unless parsed_response["error"]
56
+
57
+ error_message = "Instagram API Error: #{parsed_response["error"]}"
58
+ error_message += " - #{parsed_response["error_description"]}" if parsed_response["error_description"]
59
+ raise Opossum::Error, error_message
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "api_helper"
4
+
5
+ module Opossum
6
+ # Handles Instagram authentication flow
7
+ class Authenticator
8
+ INSTAGRAM_TOKEN_ENDPOINT = "https://api.instagram.com"
9
+
10
+ def initialize(client_id:, client_secret:, redirect_uri:)
11
+ @client_id = client_id
12
+ @client_secret = client_secret
13
+ @redirect_uri = redirect_uri
14
+ end
15
+
16
+ def exchange_code_for_token(code)
17
+ path = "#{INSTAGRAM_TOKEN_ENDPOINT}/oauth/access_token"
18
+
19
+ ApiHelper.post(
20
+ path: path,
21
+ body: token_request_params(code),
22
+ headers: { "Content-Type" => "application/x-www-form-urlencoded" }
23
+ )
24
+ end
25
+
26
+ private
27
+
28
+ attr_reader :client_id, :client_secret, :redirect_uri
29
+
30
+ def token_request_params(code)
31
+ {
32
+ client_id: @client_id,
33
+ client_secret: @client_secret,
34
+ grant_type: "authorization_code",
35
+ redirect_uri: @redirect_uri,
36
+ code: code
37
+ }
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Opossum
4
+ # Base class for Instagram API clients that require access token
5
+ class BaseClient
6
+ INSTAGRAM_GRAPH_API_ENDPOINT = "https://graph.instagram.com"
7
+ GRAPH_API_VERSION = "v23.0"
8
+
9
+ def initialize(access_token:)
10
+ @access_token = access_token
11
+ end
12
+
13
+ private
14
+
15
+ attr_reader :access_token
16
+ end
17
+ end
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "api_helper"
4
+ require_relative "base_client"
5
+
6
+ module Opossum
7
+ # Handles Instagram media publishing
8
+ class Publisher < BaseClient
9
+ def publish_media(ig_id:, media_url:, media_type: "IMAGE", caption: nil)
10
+ path = "#{INSTAGRAM_GRAPH_API_ENDPOINT}/#{GRAPH_API_VERSION}/#{ig_id}/media_publish"
11
+ media_container_id = prepare_media_container(ig_id: ig_id, media_url: media_url,
12
+ media_type: media_type, caption: caption)
13
+
14
+ ApiHelper.post(
15
+ path: path,
16
+ body: { access_token: access_token, creation_id: media_container_id }
17
+ )
18
+ end
19
+
20
+ private
21
+
22
+ def prepare_media_container(ig_id:, media_url:, media_type:, caption:)
23
+ if media_url.is_a?(Array)
24
+ children_ids = media_url.map do |url|
25
+ create_media_container(
26
+ ig_id: ig_id, media_url: url, is_carousel_item: true, caption: caption
27
+ )
28
+ end
29
+
30
+ create_media_container(
31
+ ig_id: ig_id, media_url: children_ids, media_type: media_type, caption: caption
32
+ )
33
+ else
34
+ create_media_container(
35
+ ig_id: ig_id, media_url: media_url, media_type: media_type, caption: caption
36
+ )
37
+ end
38
+ end
39
+
40
+ def create_media_container(ig_id:, media_url:, media_type: "IMAGE", is_carousel_item: false, upload_type: nil,
41
+ caption: nil)
42
+ path = "#{INSTAGRAM_GRAPH_API_ENDPOINT}/#{GRAPH_API_VERSION}/#{ig_id}/media"
43
+
44
+ body = { access_token: access_token, media_type: media_type, caption: caption }
45
+
46
+ case media_type
47
+ when "IMAGE"
48
+ body[:image_url] = media_url
49
+ when "VIDEO", "REELS", "STORIES"
50
+ body[:video_url] = media_url
51
+ when "CAROUSEL"
52
+ body[:children] = media_url
53
+ end
54
+
55
+ body[:is_carousel_item] = is_carousel_item if is_carousel_item
56
+ body[:upload_type] = upload_type if upload_type
57
+
58
+ response = ApiHelper.post(path: path, body: body)
59
+ media_container_id = response["id"]
60
+
61
+ wait_for_media_container_status(media_container_id: media_container_id)
62
+
63
+ media_container_id
64
+ end
65
+
66
+ def wait_for_media_container_status(media_container_id:)
67
+ loop do
68
+ status = check_media_container_status(media_container_id: media_container_id)["status"]
69
+
70
+ case status
71
+ when "FINISHED"
72
+ break
73
+ when "IN_PROGRESS"
74
+ sleep 30
75
+ when "EXPIRED"
76
+ raise "Media container has expired. The container was not published within 24 hours."
77
+ when "ERROR"
78
+ raise "Media container failed to complete the publishing process."
79
+ when "PUBLISHED"
80
+ raise "Media container has already been published."
81
+ else
82
+ raise "Unknown media container status: #{status}"
83
+ end
84
+ end
85
+ end
86
+
87
+ def check_media_container_status(media_container_id:)
88
+ path = "#{INSTAGRAM_GRAPH_API_ENDPOINT}/#{GRAPH_API_VERSION}/#{media_container_id}?fields=status_code"
89
+
90
+ ApiHelper.get(
91
+ path: path,
92
+ params: { access_token: access_token }
93
+ )
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "api_helper"
4
+ require_relative "base_client"
5
+
6
+ module Opossum
7
+ # Handles Instagram user information retrieval
8
+ class UserDetails < BaseClient
9
+ def get_user_info(fields:)
10
+ path = "#{INSTAGRAM_GRAPH_API_ENDPOINT}/#{GRAPH_API_VERSION}/me"
11
+
12
+ ApiHelper.get(
13
+ path: path,
14
+ params: { access_token: access_token, fields: fields }
15
+ )
16
+ end
17
+
18
+ def get_long_lived_access_token(client_secret:)
19
+ path = "#{INSTAGRAM_GRAPH_API_ENDPOINT}/access_token"
20
+
21
+ ApiHelper.get(
22
+ path: path,
23
+ params: { access_token: access_token, client_secret: client_secret, grant_type: "ig_exchange_token" }
24
+ )
25
+ end
26
+
27
+ def refresh_access_token
28
+ path = "#{INSTAGRAM_GRAPH_API_ENDPOINT}/refresh_access_token"
29
+
30
+ ApiHelper.get(
31
+ path: path,
32
+ params: { access_token: access_token, grant_type: "ig_refresh_token" }
33
+ )
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Opossum
4
+ VERSION = "0.1.0"
5
+ end
data/lib/opossum.rb ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "opossum/version"
4
+ require_relative "opossum/authenticator"
5
+ require_relative "opossum/user_details"
6
+ require_relative "opossum/publisher"
7
+
8
+ module Opossum
9
+ class Error < StandardError; end
10
+ end
data/sig/opossum.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Opossum
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: opossum
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Vadym Kruchyna
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2025-08-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '13.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '13.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
83
+ description: |
84
+ A comprehensive Ruby library for Instagram media publishing with OAuth authentication, user information retrieval,
85
+ and support for images, videos, carousels with captions. Features include token management, error handling,
86
+ and clean separation of concerns.
87
+ email:
88
+ - kruchina.vadim@gmail.com
89
+ executables: []
90
+ extensions: []
91
+ extra_rdoc_files: []
92
+ files:
93
+ - ".rspec"
94
+ - ".rubocop.yml"
95
+ - CHANGELOG.md
96
+ - CODE_OF_CONDUCT.md
97
+ - LICENSE.txt
98
+ - README.md
99
+ - Rakefile
100
+ - lib/opossum.rb
101
+ - lib/opossum/api_helper.rb
102
+ - lib/opossum/authenticator.rb
103
+ - lib/opossum/base_client.rb
104
+ - lib/opossum/publisher.rb
105
+ - lib/opossum/user_details.rb
106
+ - lib/opossum/version.rb
107
+ - sig/opossum.rbs
108
+ homepage: https://github.com/ninjarender/opossum-instagram-publisher
109
+ licenses:
110
+ - MIT
111
+ metadata:
112
+ allowed_push_host: https://rubygems.org
113
+ homepage_uri: https://github.com/ninjarender/opossum-instagram-publisher
114
+ source_code_uri: https://github.com/ninjarender/opossum-instagram-publisher
115
+ changelog_uri: https://github.com/ninjarender/opossum-instagram-publisher/blob/main/CHANGELOG.md
116
+ bug_tracker_uri: https://github.com/ninjarender/opossum-instagram-publisher/issues
117
+ documentation_uri: https://github.com/ninjarender/opossum-instagram-publisher/blob/main/README.md
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: 3.0.0
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubygems_version: 3.5.22
134
+ signing_key:
135
+ specification_version: 4
136
+ summary: Ruby gem for publishing media to Instagram using Instagram Basic Display
137
+ API
138
+ test_files: []