Class: SharefileConnect::Connection

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/sharefile_connect/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConnection

base_uri “https://#'API_ENDPOINT_DOMAIN'.sf-api.com”



7
8
9
10
# File 'lib/sharefile_connect/connection.rb', line 7

def initialize
  response = HTTParty.post(authentication_uri, authentication_content)
  @token = JSON.parse response.body
end

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token.



3
4
5
# File 'lib/sharefile_connect/connection.rb', line 3

def token
  @token
end

Instance Method Details

#authentication_contentObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/sharefile_connect/connection.rb', line 21

def authentication_content
  {
  :body => {
      "grant_type"    => "password",
      "client_id"     => ENV['SHAREFILE_KEY'],
      "client_secret" => ENV['SHAREFILE_SECRET'],
      "username"      => ENV['SHAREFILE_USER_NAME'],
      "password"      => ENV['SHAREFILE_USER_PASS']
  },
      :headers => {
      "Content-Type" => "application/x-www-form-urlencoded"
  }
  }
end

#authentication_uriObject



16
17
18
19
# File 'lib/sharefile_connect/connection.rb', line 16

def authentication_uri
  "https://#{hostname}/oauth/token"
  # "/oauth/token"
end

#hostnameObject



12
13
14
# File 'lib/sharefile_connect/connection.rb', line 12

def hostname
  "#{ENV['API_ENDPOINT_DOMAIN']}.sf-api.com"
end