instagram_api_client 0.1.1 → 0.2.1
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 +4 -4
- data/README.md +138 -40
- data/_config.yml +1 -0
- data/lib/instagram_api.rb +3 -1
- data/lib/instagram_api/configuration.rb +2 -0
- data/lib/instagram_api/exceptions.rb +1 -0
- data/lib/instagram_api/subscription.rb +66 -0
- data/lib/instagram_api/user.rb +14 -1
- data/lib/instagram_api/version.rb +1 -1
- data/lib/instagram_api_client.rb +1 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81a47ca968185f59f026e8a94c53b563785690b6
|
4
|
+
data.tar.gz: 53001d4edc04cd9792ac2e9bd01be53aa91bd7bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2533fde187b43df7de27957e4e8bd03c2734f75a2c9ca0924842ca4e08365726cd54411bf0ef666456e028165341b3103150557a25ced7842220aadfd3d3a719
|
7
|
+
data.tar.gz: 5e04b6862a578e6c6f82b6fd24f17a80e63c9276e020898a16f80b45d55e8fbfa84e99a93ee8d357ffe1ca6037312e1a83891a41b7e356b646a3fa1151138f4c
|
data/README.md
CHANGED
@@ -1,24 +1,54 @@
|
|
1
|
-
|
1
|
+
<p align="center">
|
2
|
+
<img width="600" src="https://agilie.com/instagram_api_gem_logo.png" alt="Logo">
|
3
|
+
<img width="100" src="https://agilie.com/logos.png" alt="Logos">
|
4
|
+
</p>
|
5
|
+
|
6
|
+
<p align="center">
|
7
|
+
|
8
|
+
<a href="https://www.agilie.com?utm_source=github&utm_medium=referral&utm_campaign=Git_Ruby&utm_term=instagram_api_gem">
|
9
|
+
<img src="https://img.shields.io/badge/Made%20by%20Agilie-*****-green.svg?style=flat" alt="Made by Agilie">
|
10
|
+
</a>
|
11
|
+
|
12
|
+
<a href="https://github.com/agilie/instagram_api_gem">
|
13
|
+
<img src="https://img.shields.io/github/license/mashape/apistatus.svg" alt="License">
|
14
|
+
</a>
|
15
|
+
|
16
|
+
<a href="https://rubygems.org/gems/instagram_api_client">
|
17
|
+
<img src="http://ruby-gem-downloads-badge.herokuapp.com/instagram_api_client?type=total&color=brightgreen" alt="Downloads">
|
18
|
+
</a>
|
19
|
+
|
20
|
+
</p>
|
2
21
|
|
3
22
|
# InstagramApi
|
4
23
|
|
5
|
-
|
6
|
-
|
24
|
+
<p align="center">
|
25
|
+
<img width="300" src="https://agilie.com/instagram_api_gem.png" alt="Example">
|
26
|
+
</p>
|
27
|
+
A Ruby wrapper for the Instagram API. You can see the api endpoints here https://www.instagram.com/developer/endpoints/
|
7
28
|
|
8
29
|
## Installation
|
9
30
|
|
31
|
+
Install gem in your ruby project
|
10
32
|
```ruby
|
11
33
|
gem install instagram_api_client
|
34
|
+
```
|
35
|
+
|
36
|
+
or just add to it your `Gemfile`
|
37
|
+
```
|
38
|
+
gem 'instagram_api_client'
|
12
39
|
```
|
40
|
+
if you are on the Rails and run `bundle`
|
13
41
|
|
14
42
|
## Usage
|
15
43
|
|
16
44
|
Before you start making the requests to instagram API provide the `access_token` using the configuration
|
17
|
-
wrapping.
|
45
|
+
wrapping. If you are going to use **Subscriptions** you should add client_id and client_secret.
|
18
46
|
|
19
47
|
```ruby
|
20
|
-
|
21
|
-
config.access_token = '
|
48
|
+
InstagramApi.config do |config|
|
49
|
+
config.access_token = 'put your token here'
|
50
|
+
config.client_id = 'put your client ID here'
|
51
|
+
config.client_secret = 'put your client secret here'
|
22
52
|
end
|
23
53
|
```
|
24
54
|
|
@@ -26,65 +56,133 @@ As for now Instagram access token doesn't change or expire, so you can use this
|
|
26
56
|
to generate it http://services.chrisriversdesign.com/instagram-token/
|
27
57
|
I the nearest future the OAuth authorization for access token fetching will be implemented.
|
28
58
|
|
29
|
-
|
30
|
-
|
31
|
-
|
59
|
+
## Resources
|
60
|
+
|
61
|
+
The main module of the gem is `InstagramApi`. It provides a series of methods, regarding each Instagram resource. They are:
|
62
|
+
`Users`, `Media`, `Comments`, `Likes`, `Tags` and `Locations`. So the `Users` resource methods can be accessed by `InstagramApi.user`
|
63
|
+
method, `Tags` by `InstagramApi.tag` and so on.
|
32
64
|
|
33
65
|
The main methods of each resource are `show`, `index`, `create`, `destroy` and `search`. The methods and API endpoints
|
34
66
|
correspondence is as follows
|
35
67
|
|
36
|
-
|
|
68
|
+
| Gem Action | API Endpoint |
|
37
69
|
| -------- | ----- |
|
38
70
|
| **User Resource** | |
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
71
|
+
| InstagramApi.user.show | GET /users/self |
|
72
|
+
| InstagramApi.user(**user_id**).show | GET /users/**user_id** |
|
73
|
+
| InstagramApi.user.recent_media | GET /users/self/media/recent |
|
74
|
+
| InstagramApi.user(**user_id**).recent_media | GET /users/**user_id**/media/recent |
|
75
|
+
| InstagramApi.user.liked_media | GET /users/self/media/liked |
|
76
|
+
| InstagramApi.user.search(**search_query**) | GET /users/search |
|
45
77
|
| *Relationship Endpoints block* | |
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
78
|
+
| InstagramApi.user.follows | GET /users/self/follows |
|
79
|
+
| InstagramApi.user.followed_by | GET /users/self/followed-by |
|
80
|
+
| InstagramApi.user.requested_by | GET /users/self/requested-by |
|
81
|
+
| InstagramApi.user.check_relationship(**user_id**) | GET /users/**user_id**/relathionship |
|
82
|
+
| InstagramApi.user.change_relationship(**user_id**) | POST /users/**user_id**/relathionship |
|
51
83
|
| **Media Resource** | |
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
84
|
+
| InstagramApi.media(**media_id**).show | GET /media/**media_id** |
|
85
|
+
| InstagramApi.media.short_code(**short_code**) | GET /media/shortcode/**shortcode** |
|
86
|
+
| InstagramApi.media.search(**search_query**) | GET /media/search |
|
55
87
|
| *Likes Endpoints block* | |
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
88
|
+
| InstagramApi.media(media_id).likes | GET /media/**media_id**/likes |
|
89
|
+
| InstagramApi.media(media_id).add_like | POST /media/**media_id**/likes |
|
90
|
+
| InstagramApi.media(media_id).delete_like | DELETE /media/**media_id**/likes |
|
59
91
|
| *Comment Endpoints block* | |
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
92
|
+
| InstagramApi.media(media_id).comments | GET /media/**media_id**/comments |
|
93
|
+
| InstagramApi.media(media_id).add_comment | POST /media/**media_id**/comments |
|
94
|
+
| InstagramApi.media(media_id).delete_comment(**comment_id**) | DELETE /media/**media_id**/comments/**comment_id** |
|
63
95
|
| **Tag Resource** | |
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
96
|
+
| InstagramApi.tag(**tag_name**).show | GET /tags/**tag_name** |
|
97
|
+
| InstagramApi.tag(**tag_name**).recent_media | GET /tags/**tag_name**/media/recent |
|
98
|
+
| InstagramApi.tag.search(**search_query**) | GET /tags/search |
|
67
99
|
| **Location Resource** | |
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
100
|
+
| InstagramApi.location(**location_id**).show | GET /locations/**location_id** |
|
101
|
+
| InstagramApi.location(**location_id**).recent_media | GET /locations/**location_id**/media/recent |
|
102
|
+
| InstagramApi.location.search(**search_query**) | GET /locations/search |
|
71
103
|
|
72
104
|
Each method from the list above accepts a hash as a second argument with additional params according to official
|
73
105
|
[instagram developers documentation](https://www.instagram.com/developer/endpoints/) i.e.
|
74
106
|
|
75
107
|
```ruby
|
76
|
-
|
77
|
-
|
108
|
+
InstagramApi.user.search('mell', {count: 10})
|
109
|
+
InstagramApi.user('my_user_id').recent_media({min_id: '22721881'})
|
78
110
|
```
|
79
111
|
|
80
112
|
Search method can get either a query string or a hash. It depends on API requirements, i.e.
|
81
113
|
```ruby
|
82
|
-
|
83
|
-
|
114
|
+
InstagramApi.user.search('mell')
|
115
|
+
InstagramApi.location.search({lat: 33.10, lng: 15.40})
|
84
116
|
```
|
85
117
|
|
86
118
|
Response is a `Hashie::Mash` object
|
87
119
|
|
120
|
+
## Subscriptions
|
121
|
+
|
122
|
+
Subscriptions is a useful feature which allows to receive notifications when people who authenticated your app
|
123
|
+
post new media on Instagram. You can find more information on https://www.instagram.com/developer/subscriptions/
|
124
|
+
|
125
|
+
#### Creating a subscription
|
126
|
+
|
127
|
+
Creating subscription is very simple. Just refer to the [original documentation](https://www.instagram.com/developer/subscriptions/) to
|
128
|
+
check the options available
|
129
|
+
```ruby
|
130
|
+
InstagramApi.subscription.create({
|
131
|
+
object: 'user',
|
132
|
+
aspect: 'media',
|
133
|
+
callback_url: 'http://your.callback/url'
|
134
|
+
})
|
135
|
+
```
|
136
|
+
This method automatically generates `verify_token`. However, you can pass your own, if you prefer
|
137
|
+
```ruby
|
138
|
+
InstagramApi.subscription.create({
|
139
|
+
object: 'user',
|
140
|
+
aspect: 'media',
|
141
|
+
callback_url: 'http://your.callback/url',
|
142
|
+
verify_token: 'MyCustomVerifyToken'
|
143
|
+
})
|
144
|
+
```
|
145
|
+
#### Validating subscription
|
146
|
+
|
147
|
+
When you add a subscription, Instagram will send a GET request to your callback URL to verify the existence of the URL.
|
148
|
+
When Instagram has new data, it'll POST this data to your callback URL. To validate the subscription your callback action
|
149
|
+
should validate verify_token from instagram request and response with a `hub.challenge` parameter value.
|
150
|
+
|
151
|
+
You can easily implement it with a single line
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
# CallbackController
|
155
|
+
|
156
|
+
# GET callback url action
|
157
|
+
def index
|
158
|
+
render plain: InstagramApi.subscription.validate(params)
|
159
|
+
end
|
160
|
+
```
|
161
|
+
or
|
162
|
+
```ruby
|
163
|
+
# CallbackController
|
164
|
+
|
165
|
+
# GET callback url action
|
166
|
+
def index
|
167
|
+
render plain: InstagramApi.subscription.validate(params, 'MyCustomVerifyToken')
|
168
|
+
end
|
169
|
+
```
|
170
|
+
if you are using your own `verify_token`
|
171
|
+
|
172
|
+
#### Managing subscriptions
|
173
|
+
|
174
|
+
You can easily get the list of your subscriptions
|
175
|
+
```ruby
|
176
|
+
InstagramApi.subscription.index
|
177
|
+
```
|
178
|
+
|
179
|
+
or destroy them if you prefer
|
180
|
+
|
181
|
+
```ruby
|
182
|
+
InstagramApi.subscription.destroy({object: 'all'})
|
183
|
+
InstagramApi.subscription.destroy({id: 1})
|
184
|
+
```
|
185
|
+
|
88
186
|
|
89
187
|
## TODOS
|
90
188
|
|
data/_config.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
theme: jekyll-theme-cayman
|
data/lib/instagram_api.rb
CHANGED
@@ -9,10 +9,12 @@ require 'instagram_api/location'
|
|
9
9
|
require 'instagram_api/media'
|
10
10
|
require 'instagram_api/configuration'
|
11
11
|
|
12
|
+
require 'instagram_api/subscription'
|
13
|
+
|
12
14
|
module InstagramApi
|
13
15
|
extend Configuration
|
14
16
|
|
15
|
-
RESOURCES = %w(user location tag media).freeze
|
17
|
+
RESOURCES = %w(user location tag media subscription).freeze
|
16
18
|
|
17
19
|
class << self
|
18
20
|
RESOURCES.each do |resource|
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'instagram_api/common'
|
2
|
+
|
3
|
+
module InstagramApi
|
4
|
+
|
5
|
+
class Subscription
|
6
|
+
|
7
|
+
include Client
|
8
|
+
|
9
|
+
def initialize(fake_param = nil)
|
10
|
+
@client_id = InstagramApi.client_id
|
11
|
+
@client_secret = InstagramApi.client_secret
|
12
|
+
raise 'Invalid configuration: client ID is missing' unless @client_id
|
13
|
+
raise 'Invalid configuration: client secret is missing' unless @client_secret
|
14
|
+
end
|
15
|
+
|
16
|
+
def create(options)
|
17
|
+
@@verify_token = options[:verify_token] || generate_verify_token
|
18
|
+
options = {
|
19
|
+
client_id: @client_id,
|
20
|
+
client_secret: @client_secret,
|
21
|
+
verify_token: @@verify_token,
|
22
|
+
}.merge(options)
|
23
|
+
make_request resource_path,
|
24
|
+
{ body: options },
|
25
|
+
:post
|
26
|
+
end
|
27
|
+
|
28
|
+
def index
|
29
|
+
options = {
|
30
|
+
client_id: @client_id,
|
31
|
+
client_secret: @client_secret
|
32
|
+
}
|
33
|
+
make_request resource_path,
|
34
|
+
{ query: options }
|
35
|
+
end
|
36
|
+
|
37
|
+
def destroy(options)
|
38
|
+
options = {
|
39
|
+
client_id: @client_id,
|
40
|
+
client_secret: @client_secret
|
41
|
+
}.merge(options)
|
42
|
+
make_request resource_path,
|
43
|
+
{ query: options },
|
44
|
+
:delete
|
45
|
+
end
|
46
|
+
|
47
|
+
def validate(params, verify_token = nil)
|
48
|
+
verify_token = verify_token || @@verify_token
|
49
|
+
return unless params['hub.mode'] == 'subscribe' || params['hub.verify_token'] == verify_token
|
50
|
+
params['hub.challenge']
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def generate_verify_token
|
56
|
+
['a'..'z', 'A'..'Z', 0..9].map(&:to_a).flatten.sample(16).join
|
57
|
+
end
|
58
|
+
|
59
|
+
def resource_path
|
60
|
+
"#{BASE_API_URI}/subscriptions"
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
data/lib/instagram_api/user.rb
CHANGED
@@ -2,14 +2,27 @@ require 'instagram_api/common'
|
|
2
2
|
|
3
3
|
module InstagramApi
|
4
4
|
|
5
|
+
# Defines methods which correspond to User resource
|
5
6
|
class User
|
6
7
|
include Search
|
7
8
|
include Resource
|
8
9
|
|
10
|
+
# User instance constructor. Accepts the +user_id+ or refers to +self+
|
11
|
+
|
9
12
|
def initialize(user_id)
|
10
13
|
@user_id = user_id || 'self'
|
11
14
|
end
|
12
15
|
|
16
|
+
# Returns an information about the given user
|
17
|
+
#
|
18
|
+
# @overload show(options={})
|
19
|
+
# @return [Hashie::Mash] The requested user.
|
20
|
+
# @example Return extended information for @shayne
|
21
|
+
# Instagram.user(20)
|
22
|
+
# @format :json
|
23
|
+
# @rate_limited true
|
24
|
+
# @see https://www.instagram.com/developer/endpoints/users/#get_users
|
25
|
+
# @see https://www.instagram.com/developer/endpoints/users/#get_users_self
|
13
26
|
def show(options = {})
|
14
27
|
super @user_id, options
|
15
28
|
end
|
@@ -39,7 +52,7 @@ module InstagramApi
|
|
39
52
|
end
|
40
53
|
|
41
54
|
def change_relationship(user_id, options = {})
|
42
|
-
make_request resource_path("#{user_id}/relationship"), {body: options}, :post
|
55
|
+
make_request resource_path("#{user_id}/relationship"), { body: options }, :post
|
43
56
|
end
|
44
57
|
end
|
45
58
|
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'instagram_api'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: instagram_api_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Mell
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-12-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -110,6 +110,7 @@ files:
|
|
110
110
|
- LICENSE.txt
|
111
111
|
- README.md
|
112
112
|
- Rakefile
|
113
|
+
- _config.yml
|
113
114
|
- bin/console
|
114
115
|
- bin/setup
|
115
116
|
- instagram_api.gemspec
|
@@ -120,9 +121,11 @@ files:
|
|
120
121
|
- lib/instagram_api/exceptions.rb
|
121
122
|
- lib/instagram_api/location.rb
|
122
123
|
- lib/instagram_api/media.rb
|
124
|
+
- lib/instagram_api/subscription.rb
|
123
125
|
- lib/instagram_api/tag.rb
|
124
126
|
- lib/instagram_api/user.rb
|
125
127
|
- lib/instagram_api/version.rb
|
128
|
+
- lib/instagram_api_client.rb
|
126
129
|
homepage: https://github.com/agilie/instagram_api_gem
|
127
130
|
licenses:
|
128
131
|
- MIT
|