Class: FrameIo::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/frame_io/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user:) ⇒ Client

Returns a new instance of Client.



5
6
7
# File 'lib/frame_io/client.rb', line 5

def initialize(user:)
  @user = user
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



3
4
5
# File 'lib/frame_io/client.rb', line 3

def api_key
  @api_key
end

#userObject (readonly)

Returns the value of attribute user.



3
4
5
# File 'lib/frame_io/client.rb', line 3

def user
  @user
end

Instance Method Details

#account(id:) ⇒ Object



54
55
56
# File 'lib/frame_io/client.rb', line 54

def (id:)
  Account.find(id:, client: self)
end

#accounts(cache: true) ⇒ Object



44
45
46
47
48
# File 'lib/frame_io/client.rb', line 44

def accounts(cache: true)
  @accounts = nil unless cache

  @accounts ||= Account.all(client: self)
end

#asset(id:) ⇒ Object



66
67
68
# File 'lib/frame_io/client.rb', line 66

def asset(id:)
  Asset.find(id:, client: self)
end

#current_userObject



50
51
52
# File 'lib/frame_io/client.rb', line 50

def current_user
  User.current(client: self)
end

#custom_action(id:) ⇒ Object



70
71
72
# File 'lib/frame_io/client.rb', line 70

def custom_action(id:)
  CustomAction.find(id:, client: self)
end

#get_resource(resource_path, object_class:) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/frame_io/client.rb', line 9

def get_resource(resource_path, object_class:)
  check_token
  response = token.get(resource_path)
  result = JSON.parse(
    response.body,
    symbolize_names: true,
    object_class:
  )
  if result.is_a? OpenStruct
    result.client = self
  elsif result.is_a? Array
    result.each { _1.client = self }
  end
  result
end

#oauthObject



36
37
38
39
40
41
42
# File 'lib/frame_io/client.rb', line 36

def oauth
  OmniAuth::Strategies::Frameio.new(
    nil,
    ENV['FRAME_CLIENT_ID'],
    ENV['FRAME_CLIENT_SECRET']
  )
end

#project(id:) ⇒ Object



62
63
64
# File 'lib/frame_io/client.rb', line 62

def project(id:)
  Project.find(id:, client: self)
end

#team(id:) ⇒ Object



58
59
60
# File 'lib/frame_io/client.rb', line 58

def team(id:)
  Team.find(id:, client: self)
end

#tokenObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/frame_io/client.rb', line 25

def token
  OAuth2::AccessToken.from_hash(
    oauth.client,
    {
      access_token: user.send(FrameIo.access_token),
      refresh_token: user.send(FrameIo.refresh_token),
      expires_at: user.send(FrameIo.expires_at)
    }
  )
end