Class: Agx::Content::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_id: nil, client_secret: nil, version: nil, prod: true) ⇒ Client

Returns a new instance of Client.



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/agx/content/client.rb', line 6

def initialize(client_id: nil, client_secret: nil, version: nil, prod: true)
  domain = (prod ? "agxplatform.com" : "qaagxplatform.com")
  @client_id = client_id || ENV['AGX_CONTENT_CLIENT_ID']
  @client_secret = client_secret || ENV['AGX_CONTENT_CLIENT_SECRET']
  @site = "https://refdata.#{domain}"
  @token_url = "https://auth.#{domain}/identity/connect/token"
  @version = version || "v1"
  @client = set_client
  @token = {
    access_token: nil,
    expires_at: nil
  }
end

Instance Attribute Details

#client_idObject

Returns the value of attribute client_id.



4
5
6
# File 'lib/agx/content/client.rb', line 4

def client_id
  @client_id
end

#client_secretObject

Returns the value of attribute client_secret.



4
5
6
# File 'lib/agx/content/client.rb', line 4

def client_secret
  @client_secret
end

#siteObject

Returns the value of attribute site.



4
5
6
# File 'lib/agx/content/client.rb', line 4

def site
  @site
end

#token_urlObject

Returns the value of attribute token_url.



4
5
6
# File 'lib/agx/content/client.rb', line 4

def token_url
  @token_url
end

#versionObject

Returns the value of attribute version.



4
5
6
# File 'lib/agx/content/client.rb', line 4

def version
  @version
end

Instance Method Details

#get(resource, params = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/agx/content/client.rb', line 20

def get(resource, params = {})
  validate_credentials

  resource = "/api/#{@version}/#{resource}"
  begin
    response = current_token.get(resource, {:headers => { "oauth-scopes" => "referencedata" }, :params => params})
    parse_response(response.body)
  rescue => e
    handle_error(e)
  end
end