frameio-api 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '0901a5840882914621de78e0c9e36bbff287aca801994e5b88201b96ecf31683'
4
+ data.tar.gz: 5223091ad97b2e6b46220e98d3b476e4b71351840b6b29de00dd5795306f474b
5
+ SHA512:
6
+ metadata.gz: 6f4eca7dc8eb1cd7c2b8ddab1093412e37d7c8fbcee759513b00feac7367e45c957d215d4116e921438bf98ce30193b25b9db0b3fa2dda848ff6d5278249c836
7
+ data.tar.gz: 631a196ecd6d488ebf56f085b414783c07fda7bc4b6c44751897b2f85903e0a06d34868b90f225ae1ec56df574ee2468e8b08a01f85e17d786f454ba612852bb
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright Victor Holl
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,101 @@
1
+ # FrameIo
2
+ Very basic (and wip) Frame.io API wrapper
3
+ Only OAuth2 authentification available at the moment.
4
+
5
+
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem "frame_io"
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install frame_io
22
+ ```
23
+
24
+
25
+ ## Usage
26
+ This gem uses and bundles [omniauth-frameio](https://github.com/boxprod/omniauth-frameio)
27
+
28
+ ### Omniauth configuration:
29
+
30
+ This Strategy is meant to be used with [Omniauth](https://github.com/omniauth/omniauth) and has been tested and used with [Devise](https://github.com/heartcombo/devise#omniauth)
31
+
32
+ If using Devise, add this in your Devise.setup in /config/initializers/devise.rb
33
+
34
+ ```ruby
35
+ config.omniauth :frameio,
36
+ ENV['FRAME_CLIENT_ID'], # Your app client ID (on Frame.io Oauth app mgmt)
37
+ ENV['FRAME_CLIENT_SECRET'], # Your app client Secret (on Frame.io Oauth app mgmt)
38
+ scope: 'offline' # list of availables scopes to find on Frame.io dev doc
39
+ ```
40
+
41
+ Please follow Omniauth & Devise instructions for complete configuration.
42
+
43
+ ### Wrapper configuration:
44
+
45
+ ```ruby
46
+ class User < ApplicationRecord
47
+ act_as_frameio_user
48
+ end
49
+ ```
50
+
51
+ By default, frame_io wrapper is expecting the model to respond_to? :access_token, :refresh_token and :expires_at
52
+
53
+ If you want to change the column names:
54
+
55
+ ```ruby
56
+ class User < ApplicationRecord
57
+ act_as_frameio_user access_token: :some_column, refresh_token: :some_other_column, expires_at: :oh_so_other_column
58
+ end
59
+ ```
60
+
61
+ That's all! You now have access to a frame.io client:
62
+
63
+ ```ruby
64
+ current_user.frame_io #=> FrameIo::Client
65
+
66
+ current_user.frame_io.accounts #=> All accounts for user frame.io account
67
+ ```
68
+
69
+ Due to the nature of the 'tree' on Frame.io, objects needs to be retrieved in chain
70
+
71
+ ```ruby
72
+ current_user.accounts.first.teams.first.projects.first.assets.first.children
73
+ ```
74
+
75
+ Each step is cached by default. If you need to refresh, you can pass:
76
+ ```ruby
77
+ cache: false
78
+ ```
79
+ at any moment, like that:
80
+
81
+ ```ruby
82
+ current_user.frame_io.accounts.first.teams.first.projects(cache: false).first.assets
83
+ ```
84
+
85
+ It will refresh from projects and downward.
86
+
87
+
88
+ Lastly, all objects are findable by ID without the need of the 'chain', like that:
89
+
90
+ ```ruby
91
+ current_user.frame_io.asset(id: 'some_id')
92
+ ```
93
+
94
+ It obviously works if and only current_user has access to the file in Frame.io
95
+
96
+
97
+ ## Contributing
98
+ Please raise issues at will, and suggest better ways to handle this!
99
+
100
+ ## License
101
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require "bundler/setup"
2
+
3
+ require "bundler/gem_tasks"
@@ -0,0 +1,17 @@
1
+ module FrameIo
2
+ class Account < OpenStruct
3
+ def self.all(client:)
4
+ client.get_resource('accounts', object_class: self)
5
+ end
6
+
7
+ def self.find(id:, client:)
8
+ client.get_resource("accounts/#{id}", object_class: self)
9
+ end
10
+
11
+ def teams(cache: true)
12
+ @teams = nil unless cache
13
+
14
+ @teams ||= Team.all(account: self, client:)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,8 @@
1
+ ActiveRecord::Base.extend(Module.new do
2
+ def act_as_frameio_user(opts = {})
3
+ FrameIo.access_token = opts[:access_token]
4
+ FrameIo.refresh_token = opts[:refresh_token]
5
+ FrameIo.expires_at = opts[:expires_at]
6
+ include FrameIo
7
+ end
8
+ end)
@@ -0,0 +1,23 @@
1
+ module FrameIo
2
+ class Asset < OpenStruct
3
+ def self.children(asset:, client:)
4
+ client.get_resource("assets/#{asset.id}/children", object_class: self)
5
+ end
6
+
7
+ def self.find(id:, client:)
8
+ client.get_resource("assets/#{id}", object_class: self)
9
+ end
10
+
11
+ def account(cache: true)
12
+ @account = nil unless cache
13
+
14
+ @account ||= Account.find(id: account_id, client:)
15
+ end
16
+
17
+ def children(cache: true)
18
+ @children = nil unless cache
19
+
20
+ @children ||= Asset.children(asset: self, client:)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,90 @@
1
+ module FrameIo
2
+ class Client
3
+ attr_reader :user, :api_key
4
+
5
+ def initialize(user:)
6
+ @user = user
7
+ end
8
+
9
+ def get_resource(resource_path, object_class:)
10
+ check_token
11
+ response = token.get(resource_path)
12
+ result = JSON.parse(
13
+ response.body,
14
+ symbolize_names: true,
15
+ object_class:
16
+ )
17
+ if result.is_a? OpenStruct
18
+ result.client = self
19
+ elsif result.is_a? Array
20
+ result.each { _1.client = self }
21
+ end
22
+ result
23
+ end
24
+
25
+ def token
26
+ OAuth2::AccessToken.from_hash(
27
+ oauth.client,
28
+ {
29
+ access_token: user.send(FrameIo.access_token),
30
+ refresh_token: user.send(FrameIo.refresh_token),
31
+ expires_at: user.send(FrameIo.expires_at)
32
+ }
33
+ )
34
+ end
35
+
36
+ def oauth
37
+ OmniAuth::Strategies::Frameio.new(
38
+ nil,
39
+ ENV['FRAME_CLIENT_ID'],
40
+ ENV['FRAME_CLIENT_SECRET']
41
+ )
42
+ end
43
+
44
+ def accounts(cache: true)
45
+ @accounts = nil unless cache
46
+
47
+ @accounts ||= Account.all(client: self)
48
+ end
49
+
50
+ def current_user
51
+ User.current(client: self)
52
+ end
53
+
54
+ def account(id:)
55
+ Account.find(id:, client: self)
56
+ end
57
+
58
+ def team(id:)
59
+ Team.find(id:, client: self)
60
+ end
61
+
62
+ def project(id:)
63
+ Project.find(id:, client: self)
64
+ end
65
+
66
+ def asset(id:)
67
+ Asset.find(id:, client: self)
68
+ end
69
+
70
+ def custom_action(id:)
71
+ CustomAction.find(id:, client: self)
72
+ end
73
+
74
+ private
75
+
76
+ def check_token
77
+ return unless token.expired?
78
+
79
+ new_token = token.refresh!
80
+
81
+ raise TokenError, 'something went wrong with token refresh' unless new_token.present?
82
+
83
+ user.update(
84
+ frameio_token: new_token.token,
85
+ frameio_token_expires_at: Time.at(new_token.expires_at),
86
+ frameio_refresh_token: new_token.refresh_token
87
+ )
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,7 @@
1
+ module FrameIo
2
+ class Collaborator < OpenStruct
3
+ def self.all(project:, client:)
4
+ client.get_resource("projects/#{project.id}/collaborators", object_class: self)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ module FrameIo
2
+ class CustomAction < OpenStruct
3
+ def self.all(team:, client:)
4
+ client.get_resource("teams/#{team.id}/actions", object_class: self)
5
+ end
6
+
7
+ def self.find(id:, client:)
8
+ client.get_resource("actions/#{id}", object_class: self)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,31 @@
1
+ module FrameIo
2
+ class Project < OpenStruct
3
+ def self.all(team:, client:)
4
+ client.get_resource("teams/#{team.id}/projects", object_class: self)
5
+ end
6
+
7
+ def self.find(id:, client:)
8
+ client.get_resource("projects/#{id}", object_class: self)
9
+ end
10
+
11
+ def root
12
+ @root ||= Asset.find(id: root_asset.id, client:)
13
+ end
14
+
15
+ def account
16
+ root.account
17
+ end
18
+
19
+ def assets(cache: true)
20
+ @assets = nil unless cache
21
+
22
+ @assets ||= root.children(cache:)
23
+ end
24
+
25
+ def collaborators(cache: true)
26
+ @collaborators = nil unless cache
27
+
28
+ @collaborators ||= Collaborator.all(project: self, client:)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,4 @@
1
+ module FrameIo
2
+ class Railtie < ::Rails::Railtie
3
+ end
4
+ end
@@ -0,0 +1,23 @@
1
+ module FrameIo
2
+ class Team < OpenStruct
3
+ def self.all(account:, client:)
4
+ client.get_resource("accounts/#{account.id}/teams?include=user_role", object_class: self)
5
+ end
6
+
7
+ def self.find(id:, client:)
8
+ client.get_resource("teams/#{id}", object_class: self)
9
+ end
10
+
11
+ def projects(cache: true)
12
+ @projects = nil unless cache
13
+
14
+ @projects ||= Project.all(team: self, client:)
15
+ end
16
+
17
+ def custom_actions(cache: true)
18
+ @custom_actions = nil unless cache
19
+
20
+ @custom_actions ||= CustomAction.all(team: self, client:)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,7 @@
1
+ module FrameIo
2
+ class User < OpenStruct
3
+ def self.current(client:)
4
+ client.get_resource('me', object_class: self)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module FrameIo
2
+ VERSION = "0.1.0"
3
+ end
data/lib/frame_io.rb ADDED
@@ -0,0 +1,47 @@
1
+ require "frame_io/version"
2
+ require "frame_io/railtie"
3
+ require 'frame_io/account'
4
+ require 'frame_io/active_record_extension'
5
+ require 'frame_io/asset'
6
+ require 'frame_io/client'
7
+ require 'frame_io/collaborator'
8
+ require 'frame_io/custom_action'
9
+ require 'frame_io/project'
10
+ require 'frame_io/team'
11
+ require 'frame_io/user'
12
+ require 'omniauth-frameio'
13
+
14
+ module FrameIo
15
+ TokenError = Class.new(StandardError)
16
+
17
+ class << self
18
+ attr_writer :access_token, :refresh_token, :expires_at
19
+ end
20
+
21
+ def self.included(base)
22
+ return if [
23
+ access_token,
24
+ refresh_token,
25
+ expires_at
26
+ ].all? { base.attribute_method? _1 }
27
+
28
+ raise TokenError, "#{base} must implement ##{access_token}, ##{refresh_token}, ##{expires_at} or define otherwise at include."
29
+ end
30
+
31
+ def frame_io
32
+ Client.new(user: self)
33
+ end
34
+
35
+ def self.access_token
36
+ @access_token || :access_token
37
+ end
38
+
39
+ def self.refresh_token
40
+ @refresh_token || :refresh_token
41
+ end
42
+
43
+ def self.expires_at
44
+ @expires_at || :expires_at
45
+ end
46
+ end
47
+
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :frame_io do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: frameio-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Victor Holl
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-01-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth-frameio
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 7.1.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 7.1.2
41
+ description: Basic and WIP API wrapper for Frame.io. Uses OAuth2 and omniauth-frameio
42
+ strategy gem.
43
+ email:
44
+ - v_h@me.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - MIT-LICENSE
50
+ - README.md
51
+ - Rakefile
52
+ - lib/frame_io.rb
53
+ - lib/frame_io/account.rb
54
+ - lib/frame_io/active_record_extension.rb
55
+ - lib/frame_io/asset.rb
56
+ - lib/frame_io/client.rb
57
+ - lib/frame_io/collaborator.rb
58
+ - lib/frame_io/custom_action.rb
59
+ - lib/frame_io/project.rb
60
+ - lib/frame_io/railtie.rb
61
+ - lib/frame_io/team.rb
62
+ - lib/frame_io/user.rb
63
+ - lib/frame_io/version.rb
64
+ - lib/tasks/frame_io_tasks.rake
65
+ homepage: https://github.com/boxprod/frame_io
66
+ licenses:
67
+ - MIT
68
+ metadata:
69
+ homepage_uri: https://github.com/boxprod/frame_io
70
+ source_code_uri: https://github.com/boxprod/frame_io
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubygems_version: 3.5.3
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: Basic API Wrapper for Frame.io using OAuth2
90
+ test_files: []