• Stars
    star
    104
  • Rank 320,227 (Top 7 %)
  • Language
    Ruby
  • License
    MIT License
  • Created almost 7 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Ruby wrapper for the Instagram API

Logo Logos

Made by Agilie License Downloads

InstagramApi

Example

A Ruby wrapper for the Instagram API. You can see the api endpoints here https://www.instagram.com/developer/endpoints/

Installation

Install gem in your ruby project

gem install instagram_api_client

or just add to it your Gemfile

gem 'instagram_api_client'

if you are on the Rails and run bundle

Usage

Before you start making the requests to instagram API provide the access_token using the configuration wrapping. If you are going to use Subscriptions you should add client_id and client_secret.

InstagramApi.config do |config|
  config.access_token = 'put your token here'
  config.client_id = 'put your client ID here'
  config.client_secret = 'put your client secret here'
end

As for now Instagram access token doesn't change or expire, so you can use this simple-to-use service to generate it http://services.chrisriversdesign.com/instagram-token/ I the nearest future the OAuth authorization for access token fetching will be implemented.

Resources

The main module of the gem is InstagramApi. It provides a series of methods, regarding each Instagram resource. They are: Users, Media, Comments, Likes, Tags and Locations. So the Users resource methods can be accessed by InstagramApi.user method, Tags by InstagramApi.tag and so on.

The main methods of each resource are show, index, create, destroy and search. The methods and API endpoints correspondence is as follows

Gem Action API Endpoint
User Resource
InstagramApi.user.show GET /users/self
InstagramApi.user(user_id).show GET /users/user_id
InstagramApi.user.recent_media GET /users/self/media/recent
InstagramApi.user(user_id).recent_media GET /users/user_id/media/recent
InstagramApi.user.liked_media GET /users/self/media/liked
InstagramApi.user.search(search_query) GET /users/search
Relationship Endpoints block
InstagramApi.user.follows GET /users/self/follows
InstagramApi.user.followed_by GET /users/self/followed-by
InstagramApi.user.requested_by GET /users/self/requested-by
InstagramApi.user.check_relationship(user_id) GET /users/user_id/relathionship
InstagramApi.user.change_relationship(user_id) POST /users/user_id/relathionship
Media Resource
InstagramApi.media(media_id).show GET /media/media_id
InstagramApi.media.short_code(short_code) GET /media/shortcode/shortcode
InstagramApi.media.search(search_query) GET /media/search
Likes Endpoints block
InstagramApi.media(media_id).likes GET /media/media_id/likes
InstagramApi.media(media_id).add_like POST /media/media_id/likes
InstagramApi.media(media_id).delete_like DELETE /media/media_id/likes
Comment Endpoints block
InstagramApi.media(media_id).comments GET /media/media_id/comments
InstagramApi.media(media_id).add_comment POST /media/media_id/comments
InstagramApi.media(media_id).delete_comment(comment_id) DELETE /media/media_id/comments/comment_id
Tag Resource
InstagramApi.tag(tag_name).show GET /tags/tag_name
InstagramApi.tag(tag_name).recent_media GET /tags/tag_name/media/recent
InstagramApi.tag.search(search_query) GET /tags/search
Location Resource
InstagramApi.location(location_id).show GET /locations/location_id
InstagramApi.location(location_id).recent_media GET /locations/location_id/media/recent
InstagramApi.location.search(search_query) GET /locations/search

Each method from the list above accepts a hash as a second argument with additional params according to official instagram developers documentation i.e.

InstagramApi.user.search('mell', {count: 10})
InstagramApi.user('my_user_id').recent_media({min_id: '22721881'})

Search method can get either a query string or a hash. It depends on API requirements, i.e.

InstagramApi.user.search('mell')
InstagramApi.location.search({lat: 33.10, lng: 15.40})

Response is a Hashie::Mash object

Subscriptions

Subscriptions is a useful feature which allows to receive notifications when people who authenticated your app post new media on Instagram. You can find more information on https://www.instagram.com/developer/subscriptions/

Creating a subscription

Creating subscription is very simple. Just refer to the original documentation to check the options available

InstagramApi.subscription.create({
    object: 'user',
    aspect: 'media',
    callback_url: 'http://your.callback/url'
})

This method automatically generates verify_token. However, you can pass your own, if you prefer

InstagramApi.subscription.create({
    object: 'user',
    aspect: 'media',
    callback_url: 'http://your.callback/url',
    verify_token: 'MyCustomVerifyToken'
})

Validating subscription

When you add a subscription, Instagram will send a GET request to your callback URL to verify the existence of the URL. When Instagram has new data, it'll POST this data to your callback URL. To validate the subscription your callback action should validate verify_token from instagram request and response with a hub.challenge parameter value.

You can easily implement it with a single line

# CallbackController

# GET callback url action
def index
    render plain: InstagramApi.subscription.validate(params)
end

or

# CallbackController

# GET callback url action
def index
    render plain: InstagramApi.subscription.validate(params, 'MyCustomVerifyToken')
end

if you are using your own verify_token

Managing subscriptions

You can easily get the list of your subscriptions

InstagramApi.subscription.index

or destroy them if you prefer

InstagramApi.subscription.destroy({object: 'all'})
InstagramApi.subscription.destroy({id: 1})

TODOS

  1. OAuth authorization for access token fetching
  2. Incode Documentation
  3. Cover functionality with tests

Troubleshooting

Problems? Check the Issues block to find the solution or create an new issue that we will fix asap. Feel free to contribute. This project is intended to be a safe, welcoming space for collaboration.

Author

This gem is open-sourced by Agilie Team ([email protected])

Contributor

Sergey Mell

Contact us

If you have any questions, suggestions or just need a help with web or mobile development, please email us at [email protected]. You can ask us anything from basic to complex questions.

We will continue publishing new open-source projects. Stay with us, more updates will follow!

License

The gem is available as open source under the MIT License (MIT) Copyright © 2017 Agilie Team

More Repositories

1

AGCircularPicker

AGCircularPicker is helpful component for creating a controller aimed to manage any calculated parameter
Swift
625
star
2

DisPlayers-Audio-Visualizers

DisPlayer is a customizable audio visualization component that works with recording and playing back audio files
Objective-C
308
star
3

AGImageControls

cool tools for image edition
Swift
227
star
4

AGVolumeControlView

Visual regulator can be connected to a player or other smart house’s device making the process of controlling the level of a particular characteristic
Swift
172
star
5

AGInterfaceInteraction

library performs interaction with UI interface
Swift
156
star
6

AGLocationDispatcher

Location manage framework working in different modes
Objective-C
149
star
7

CircularPicker

CircularPicker is helpful for creating a controller aimed to manage any calculated parameter.
Kotlin
83
star
8

VolumeControlView

Visual regulator can be connected to a player or other smart house’s device making the process of controlling the level of a particular characteristic much easier.
Kotlin
75
star
9

dribbble-ios-sdk

Unofficial Dribbble iOS wrapper allows you to integrate Dribble API into iOS application (Designer, Shot, Comment, User Story, Like, Follow)
Objective-C
73
star
10

InterfaceInteraction

Interact your app's interface elements with different effects!
Kotlin
57
star
11

RotatableAutofitEditText

Extended EditText which allows to move, rotate and resize text at the same time
Java
53
star
12

GoButton

This button is used for displaying an animation while a request is going. It could be run with infinite animation loop or with finish animation as well.
JavaScript
51
star
13

MobileGift

Simplifies interaction with GIF images.
Kotlin
46
star
14

canvas-image-cover-position

Calculating image position for scaling it on the canvas.
HTML
39
star
15

AGMobileGiftInterface

simplified interaction with GIF animations
Swift
39
star
16

dribbble-android-sdk

Dribbble Android SDK is an unofficial wrapper for Dribbble API v1. (Designer, Shot, Comment, User Story, Like, Follow)
Java
31
star
17

AnimatedToggleMenu

The Animated Toggle Menu is helpful for creating websites. It’s lightweight, easy-to-use and requires minimum lines of code.
CSS
28
star
18

PXSDK

Objective-C
27
star
19

science-fiction-magazines-blog

Blog template (concept) is inspired by stylish science fiction magazines of the 80-90s.
CSS
26
star
20

gtm-in-viewport-manager

A manager of in-viewport events for GTM (Google Tag Manager).
HTML
21
star
21

Web-Time-Tracker

Plugin named Timetracker is a time counter that works in both increase and decrease directions.
JavaScript
21
star
22

Rails-Application-Template

Base template for creating rails applications.
Ruby
18
star
23

ng2-dialog-window

Modal/dialog windows and popups module for Angular applications.
JavaScript
17
star
24

Bouncing-Carousel

The bouncing carousel is an experiment with SVG animations technology.
CSS
14
star
25

viper_sample

Swift
10
star
26

electrum-proxy-middleware

ExpressJS middleware to add functionality for proxying requests to Electrum servers
TypeScript
7
star
27

vimeo-api-gem

A Ruby wrapper for the Vimeo API. Utilizes v3 API version
Ruby
6
star
28

AIS-MobileDesign

A Mobile Design API client for Agilie IT School teaching purposes
JavaScript
5
star
29

Agilie-IT-School

A sandbox repository for experiments with AngularJS techniques and studying purposes for Agilie IT School students
HTML
4
star
30

swift_viper_template

The template for creating VIPER module using generamba in Swift
Liquid
4
star
31

kraken-wsclient-js

Kraken WebSockets client in JS for the Kraken websocket API.
TypeScript
2
star
32

rails-generators

Rails ready-to-use generators to improve adding libs that we are usually using
Ruby
2
star
33

angular-helpies

Helping instances for developing Angular applications
HTML
2
star
34

action-button

JavaScript
1
star