Class: Pipedrive::Base

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

Overview

Base class for setting HTTParty configurations globally

Direct Known Subclasses

Deal, Organization, Person

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ CloudApp::Base

Create a new CloudApp::Base object.

Only used internally

Parameters:

  • attributes (Hash)


52
53
54
# File 'lib/pipedrive/base.rb', line 52

def initialize(attrs = {})
  super( attrs['data'] )
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



44
45
46
# File 'lib/pipedrive/base.rb', line 44

def data
  @data
end

Class Method Details

.authenticate(token) ⇒ Hash

Sets the authentication credentials in a class variable.

Parameters:

  • email (String)

    cl.ly email

  • password (String)

    cl.ly password

Returns:

  • (Hash)

    authentication credentials



26
27
28
# File 'lib/pipedrive/base.rb', line 26

def self.authenticate(token)
  self.default_params :api_token => token
end

.bad_response(response) ⇒ Object

Examines a bad response and raises an approriate exception

Parameters:

  • response (HTTParty::Response)

Raises:

  • (StandardError)


33
34
35
36
37
38
# File 'lib/pipedrive/base.rb', line 33

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

.new_list(attrs) ⇒ Object



40
41
42
# File 'lib/pipedrive/base.rb', line 40

def self.new_list( attrs )
  attrs['data'].is_a?(Array) ? attrs['data'].map {|data| self.new( 'data' => data ) } : []
end