instagram_basic_display_api 0.0.0 → 0.0.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/lib/instagram_basic_display_api/api.rb +15 -0
- data/lib/instagram_basic_display_api/client.rb +9 -0
- data/lib/instagram_basic_display_api/client/media.rb +23 -0
- data/lib/instagram_basic_display_api/client/users.rb +22 -0
- data/lib/instagram_basic_display_api/configuration.rb +20 -0
- data/lib/instagram_basic_display_api/connection.rb +14 -0
- data/spec/media_spec.rb +24 -0
- data/spec/users_spec.rb +44 -0
- metadata +9 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e7b67095cbeb00fa16bac4a65d026c6103aa5d7
|
4
|
+
data.tar.gz: 1c107ab2fc453fc8ea07a96f6a2f40768166bb10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 129a60a0f7a7a5c8c2023d7f75723a6bea959a3a138c81b609e5aae222a0c297c9199fa447dcfae7f11014e6ac26ef81cb69a5df6e797226b9959d24327632bb
|
7
|
+
data.tar.gz: fd927248020413309ed4ee09a4387acda38720ed552f1be4c698222f1d340d0ddb4a3b562574e5c54d3a5e8620923ff2a0309cea2b2b7f0ea5c958aa3fc8f3a3
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'instagram_basic_display_api/connection'
|
2
|
+
|
3
|
+
module InstagramBasicDisplayAPI
|
4
|
+
class API
|
5
|
+
attr_accessor :access_token
|
6
|
+
attr_accessor :endpoint
|
7
|
+
|
8
|
+
def initialize(options={})
|
9
|
+
self.access_token = options[:access_token]
|
10
|
+
self.endpoint = options[:endpoint]
|
11
|
+
end
|
12
|
+
|
13
|
+
include Connection
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module InstagramBasicDisplayAPI
|
2
|
+
class Client < API
|
3
|
+
require 'instagram_basic_display_api/client/users'
|
4
|
+
require 'instagram_basic_display_api/client/media'
|
5
|
+
|
6
|
+
include InstagramBasicDisplayAPI::Client::Users
|
7
|
+
include InstagramBasicDisplayAPI::Client::Media
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module InstagramBasicDisplayAPI
|
2
|
+
class Client
|
3
|
+
module Media
|
4
|
+
def media_item(*args)
|
5
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
6
|
+
id = args.first
|
7
|
+
fields = options[:fields] || 'id,caption,media_type,media_url,permalink,thumbnail_url,timestamp,username'
|
8
|
+
response = connection.get("#{id}?fields=#{fields}&access_token=#{access_token}")
|
9
|
+
puts "media item: #{response.body}"
|
10
|
+
response.body
|
11
|
+
end
|
12
|
+
|
13
|
+
def media_children(*args)
|
14
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
15
|
+
id = args.first
|
16
|
+
fields = options[:fields] || 'id,media_type,media_url,permalink,thumbnail_url,timestamp,username'
|
17
|
+
response = connection.get("#{id}/children?fields=#{fields}&access_token=#{access_token}")
|
18
|
+
puts "media children: #{response.body.data}"
|
19
|
+
response.body.data
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module InstagramBasicDisplayAPI
|
2
|
+
class Client
|
3
|
+
module Users
|
4
|
+
def user(*args)
|
5
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
6
|
+
id = args.first || 'me'
|
7
|
+
fields = options[:fields] || 'id,account_type,media_count,username'
|
8
|
+
response = connection.get("#{id}?fields=#{fields}&access_token=#{access_token}")
|
9
|
+
response.body
|
10
|
+
end
|
11
|
+
|
12
|
+
def user_recent_media(*args)
|
13
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
14
|
+
id = args.first || 'me'
|
15
|
+
fields = options[:fields] || 'id,caption,media_type,media_url,permalink,thumbnail_url,timestamp,username'
|
16
|
+
response = connection.get("#{id}/media?fields=#{fields}&access_token=#{access_token}")
|
17
|
+
# puts "user recent media: #{response.body.data}"
|
18
|
+
response.body.data
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module InstagramBasicDisplayAPI
|
2
|
+
module Configuration
|
3
|
+
attr_accessor :access_token
|
4
|
+
attr_accessor :endpoint
|
5
|
+
|
6
|
+
DEFAULT_ENDPOINT = 'https://graph.instagram.com/'.freeze
|
7
|
+
|
8
|
+
def self.extended(base)
|
9
|
+
base.reset
|
10
|
+
end
|
11
|
+
|
12
|
+
def options
|
13
|
+
{ access_token: access_token, endpoint: endpoint }
|
14
|
+
end
|
15
|
+
|
16
|
+
def reset
|
17
|
+
self.endpoint = DEFAULT_ENDPOINT
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'faraday_middleware'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
module InstagramBasicDisplayAPI
|
5
|
+
module Connection
|
6
|
+
def connection
|
7
|
+
Faraday.new endpoint do |conn|
|
8
|
+
# conn.response :json, content_type: /\bjson$/
|
9
|
+
conn.response :json, content_type: /\bjson$/, parser_options: { object_class: OpenStruct }
|
10
|
+
conn.adapter Faraday.default_adapter
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/spec/media_spec.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'dotenv/load'
|
2
|
+
require File.expand_path('../../lib/instagram_basic_display_api', __FILE__)
|
3
|
+
|
4
|
+
describe InstagramBasicDisplayAPI::Client do
|
5
|
+
context '.new' do
|
6
|
+
before do
|
7
|
+
@client = InstagramBasicDisplayAPI.client(access_token: ENV['ACCESS_TOKEN'])
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '.media_item' do
|
11
|
+
it 'should return extended information of a given media item' do
|
12
|
+
media = @client.media_item(ENV['MEDIA_ID'])
|
13
|
+
expect(media.username).to eq(ENV['USERNAME'])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '.media_children' do
|
18
|
+
it 'should return list of children media for the given media item' do
|
19
|
+
media = @client.media_children(ENV['MEDIA_ID'])
|
20
|
+
expect(media.first.username).to eq(ENV['USERNAME'])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/spec/users_spec.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'dotenv/load'
|
2
|
+
require File.expand_path('../../lib/instagram_basic_display_api', __FILE__)
|
3
|
+
|
4
|
+
describe InstagramBasicDisplayAPI::Client do
|
5
|
+
context '.new' do
|
6
|
+
before do
|
7
|
+
@client = InstagramBasicDisplayAPI.client(access_token: ENV['ACCESS_TOKEN'])
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '.user' do
|
11
|
+
context 'with user ID passed' do
|
12
|
+
it 'should return extended information of a given user' do
|
13
|
+
user = @client.user('me')
|
14
|
+
expect(user.username).to eq(ENV['USERNAME'])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'without user ID passed' do
|
19
|
+
it 'should return extended information of a given user' do
|
20
|
+
user = @client.user
|
21
|
+
expect(user.username).to eq(ENV['USERNAME'])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '.user_recent_media' do
|
27
|
+
context 'with user ID passed' do
|
28
|
+
it 'should return a list of recent media items for the given user' do
|
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'])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'without user ID passed' do
|
36
|
+
it 'should return a list of recent media items for the given user' do
|
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'])
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Craig Phares
|
@@ -86,6 +86,14 @@ extensions: []
|
|
86
86
|
extra_rdoc_files: []
|
87
87
|
files:
|
88
88
|
- lib/instagram_basic_display_api.rb
|
89
|
+
- lib/instagram_basic_display_api/api.rb
|
90
|
+
- lib/instagram_basic_display_api/client.rb
|
91
|
+
- lib/instagram_basic_display_api/client/media.rb
|
92
|
+
- lib/instagram_basic_display_api/client/users.rb
|
93
|
+
- lib/instagram_basic_display_api/configuration.rb
|
94
|
+
- lib/instagram_basic_display_api/connection.rb
|
95
|
+
- spec/media_spec.rb
|
96
|
+
- spec/users_spec.rb
|
89
97
|
homepage: https://github.com/sixoverground/instagram_basic_display_api
|
90
98
|
licenses:
|
91
99
|
- MIT
|