Module: Azure::Storage::Table::BatchResponse
- Defined in:
- table/lib/azure/storage/table/batch_response.rb
Class Method Summary collapse
- .batch_boundary(context) ⇒ Object
- .batch_headers(context) ⇒ Object
- .changeset_boundary_or_end(context) ⇒ Object
- .changeset_headers(context) ⇒ Object
- .current_line(context) ⇒ Object
- .find(context, &block) ⇒ Object
- .parse(data, is_get) ⇒ Object
- .response(context) ⇒ Object
- .response_body(context) ⇒ Object
- .response_headers(context) ⇒ Object
Class Method Details
.batch_boundary(context) ⇒ Object
123 124 125 126 |
# File 'table/lib/azure/storage/table/batch_response.rb', line 123 def self.batch_boundary(context) match = /--batchresponse_(.*)/.match(current_line(context)) match ? match[1] : nil end |
.batch_headers(context) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'table/lib/azure/storage/table/batch_response.rb', line 109 def self.batch_headers(context) match = /(.*): (.*)/.match(current_line(context)) if context[:batch_headers] && (not match) return context[:batch_headers] elsif match context[:batch_headers] ||= {} context[:batch_headers][match[1].downcase] = match[2] return nil else return nil end end |
.changeset_boundary_or_end(context) ⇒ Object
102 103 104 105 106 107 |
# File 'table/lib/azure/storage/table/batch_response.rb', line 102 def self.changeset_boundary_or_end(context) match_boundary = /--changesetresponse_(.*)/.match(current_line(context)) match_end = /--changesetresponse_(.*)--/.match(current_line(context)) || /--batchresponse_(.*)--/.match(current_line(context)) (match_boundary && (not match_end)) ? :boundary : (match_end ? :end : nil) end |
.changeset_headers(context) ⇒ Object
98 99 100 |
# File 'table/lib/azure/storage/table/batch_response.rb', line 98 def self.changeset_headers(context) current_line(context).strip == "" end |
.current_line(context) ⇒ Object
128 129 130 |
# File 'table/lib/azure/storage/table/batch_response.rb', line 128 def self.current_line(context) context[:lines][context[:index]] end |
.find(context, &block) ⇒ Object
53 54 55 56 57 58 59 |
# File 'table/lib/azure/storage/table/batch_response.rb', line 53 def self.find(context, &block) while (context[:index] < context[:lines].length) result = block.call(context) return result if result context[:index] += 1 end end |
.parse(data, is_get) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'table/lib/azure/storage/table/batch_response.rb', line 27 def self.parse(data, is_get) context = { lines: data.lines.to_a, index: 0, responses: [] } find(context) { |c| batch_boundary c } find(context) { |c| batch_headers c } if is_get find(context) { |c| response c } find(context) { |c| response_headers c } find(context) { |c| response_body c } else while (find(context) { |c| changeset_boundary_or_end c } == :boundary) find(context) { |c| changeset_headers c } find(context) { |c| response c } find(context) { |c| response_headers c } find(context) { |c| response_body c } end end context[:responses] end |
.response(context) ⇒ Object
91 92 93 94 95 96 |
# File 'table/lib/azure/storage/table/batch_response.rb', line 91 def self.response(context) match = /HTTP\/1.1 (\d*) (.*)/.match(current_line(context)) return nil unless match response = { status_code: match[1], message: match[2] } context[:responses].push response end |
.response_body(context) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'table/lib/azure/storage/table/batch_response.rb', line 61 def self.response_body(context) end_of_body = nil end_of_body = changeset_boundary_or_end(context.dup.merge!(index: context[:index] + 1)) if context[:index] < (context[:lines].length - 1) if end_of_body context[:responses].last[:body] ||= "" context[:responses].last[:body] << current_line(context) return context[:responses].last[:body] else context[:responses].last[:body] ||= "" context[:responses].last[:body] << current_line(context) return nil end end |
.response_headers(context) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'table/lib/azure/storage/table/batch_response.rb', line 76 def self.response_headers(context) match = /(.*): (.*)/.match(current_line(context)) if context[:responses].last[:headers] && (not match) context[:index] += 1 return context[:responses].last[:headers] elsif match context[:responses].last[:headers] ||= {} context[:responses].last[:headers][match[1].downcase] = match[2].strip return nil else return nil end end |