Class: CloudApp::Base

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/cloudapp/base.rb

Overview

Base class for setting HTTParty configurations globally

Direct Known Subclasses

Account, Drop, GiftCard

Constant Summary

@@auth =

Define empty auth hash

{}

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (CloudApp::Base) initialize(attributes = {})

Create a new CloudApp::Base object.

Only used internally

Parameters:

  • attributes (Hash) (defaults to: {})


50
51
52
53
# File 'lib/cloudapp/base.rb', line 50

def initialize(attributes = {})
  @data = attributes
  load(@data)
end

Instance Attribute Details

- (Object) data (readonly)

Returns the value of attribute data



42
43
44
# File 'lib/cloudapp/base.rb', line 42

def data
  @data
end

Class Method Details

+ (Hash) authenticate(email, password)

Sets the authentication credentials in a class variable.

Parameters:

  • email (String)

    cl.ly email

  • password (String)

    cl.ly password

Returns:

  • (Hash)

    authentication credentials



28
29
30
# File 'lib/cloudapp/base.rb', line 28

def self.authenticate(email, password)
  @@auth = {:username => email, :password => password}
end

+ (Object) bad_response(response)

Examines a bad response and raises an approriate exception

Parameters:

Raises:

  • (StandardError)


35
36
37
38
39
40
# File 'lib/cloudapp/base.rb', line 35

def self.bad_response(response)
  if response.class == HTTParty::Response
    raise ResponseError, response
  end
  raise StandardError, "Unkown error"
end