instagram_basic_display_api 0.0.1 → 0.0.2
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 +5 -5
- data/lib/instagram_basic_display_api.rb +1 -0
- data/lib/instagram_basic_display_api/client/media.rb +4 -4
- data/lib/instagram_basic_display_api/client/users.rb +5 -3
- data/lib/instagram_basic_display_api/connection.rb +2 -0
- data/lib/instagram_basic_display_api/error.rb +34 -0
- data/lib/instagram_basic_display_api/raise_http_exception.rb +63 -0
- data/spec/media_spec.rb +1 -1
- data/spec/users_spec.rb +4 -4
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 852278006c3aba2b7b380d04ac6689758074d57289e231422670497d529acce5
|
4
|
+
data.tar.gz: ebda7e248c2764f4e8dd7ede9d7a75eca2eba4adf9cb957776b30329881fc7cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 004d8198ccc6d640487df8fc5a9b913140907749a7966a2f248441346774caa55d4ce25a038db9ceeece5a0b47c32de1fb5aaa46a002c890e5da36a21e13c95f
|
7
|
+
data.tar.gz: fb734308b4f3976f348a7b60274a9d4fab2337ea7074dd41394284351cceb2743e9d078515bc600b8032185b959ef85dd1fec37429ec6230e574e049e3a62b12
|
@@ -6,7 +6,6 @@ module InstagramBasicDisplayAPI
|
|
6
6
|
id = args.first
|
7
7
|
fields = options[:fields] || 'id,caption,media_type,media_url,permalink,thumbnail_url,timestamp,username'
|
8
8
|
response = connection.get("#{id}?fields=#{fields}&access_token=#{access_token}")
|
9
|
-
puts "media item: #{response.body}"
|
10
9
|
response.body
|
11
10
|
end
|
12
11
|
|
@@ -14,9 +13,10 @@ module InstagramBasicDisplayAPI
|
|
14
13
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
15
14
|
id = args.first
|
16
15
|
fields = options[:fields] || 'id,media_type,media_url,permalink,thumbnail_url,timestamp,username'
|
17
|
-
|
18
|
-
|
19
|
-
response.
|
16
|
+
limit = options[:limit] || ''
|
17
|
+
after = options[:after] || ''
|
18
|
+
response = connection.get("#{id}/children?fields=#{fields}&access_token=#{access_token}&limit=#{limit}&after=#{after}")
|
19
|
+
response.body
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -13,9 +13,11 @@ module InstagramBasicDisplayAPI
|
|
13
13
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
14
14
|
id = args.first || 'me'
|
15
15
|
fields = options[:fields] || 'id,caption,media_type,media_url,permalink,thumbnail_url,timestamp,username'
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
limit = options[:limit] || ''
|
17
|
+
after = options[:after] || ''
|
18
|
+
url = "#{id}/media?fields=#{fields}&access_token=#{access_token}&limit=#{limit}&after=#{after}"
|
19
|
+
response = connection.get(url)
|
20
|
+
response.body
|
19
21
|
end
|
20
22
|
end
|
21
23
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'faraday_middleware'
|
2
2
|
require 'ostruct'
|
3
|
+
require 'instagram_basic_display_api/raise_http_exception'
|
3
4
|
|
4
5
|
module InstagramBasicDisplayAPI
|
5
6
|
module Connection
|
@@ -7,6 +8,7 @@ module InstagramBasicDisplayAPI
|
|
7
8
|
Faraday.new endpoint do |conn|
|
8
9
|
# conn.response :json, content_type: /\bjson$/
|
9
10
|
conn.response :json, content_type: /\bjson$/, parser_options: { object_class: OpenStruct }
|
11
|
+
conn.use InstagramBasicDisplayAPI::RaiseHttpException
|
10
12
|
conn.adapter Faraday.default_adapter
|
11
13
|
end
|
12
14
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module InstagramBasicDisplayAPI
|
2
|
+
# Custom error class for rescuing from all Instagram errors
|
3
|
+
class Error < StandardError; end
|
4
|
+
|
5
|
+
# Raised when Instagram returns the HTTP status code 400
|
6
|
+
class BadRequest < Error; end
|
7
|
+
|
8
|
+
# Raised when Instagram returns the HTTP status code 403
|
9
|
+
class Forbidden < Error; end
|
10
|
+
|
11
|
+
# Raised when Instagram returns the HTTP status code 404
|
12
|
+
class NotFound < Error; end
|
13
|
+
|
14
|
+
# Raised when Instagram returns the HTTP status code 429
|
15
|
+
class TooManyRequests < Error; end
|
16
|
+
|
17
|
+
# Raised when Instagram returns the HTTP status code 500
|
18
|
+
class InternalServerError < Error; end
|
19
|
+
|
20
|
+
# Raised when Instagram returns the HTTP status code 502
|
21
|
+
class BadGateway < Error; end
|
22
|
+
|
23
|
+
# Raised when Instagram returns the HTTP status code 503
|
24
|
+
class ServiceUnavailable < Error; end
|
25
|
+
|
26
|
+
# Raised when Instagram returns the HTTP status code 504
|
27
|
+
class GatewayTimeout < Error; end
|
28
|
+
|
29
|
+
# Raised when a subscription payload hash is invalid
|
30
|
+
class InvalidSignature < Error; end
|
31
|
+
|
32
|
+
# Raised when Instagram returns the HTTP status code 429
|
33
|
+
class RateLimitExceeded < Error; end
|
34
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
# @private
|
4
|
+
module InstagramBasicDisplayAPI
|
5
|
+
# @private
|
6
|
+
class RaiseHttpException < Faraday::Middleware
|
7
|
+
def call(env)
|
8
|
+
@app.call(env).on_complete do |response|
|
9
|
+
case response[:status].to_i
|
10
|
+
when 400
|
11
|
+
raise InstagramBasicDisplayAPI::BadRequest, error_message_400(response)
|
12
|
+
when 403
|
13
|
+
raise InstagramBasicDisplayAPI::Forbidden, error_message_400(response)
|
14
|
+
when 404
|
15
|
+
raise InstagramBasicDisplayAPI::NotFound, error_message_400(response)
|
16
|
+
when 429
|
17
|
+
raise InstagramBasicDisplayAPI::TooManyRequests, error_message_400(response)
|
18
|
+
when 500
|
19
|
+
raise InstagramBasicDisplayAPI::InternalServerError, error_message_500(response, "Something is technically wrong.")
|
20
|
+
when 502
|
21
|
+
raise InstagramBasicDisplayAPI::BadGateway, error_message_500(response, "The server returned an invalid or incomplete response.")
|
22
|
+
when 503
|
23
|
+
raise InstagramBasicDisplayAPI::ServiceUnavailable, error_message_500(response, "Instagram is rate limiting your requests.")
|
24
|
+
when 504
|
25
|
+
raise InstagramBasicDisplayAPI::GatewayTimeout, error_message_500(response, "504 Gateway Time-out")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def initialize(app)
|
31
|
+
super app
|
32
|
+
@parser = nil
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def error_message_400(response)
|
38
|
+
"#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]}#{error_body(response[:body])}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def error_body(body)
|
42
|
+
# body gets passed as a string, not sure if it is passed as something else from other spots?
|
43
|
+
if not body.nil? and not body.empty? and body.kind_of?(String)
|
44
|
+
# removed multi_json thanks to wesnolte's commit
|
45
|
+
if body == "Sorry, this content isn't available right now"
|
46
|
+
body
|
47
|
+
else
|
48
|
+
body = ::JSON.parse(body)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
if body.nil?
|
53
|
+
nil
|
54
|
+
elsif body['error'] and body['error']['message'] and not body['error']['message'].empty?
|
55
|
+
": #{body['error']['message']}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def error_message_500(response, body=nil)
|
60
|
+
"#{response[:method].to_s.upcase} #{response[:url].to_s}: #{[response[:status].to_s + ':', body].compact.join(' ')}"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/spec/media_spec.rb
CHANGED
@@ -17,7 +17,7 @@ describe InstagramBasicDisplayAPI::Client do
|
|
17
17
|
describe '.media_children' do
|
18
18
|
it 'should return list of children media for the given media item' do
|
19
19
|
media = @client.media_children(ENV['MEDIA_ID'])
|
20
|
-
expect(media.first.username).to eq(ENV['USERNAME'])
|
20
|
+
expect(media.data.first.username).to eq(ENV['USERNAME'])
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
data/spec/users_spec.rb
CHANGED
@@ -27,16 +27,16 @@ describe InstagramBasicDisplayAPI::Client do
|
|
27
27
|
context 'with user ID passed' do
|
28
28
|
it 'should return a list of recent media items for the given user' do
|
29
29
|
recent_media = @client.user_recent_media('me')
|
30
|
-
expect(recent_media).to be_a Array
|
31
|
-
expect(recent_media.first.username).to eq(ENV['USERNAME'])
|
30
|
+
expect(recent_media.data).to be_a Array
|
31
|
+
expect(recent_media.data.first.username).to eq(ENV['USERNAME'])
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
35
|
context 'without user ID passed' do
|
36
36
|
it 'should return a list of recent media items for the given user' do
|
37
37
|
recent_media = @client.user_recent_media
|
38
|
-
expect(recent_media).to be_a Array
|
39
|
-
expect(recent_media.first.username).to eq(ENV['USERNAME'])
|
38
|
+
expect(recent_media.data).to be_a Array
|
39
|
+
expect(recent_media.data.first.username).to eq(ENV['USERNAME'])
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: instagram_basic_display_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Craig Phares
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -92,6 +92,8 @@ files:
|
|
92
92
|
- lib/instagram_basic_display_api/client/users.rb
|
93
93
|
- lib/instagram_basic_display_api/configuration.rb
|
94
94
|
- lib/instagram_basic_display_api/connection.rb
|
95
|
+
- lib/instagram_basic_display_api/error.rb
|
96
|
+
- lib/instagram_basic_display_api/raise_http_exception.rb
|
95
97
|
- spec/media_spec.rb
|
96
98
|
- spec/users_spec.rb
|
97
99
|
homepage: https://github.com/sixoverground/instagram_basic_display_api
|
@@ -113,8 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
115
|
- !ruby/object:Gem::Version
|
114
116
|
version: '0'
|
115
117
|
requirements: []
|
116
|
-
|
117
|
-
rubygems_version: 2.5.1
|
118
|
+
rubygems_version: 3.1.4
|
118
119
|
signing_key:
|
119
120
|
specification_version: 4
|
120
121
|
summary: Instagram Basic Display API
|