instagram_api_client 0.1.1 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 887baccb0b7d3120a0ee92699dcd921b4c570b72
4
- data.tar.gz: 814b97dfe0ed9fa03a0288083eca1d9ab40d3619
3
+ metadata.gz: 81a47ca968185f59f026e8a94c53b563785690b6
4
+ data.tar.gz: 53001d4edc04cd9792ac2e9bd01be53aa91bd7bc
5
5
  SHA512:
6
- metadata.gz: 4914cbf47863676d499ed7cc7373cab55fef640358d0d2c6abcca69112d7459a639557cb0e1a711f23cdce7cc6249d51b6925c27704d03635f0330a5b107e582
7
- data.tar.gz: bf86c1804a3e89fe4028413354dd88d303f811746bcdd6954e1deed75b2ab38d520051917ff29fb60b6e4b79045a8f4ae46b4f3ca94763881915de9cf0e2997f
6
+ metadata.gz: 2533fde187b43df7de27957e4e8bd03c2734f75a2c9ca0924842ca4e08365726cd54411bf0ef666456e028165341b3103150557a25ced7842220aadfd3d3a719
7
+ data.tar.gz: 5e04b6862a578e6c6f82b6fd24f17a80e63c9276e020898a16f80b45d55e8fbfa84e99a93ee8d357ffe1ca6037312e1a83891a41b7e356b646a3fa1151138f4c
data/README.md CHANGED
@@ -1,24 +1,54 @@
1
- [![License](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/agilie/instagram_api_gem)
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
- A Ruby wrapper for the Instagram API.
6
- You can see the api endpoints here https://www.instagram.com/developer/endpoints/
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
- InstagramAPI.config do |config|
21
- config.access_token = 'put_your_token_here'
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
- The main module of the gem is `InstagramAPI`. It provides a series of methods, regarding each Instagram resource. They are:
30
- `Users`, `Media`, `Comments`, `Likes`, `Tags` and `Locations`. So the `Users` resource methods can be accessed by `InstagramAPI.user`
31
- method, `Tags` by `InstagramAPI.tag` and so on.
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
- | InstagramAPI.user.show | GET /users/self |
40
- | InstagramAPI.user(**user_id**).show | GET /users/**user_id** |
41
- | InstagramAPI.user.recent_media | GET /users/self/media/recent |
42
- | InstagramAPI.user(**user_id**).recent_media | GET /users/**user_id**/media/recent |
43
- | InstagramAPI.user.liked_media | GET /users/self/media/liked |
44
- | InstagramAPI.user.search(**search_query**) | GET /users/search |
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
- | InstagramAPI.user.follows | GET /users/self/follows |
47
- | InstagramAPI.user.followed_by | GET /users/self/followed-by |
48
- | InstagramAPI.user.requested_by | GET /users/self/requested-by |
49
- | InstagramAPI.user.check_relationship(**user_id**) | GET /users/**user_id**/relathionship |
50
- | InstagramAPI.user.change_relationship(**user_id**) | POST /users/**user_id**/relathionship |
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
- | InstagramAPI.media(**media_id**).show | GET /media/**media_id** |
53
- | InstagramAPI.media.short_code(**short_code**) | GET /media/shortcode/**shortcode** |
54
- | InstagramAPI.media.search(**search_query**) | GET /media/search |
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
- | InstagramAPI.media(media_id).likes | GET /media/**media_id**/likes |
57
- | InstagramAPI.media(media_id).add_like | POST /media/**media_id**/likes |
58
- | InstagramAPI.media(media_id).delete_like | DELETE /media/**media_id**/likes |
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
- | InstagramAPI.media(media_id).comments | GET /media/**media_id**/comments |
61
- | InstagramAPI.media(media_id).add_comment | POST /media/**media_id**/comments |
62
- | InstagramAPI.media(media_id).delete_comment(**comment_id**) | DELETE /media/**media_id**/comments/**comment_id** |
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
- | InstagramAPI.tag(**tag_name**).show | GET /tags/**tag_name** |
65
- | InstagramAPI.tag(**tag_name**).recent_media | GET /tags/**tag_name**/media/recent |
66
- | InstagramAPI.tag.search(**search_query**) | GET /tags/search |
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
- | InstagramAPI.location(**location_id**).show | GET /locations/**location_id** |
69
- | InstagramAPI.location(**location_id**).recent_media | GET /locations/**location_id**/media/recent |
70
- | InstagramAPI.location.search(**search_query**) | GET /locations/search |
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
- InstagramAPI.user.search('mell', {count: 10})
77
- InstagramAPI.user('my_user_id').recent_media({min_id: '22721881'})
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
- InstagramAPI.user.search('mell')
83
- InstagramAPI.location.search({lat: 33.10, lng: 15.40})
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
 
@@ -0,0 +1 @@
1
+ theme: jekyll-theme-cayman
@@ -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|
@@ -2,6 +2,8 @@ module InstagramApi
2
2
  module Configuration
3
3
 
4
4
  OPTIONS = [
5
+ :client_id,
6
+ :client_secret,
5
7
  :access_token
6
8
  ].freeze
7
9
 
@@ -1,5 +1,6 @@
1
1
  module InstagramApi
2
2
 
3
+ # Custom error class to rescue from Instagram errors
3
4
  class Error < StandardError
4
5
  attr_reader :message, :type, :code
5
6
 
@@ -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
+
@@ -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
 
@@ -1,3 +1,3 @@
1
1
  module InstagramApi
2
- VERSION = '0.1.1'
2
+ VERSION = '0.2.1'
3
3
  end
@@ -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.1.1
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-07-05 00:00:00.000000000 Z
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