Class: ExoBasic::JsonHttp

Inherits:
Object
  • Object
show all
Defined in:
lib/exobasic/http/json_http.rb

Class Method Summary collapse

Class Method Details

.append_http_body(result, k, v) ⇒ Object



38
39
40
41
42
43
# File 'lib/exobasic/http/json_http.rb', line 38

def self.append_http_body(result, k, v)
  result[:http_return] = 200
  result[:body][k]     = v

  false
end

.append_http_error(result, code, err) ⇒ Object



24
25
26
27
28
29
# File 'lib/exobasic/http/json_http.rb', line 24

def self.append_http_error(result, code, err)
  result[:http_return] = code
  result[:errors].push(err)

  true
end

.append_http_errors(result, code, errs) ⇒ Object



31
32
33
34
35
36
# File 'lib/exobasic/http/json_http.rb', line 31

def self.append_http_errors(result, code, errs)
  result[:http_return] = code
  result[:errors]     += errs

  true
end

.append_result_body(result, k, v) ⇒ Object



75
76
77
78
79
80
# File 'lib/exobasic/http/json_http.rb', line 75

def self.append_result_body(result, k, v)
  result[:success] = true
  result[:body][k] = v

  false
end

.append_result_error(result, err) ⇒ Object



61
62
63
64
65
66
# File 'lib/exobasic/http/json_http.rb', line 61

def self.append_result_error(result, err)
  result[:success] = false
  result[:errors].push(err)

  true
end

.append_result_errors(result, errs) ⇒ Object



68
69
70
71
72
73
# File 'lib/exobasic/http/json_http.rb', line 68

def self.append_result_errors(result, errs)
  result[:success] = false
  result[:errors]  += errs

  true
end

.is_success?(code) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
13
# File 'lib/exobasic/http/json_http.rb', line 7

def self.is_success?(code)
  begin
    JsonHttp.is_success_raw?(code.to_i)
  rescue
    false
  end
end

.is_success_raw?(code) ⇒ Boolean

Returns:

  • (Boolean)


3
4
5
# File 'lib/exobasic/http/json_http.rb', line 3

def self.is_success_raw?(code)
  code >= 200 && code < 300
end

.mk_http_returnObject



15
16
17
18
19
20
21
22
# File 'lib/exobasic/http/json_http.rb', line 15

def self.mk_http_return
  {
    :http_return => 0,
    :warnings => [],
    :errors => [],
    :body => {}
  }
end

.mk_resultObject



52
53
54
55
56
57
58
59
# File 'lib/exobasic/http/json_http.rb', line 52

def self.mk_result
  {
    :success => true,
    :errors => [],
    :warnings => [],
    :body => {}
  }
end

.set_http_body(result, h) ⇒ Object



45
46
47
48
49
50
# File 'lib/exobasic/http/json_http.rb', line 45

def self.set_http_body(result, h)
  result[:http_return] = 200
  result[:body]        = h

  false
end

.set_result_body(result, h) ⇒ Object



82
83
84
85
86
87
# File 'lib/exobasic/http/json_http.rb', line 82

def self.set_result_body(result, h)
  result[:success] = true
  result[:body]    = h

  false
end