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.



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

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

Instance Attribute Details

#password=(value) ⇒ Object (writeonly)

Sets the attribute password

Parameters:

  • value

    the value to set the attribute password to.



6
7
8
# File 'lib/pcloud/client.rb', line 6

def password=(value)
  @password = value
end

#username=(value) ⇒ Object (writeonly)

Sets the attribute username

Parameters:

  • value

    the value to set the attribute username to.



6
7
8
# File 'lib/pcloud/client.rb', line 6

def username=(value)
  @username = value
end

Instance Method Details

#authObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/pcloud/client.rb', line 28

def auth
  @auth ||= begin
    raise ConfigurationError, :username unless @username
    raise ConfigurationError, :password unless @password
    digest = JSON.parse(RestClient.get("#{BASE_URL}/getdigest"))['digest']
    passworddigest = digest_data(@password + digest_data( @username.downcase ) + digest)
    JSON.parse(
      RestClient.get("#{BASE_URL}/userinfo?getauth=1&logout=1", 
      {params: {username: @username, digest: digest, passworddigest: passworddigest}})
    )['auth']
  end
end

#fileObject



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

def file
  Resource.new(self).file()
end

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



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

def get(path, params = {})
  resource(path).get(params)
end

#http_clientObject



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

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

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



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

def post(path, params = {})
  resource(path).post(params)
end