Class: Pcloud::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



11
12
13
14
# File 'lib/pcloud/client.rb', line 11

def initialize(options = {})
  @username, @password = options.values_at(:username, :password)
  @auth_token = options[:auth_token]
end

Instance Attribute Details

#auth_tokenObject

Returns the value of attribute auth_token.



9
10
11
# File 'lib/pcloud/client.rb', line 9

def auth_token
  @auth_token
end

#password=(value) ⇒ Object (writeonly)

Sets the attribute password

Parameters:

  • value

    the value to set the attribute password to.



8
9
10
# File 'lib/pcloud/client.rb', line 8

def password=(value)
  @password = value
end

#username=(value) ⇒ Object (writeonly)

Sets the attribute username

Parameters:

  • value

    the value to set the attribute username to.



8
9
10
# File 'lib/pcloud/client.rb', line 8

def username=(value)
  @username = value
end

Instance Method Details

#authenticate(options = {}) ⇒ Object



32
33
34
35
# File 'lib/pcloud/client.rb', line 32

def authenticate(options = {})
  @auth_token = authorize(options)['auth']
  self
end

#fileObject



24
25
26
# File 'lib/pcloud/client.rb', line 24

def file
  @file ||= FileHandler.new(self)
end

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



16
17
18
# File 'lib/pcloud/client.rb', line 16

def get(path, params={})
  request(:get, path, params)
end

#http_clientObject



28
29
30
# File 'lib/pcloud/client.rb', line 28

def http_client
  @http_client ||= RestClient::Resource.new(BASE_URL)
end

#post(path, payload = {}, params = {}) ⇒ Object



20
21
22
# File 'lib/pcloud/client.rb', line 20

def post(path, payload={}, params={})
  request(:post, path, params, payload)
end

#request(verb, path, params, payload = {}) ⇒ Object



37
38
39
# File 'lib/pcloud/client.rb', line 37

def request(verb, path, params, payload = {})
  Pcloud::Request.call(self, verb, path, params, payload)
end