frameio 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/frameio.rb +37 -0
- data/lib/frameio/auth.rb +57 -0
- data/lib/frameio/client.rb +71 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c82ca404c2e6aad48ce1c3a827b9b5f697779c4419994f2d139ce854114484d3
|
4
|
+
data.tar.gz: 2170b585dc62fce437a66ebf080df32faa2296f8ca647476e8aa69bc92557cd9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3525b2a2d07abc7517b91c152fdcf31c123b565ad6451e19ebf9d152e26b02cb9c3df5f50331747c4849ac98299960e7b890506129a9d7985867a2775f2579c0
|
7
|
+
data.tar.gz: 5f58f0cf46f7726ac26d3db0b2f19c143645d6112e0b99c47c6efcb9c8d6411158df160d46ad9f1ec7311975309d4bc44257cb634270673d5c310f0d843420be
|
data/lib/frameio.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require "httparty"
|
2
|
+
require "addressable/uri"
|
3
|
+
require "uri"
|
4
|
+
require "ostruct"
|
5
|
+
# require "frameio/client"
|
6
|
+
|
7
|
+
# client_id = "e0ec793d-2b70-41b9-b038-762d22b76eb8"
|
8
|
+
# client_secret = "lsqRmdegl0_d"
|
9
|
+
module Frameio
|
10
|
+
# Call this method to modify defaults in your initializers.
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# Frameio.configure do |config|
|
14
|
+
# config.client_id = "abc123"
|
15
|
+
# config.client_secret = "abc123"
|
16
|
+
# config.auth_redirect_url = "abc123"
|
17
|
+
# config.scope = "abc123"
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
class << self
|
21
|
+
attr_accessor :configuration
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.welcome
|
25
|
+
"Welcome to the Frameio ruby gem"
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.configure
|
29
|
+
yield(configuration)
|
30
|
+
end
|
31
|
+
def self.configuration
|
32
|
+
@configuration ||= OpenStruct.new
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
require "frameio/auth"
|
37
|
+
require "frameio/client"
|
data/lib/frameio/auth.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
module Frameio
|
2
|
+
class Auth
|
3
|
+
include HTTParty
|
4
|
+
format :json
|
5
|
+
|
6
|
+
AUTH_URL = "https://applications.frame.io/oauth2/auth".freeze
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
end
|
10
|
+
|
11
|
+
def create_auth_url(state: "default_state")
|
12
|
+
uri = Addressable::URI.new
|
13
|
+
uri.query_values = {
|
14
|
+
response_type: 'code',
|
15
|
+
redirect_uri: Frameio.configuration.auth_redirect_uri,
|
16
|
+
client_id: Frameio.configuration.client_id,
|
17
|
+
scope: Frameio.configuration.scope,
|
18
|
+
state: state
|
19
|
+
}
|
20
|
+
"#{AUTH_URL}?#{uri.query}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def create_auth_token(auth_code:)
|
24
|
+
body = {
|
25
|
+
code: auth_code,
|
26
|
+
grant_type: "authorization_code",
|
27
|
+
redirect_uri: Frameio.configuration.auth_redirect_uri,
|
28
|
+
}
|
29
|
+
request(body)
|
30
|
+
end
|
31
|
+
|
32
|
+
def refresh_auth_token(frameio_token:)
|
33
|
+
body = {
|
34
|
+
grant_type: "refresh_token",
|
35
|
+
refresh_token: frameio_token.refresh_token
|
36
|
+
}
|
37
|
+
request(body)
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def encoded_secret
|
43
|
+
client_id = Frameio.configuration.client_id
|
44
|
+
client_secret = Frameio.configuration.client_secret
|
45
|
+
Base64.strict_encode64("#{client_id}:#{client_secret}")
|
46
|
+
end
|
47
|
+
|
48
|
+
def request(body)
|
49
|
+
HTTParty.send(
|
50
|
+
:post,
|
51
|
+
"https://applications.frame.io/oauth2/token",
|
52
|
+
headers: { Authorization: "Basic #{encoded_secret}" },
|
53
|
+
body: body,
|
54
|
+
)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require "json"
|
2
|
+
module Frameio
|
3
|
+
class Client
|
4
|
+
include HTTParty
|
5
|
+
format :json
|
6
|
+
|
7
|
+
attr_reader :token
|
8
|
+
|
9
|
+
def initialize(token)
|
10
|
+
@token = token
|
11
|
+
end
|
12
|
+
|
13
|
+
def create(request_path, body:)
|
14
|
+
request(:post, request_path, body)
|
15
|
+
end
|
16
|
+
|
17
|
+
def delete(request_path)
|
18
|
+
request(:delete, request_path)
|
19
|
+
end
|
20
|
+
|
21
|
+
def get(request_path)
|
22
|
+
request(:get, request_path)
|
23
|
+
end
|
24
|
+
|
25
|
+
def update(request_path, body:)
|
26
|
+
request(:put, request_path, body)
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_query_string(query_values: {})
|
30
|
+
uri = Addressable::URI.new
|
31
|
+
uri.query_values = query_values
|
32
|
+
uri.query
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_ostruct(hash)
|
36
|
+
OpenStruct.new(hash.each_with_object({}) do |(key, val), memo|
|
37
|
+
memo[key] = val.is_a?(Hash) ? to_ostruct(val) : val
|
38
|
+
end)
|
39
|
+
end
|
40
|
+
|
41
|
+
def auth_headers
|
42
|
+
{
|
43
|
+
Authorization: "Bearer #{access_token}"
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def access_token
|
50
|
+
access_token = @token[:token]&.access_token if @token.methods.include? :access_token
|
51
|
+
access_token = @token[:token][:access_token] if @token.class.to_s == "Hash"
|
52
|
+
return access_token
|
53
|
+
if access_token.empty?
|
54
|
+
raise "Please supply a valid frameio token with an access_token attribute or method"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def base_url
|
59
|
+
"https://api.frame.io/v2"
|
60
|
+
end
|
61
|
+
|
62
|
+
def request(method, path, body: {})
|
63
|
+
if body.empty?
|
64
|
+
HTTParty.send(method, "#{base_url}""#{path}", headers: auth_headers)
|
65
|
+
else
|
66
|
+
HTTParty.send(method, "#{base_url}""#{path}", headers: auth_headers, body: body)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: frameio
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Taylor Preston
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-06-19 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Frameio Ruby is a simple gem that wraps HTTParty and makes it easy to
|
14
|
+
hit the Frameio API.
|
15
|
+
email: taylor.preston.dev@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/frameio.rb
|
21
|
+
- lib/frameio/auth.rb
|
22
|
+
- lib/frameio/client.rb
|
23
|
+
homepage: http://rubygems.org/gems/frameio
|
24
|
+
licenses:
|
25
|
+
- MIT
|
26
|
+
metadata: {}
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubygems_version: 3.0.8
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: A small ruby gem to help with your Frameio integration
|
46
|
+
test_files: []
|