Class: Pcloud::Client
- Inherits:
-
Object
- Object
- Pcloud::Client
- Defined in:
- lib/pcloud/client.rb
Instance Attribute Summary collapse
-
#password ⇒ Object
writeonly
Sets the attribute password.
-
#username ⇒ Object
writeonly
Sets the attribute username.
Instance Method Summary collapse
- #auth ⇒ Object
- #file ⇒ Object
- #get(path, params = {}) ⇒ Object
- #http_client ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #post(path, params = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
8 9 10 |
# File 'lib/pcloud/client.rb', line 8 def initialize( = {}) @username, @password = .values_at(:username, :password) end |
Instance Attribute Details
#password=(value) ⇒ Object (writeonly)
Sets the attribute password
6 7 8 |
# File 'lib/pcloud/client.rb', line 6 def password=(value) @password = value end |
#username=(value) ⇒ Object (writeonly)
Sets the attribute username
6 7 8 |
# File 'lib/pcloud/client.rb', line 6 def username=(value) @username = value end |
Instance Method Details
#auth ⇒ Object
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 |
#file ⇒ Object
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_client ⇒ Object
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 |