Class: Protons8::Couch::CouchResponse::BaseResponse

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

Overview

Add several methods to all type of response

Direct Known Subclasses

Get, PutPostDelete, View

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ BaseResponse

Returns a new instance of BaseResponse.



97
98
99
# File 'lib/protoncouch.rb', line 97

def initialize(hash)
	@hash = hash
end

Instance Method Details

#attachment(id) ⇒ Object



137
138
139
# File 'lib/protoncouch.rb', line 137

def attachment(id)
	@hash['_attachments'] ? @hash['_attachments'][id] : nil
end

#attachmentsObject



133
134
135
# File 'lib/protoncouch.rb', line 133

def attachments
	@hash['_attachments'] || nil
end

#conflict?Boolean

Returns:

  • (Boolean)


125
126
127
# File 'lib/protoncouch.rb', line 125

def conflict?
	@hash['error'] == 'conflict' ? true : false
end

#error?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/protoncouch.rb', line 101

def error?
	not @hash['error'].nil?
end

#error_nameObject



109
110
111
# File 'lib/protoncouch.rb', line 109

def error_name
	@hash['error'] || 'No error'
end

#no_error?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/protoncouch.rb', line 105

def no_error?
	@hash['error'].nil?
end

#not_found?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/protoncouch.rb', line 117

def not_found?
	@hash['error'] == 'not_found' ? true : false
end

#rawObject



129
130
131
# File 'lib/protoncouch.rb', line 129

def raw
	@hash
end

#reasonObject



113
114
115
# File 'lib/protoncouch.rb', line 113

def reason
	@hash['error'] ? @hash['reason'] : 'No reason - everything ok'
end

#unauth?Boolean

Returns:

  • (Boolean)


121
122
123
# File 'lib/protoncouch.rb', line 121

def unauth?
	@hash['error'] == 'unauthorized' ? true : false
end