Class: Plamo::Request

Inherits:
Object
  • Object
show all
Defined in:
ext/plamo/plamo_request.c

Instance Method Summary collapse

Constructor Details

#initialize(rb_scheme, rb_version, rb_method, rb_path, rb_query, rb_header, rb_body) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'ext/plamo/plamo_request.c', line 27

static VALUE initialize(VALUE self, VALUE rb_scheme, VALUE rb_version, VALUE rb_method, VALUE rb_path, VALUE rb_query, VALUE rb_header, VALUE rb_body) {
  const PlamoScheme scheme = sym_http == rb_scheme ? PlamoSchemeHttp : PlamoSchemeHttps;
  const PlamoHttpVersion version = sym_http_2_0 == rb_version ? PlamoHttpVersionHttp20
                                 : sym_http_1_1 == rb_version ? PlamoHttpVersionHttp11
                                 : sym_http_1_0 == rb_version ? PlamoHttpVersionHttp10
                                 : PlamoHttpVersionHttp09;
  PlamoHttpMethod method;
  if (RB_TYPE_P(rb_method, RUBY_T_FIXNUM)) {
    method.defined_http_method = NUM2SIZET(rb_method);
  } else {
    method.undefined_http_method = StringValueCStr(rb_method);
  }
  const char *path = StringValueCStr(rb_path);
  PlamoHttpQuery *plamo_http_query;
  TypedData_Get_Struct(rb_query, PlamoHttpQuery, &rb_plamo_http_query_type, plamo_http_query);
  PlamoHttpHeader *plamo_http_header;
  TypedData_Get_Struct(rb_header, PlamoHttpHeader, &rb_plamo_http_header_type, plamo_http_header);
  PlamoByteArray *plamo_byte_array;
  TypedData_Get_Struct(rb_body, PlamoByteArray, &rb_plamo_byte_array_type, plamo_byte_array);
  DATA_PTR(self) = plamo_request_new(scheme, version, method, path, plamo_http_query, plamo_http_header, plamo_byte_array);
  return self;
}

Instance Method Details

#bodyObject



118
119
120
121
122
123
# File 'ext/plamo/plamo_request.c', line 118

static VALUE body(VALUE self) {
  PlamoRequest *plamo_request;
  TypedData_Get_Struct(self, PlamoRequest, &rb_plamo_request_type, plamo_request);
  VALUE rb_plamo_byte_array = TypedData_Wrap_Struct(rb_cPlamoByteArray, &rb_plamo_byte_array_type, plamo_request->body);
  return rb_plamo_byte_array;
}

#headerObject



111
112
113
114
115
116
# File 'ext/plamo/plamo_request.c', line 111

static VALUE header(VALUE self) {
  PlamoRequest *plamo_request;
  TypedData_Get_Struct(self, PlamoRequest, &rb_plamo_request_type, plamo_request);
  VALUE rb_plamo_http_header = TypedData_Wrap_Struct(rb_cPlamoHttpHeader, &rb_plamo_http_header_type, plamo_request->header);
  return rb_plamo_http_header;
}

#methodObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'ext/plamo/plamo_request.c', line 71

static VALUE method(VALUE self) {
  PlamoRequest *plamo_request;
  TypedData_Get_Struct(self, PlamoRequest, &rb_plamo_request_type, plamo_request);
  PlamoDefinedHttpMethod method = plamo_request->method.defined_http_method;
  if (method == PLAMO_HTTP_METHOD_GET) {
    return rb_str_new2("GET");
  } else if (method == PLAMO_HTTP_METHOD_POST) {
    return rb_str_new2("POST");
  } else if (method == PLAMO_HTTP_METHOD_PUT) {
    return rb_str_new2("PUT");
  } else if (method == PLAMO_HTTP_METHOD_DELETE) {
    return rb_str_new2("DELETE");
  } else if (method == PLAMO_HTTP_METHOD_HEAD) {
    return rb_str_new2("HEAD");
  } else if (method == PLAMO_HTTP_METHOD_CONNECT) {
    return rb_str_new2("CONNECT");
  } else if (method == PLAMO_HTTP_METHOD_OPTIONS) {
    return rb_str_new2("OPTIONS");
  } else if (method == PLAMO_HTTP_METHOD_TRACE) {
    return rb_str_new2("TRACE");
  } else if (method == PLAMO_HTTP_METHOD_PATCH) {
    return rb_str_new2("PATCH");
  } else {
    return rb_str_new2(plamo_request->method.undefined_http_method);
  }
}

#pathObject



98
99
100
101
102
# File 'ext/plamo/plamo_request.c', line 98

static VALUE path(VALUE self) {
  PlamoRequest *plamo_request;
  TypedData_Get_Struct(self, PlamoRequest, &rb_plamo_request_type, plamo_request);
  return rb_str_new2(plamo_string_get_char(plamo_request->path));
}

#queryObject



104
105
106
107
108
109
# File 'ext/plamo/plamo_request.c', line 104

static VALUE query(VALUE self) {
  PlamoRequest *plamo_request;
  TypedData_Get_Struct(self, PlamoRequest, &rb_plamo_request_type, plamo_request);
  VALUE rb_plamo_http_query = TypedData_Wrap_Struct(rb_cPlamoHttpQuery, &rb_plamo_http_query_type, plamo_request->query);
  return rb_plamo_http_query;
}

#schemeObject



50
51
52
53
54
# File 'ext/plamo/plamo_request.c', line 50

static VALUE scheme(VALUE self) {
  PlamoRequest *plamo_request;
  TypedData_Get_Struct(self, PlamoRequest, &rb_plamo_request_type, plamo_request);
  return plamo_request->scheme == PlamoSchemeHttp ? sym_http : sym_https;
}

#versionObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'ext/plamo/plamo_request.c', line 56

static VALUE version(VALUE self) {
  PlamoRequest *plamo_request;
  TypedData_Get_Struct(self, PlamoRequest, &rb_plamo_request_type, plamo_request);
  switch (plamo_request->version) {
    case PlamoHttpVersionHttp20:
      return sym_http_2_0;
    case PlamoHttpVersionHttp11:
      return sym_http_1_1;
    case PlamoHttpVersionHttp10:
      return sym_http_1_0;
    default:
      return sym_http_0_9;
  }
}