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

#initialize(config) ⇒ Connection

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



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

def initialize(config)
  @config = config  # || SharefileConnect::Config.new(ENV['SHAREFILE_KEY'],  ENV['SHAREFILE_SECRET'], ENV['SHAREFILE_USER_NAME'], ENV['SHAREFILE_USER_PASS'], ENV['API_ENDPOINT_DOMAIN'])
  response = HTTParty.post(authentication_uri, authentication_content)
  @token = JSON.parse response.body
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



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

def config
  @config
end

#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



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

def authentication_content
  {
  :body => {
      "grant_type"    => "password",
      "client_id"     => config.sharefile_key,
      "client_secret" => config.sharefile_secret,
      "username"      => config.sharefile_user,
      "password"      => config.sharefile_user_pass
  },
      :headers => {
      "Content-Type" => "application/x-www-form-urlencoded"
  }
  }
end

#authentication_uriObject



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

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

#hostnameObject



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

def hostname
  "#{config.domain}.sf-api.com"
end