Class: Agx::Pictures::Client
- Inherits:
-
Object
- Object
- Agx::Pictures::Client
- Defined in:
- lib/agx/pictures/client.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#authorize_url ⇒ Object
Returns the value of attribute authorize_url.
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
Returns the value of attribute client_secret.
-
#host ⇒ Object
Returns the value of attribute host.
-
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
-
#site ⇒ Object
Returns the value of attribute site.
-
#sync_id ⇒ Object
Returns the value of attribute sync_id.
-
#token_expires_at ⇒ Object
Returns the value of attribute token_expires_at.
-
#token_url ⇒ Object
Returns the value of attribute token_url.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
- #get(id) ⇒ Object
- #get_metadata(id) ⇒ Object
-
#initialize(client_id: nil, client_secret: nil, version: nil, sync_id: nil, access_token: nil, refresh_token: nil, token_expires_at: nil, prod: true, filepath: nil) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(client_id: nil, client_secret: nil, version: nil, sync_id: nil, access_token: nil, refresh_token: nil, token_expires_at: nil, prod: true, filepath: nil) ⇒ Client
Returns a new instance of Client.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/agx/pictures/client.rb', line 7 def initialize(client_id: nil, client_secret: nil, version: nil, sync_id: nil, access_token: nil, refresh_token: nil, token_expires_at: nil, prod: true, filepath: nil) domain = (prod ? "agxplatform.com" : "qaagxplatform.com") @client_id = client_id || ENV['AGX_SYNC_CLIENT_ID'] @client_secret = client_secret || ENV['AGX_SYNC_CLIENT_SECRET'] @site = "https://pictures.#{domain}" @host = host || "pictures.#{domain}" @authorize_url = "https://auth.#{domain}/identity/connect/Authorize" @token_url = "https://auth.#{domain}/identity/connect/Token" @version = version || "v1" @sync_id = sync_id @api_url = "#{@site}/api/#{@version}/picture/" @filepath = filepath @headers = { 'oauth-scopes' => "Sync", 'Host' => @host } @client = set_client @token = { access_token: access_token, refresh_token: refresh_token, expires_at: token_expires_at } end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
4 5 6 |
# File 'lib/agx/pictures/client.rb', line 4 def access_token @access_token end |
#authorize_url ⇒ Object
Returns the value of attribute authorize_url.
4 5 6 |
# File 'lib/agx/pictures/client.rb', line 4 def @authorize_url end |
#client_id ⇒ Object
Returns the value of attribute client_id.
4 5 6 |
# File 'lib/agx/pictures/client.rb', line 4 def client_id @client_id end |
#client_secret ⇒ Object
Returns the value of attribute client_secret.
4 5 6 |
# File 'lib/agx/pictures/client.rb', line 4 def client_secret @client_secret end |
#host ⇒ Object
Returns the value of attribute host.
4 5 6 |
# File 'lib/agx/pictures/client.rb', line 4 def host @host end |
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
4 5 6 |
# File 'lib/agx/pictures/client.rb', line 4 def refresh_token @refresh_token end |
#site ⇒ Object
Returns the value of attribute site.
4 5 6 |
# File 'lib/agx/pictures/client.rb', line 4 def site @site end |
#sync_id ⇒ Object
Returns the value of attribute sync_id.
4 5 6 |
# File 'lib/agx/pictures/client.rb', line 4 def sync_id @sync_id end |
#token_expires_at ⇒ Object
Returns the value of attribute token_expires_at.
4 5 6 |
# File 'lib/agx/pictures/client.rb', line 4 def token_expires_at @token_expires_at end |
#token_url ⇒ Object
Returns the value of attribute token_url.
4 5 6 |
# File 'lib/agx/pictures/client.rb', line 4 def token_url @token_url end |
#version ⇒ Object
Returns the value of attribute version.
4 5 6 |
# File 'lib/agx/pictures/client.rb', line 4 def version @version end |
Instance Method Details
#get(id) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/agx/pictures/client.rb', line 33 def get(id) url = "#{@api_url}#{id}" begin response = current_token.get(url, :headers => @headers) filename = "#{@filepath}/#{@sync_id}_#{id}.jpeg" File.open(filename, 'wb') { |fp| fp.write(response.body) } rescue => e handle_error(e) end end |
#get_metadata(id) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/agx/pictures/client.rb', line 44 def (id) url = "#{@api_url}#{id}/metadata" begin response = current_token.get(url, :headers => @headers) parse_response(response.body) rescue => e handle_error(e) end end |