Class: Plamo::Response

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

Instance Method Summary collapse

Constructor Details

#initializeObject



25
26
27
28
# File 'ext/plamo/plamo_response.c', line 25

static VALUE initialize(VALUE self) {
  DATA_PTR(self) = plamo_response_new();
  return self;
}

Instance Method Details

#bodyObject



50
51
52
53
54
55
56
57
58
59
# File 'ext/plamo/plamo_response.c', line 50

static VALUE body(VALUE self) {
  PlamoResponse *plamo_response;
  TypedData_Get_Struct(self, PlamoResponse, &rb_plamo_response_type, plamo_response);
  if (plamo_response->body != NULL) {
    VALUE rb_plamo_byte_array = TypedData_Wrap_Struct(rb_cPlamoByteArray, &rb_plamo_byte_array_type, plamo_response->body);
    return rb_plamo_byte_array;
  } else {
    return Qnil;
  }
}

#body=(rb_body) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'ext/plamo/plamo_response.c', line 61

static VALUE set_body(VALUE self, VALUE rb_body) {
  PlamoResponse *plamo_response;
  TypedData_Get_Struct(self, PlamoResponse, &rb_plamo_response_type, plamo_response);
  if (strcmp("String", rb_class2name(rb_obj_class(rb_body))) == 0) {
    struct RString *rstring = RSTRING(rb_body);
    plamo_response->body = plamo_byte_array_new(RSTRING_PTR(rstring), RSTRING_LEN(rstring));
  } else {
    VALUE *array = RARRAY_PTR(rb_body);
    size_t len = RARRAY_LEN(rb_body);
    unsigned char *buf = malloc(sizeof(unsigned char) * len);
    for (size_t i = 0; i < len; i++) {
      buf[i] = NUM2CHR(array[i]);
    }
    plamo_response->body = plamo_byte_array_new(buf, len);
    free(array);
  }
  return self;
}

#headerObject



43
44
45
46
47
48
# File 'ext/plamo/plamo_response.c', line 43

static VALUE header(VALUE self) {
  PlamoResponse *plamo_response;
  TypedData_Get_Struct(self, PlamoResponse, &rb_plamo_response_type, plamo_response);
  VALUE rb_plamo_http_header = TypedData_Wrap_Struct(rb_cPlamoHttpHeader, &rb_plamo_http_header_type, plamo_response->header);
  return rb_plamo_http_header;
}

#status_codeObject



30
31
32
33
34
# File 'ext/plamo/plamo_response.c', line 30

static VALUE status_code(VALUE self) {
  PlamoResponse *plamo_response;
  TypedData_Get_Struct(self, PlamoResponse, &rb_plamo_response_type, plamo_response);
  return UINT2NUM(plamo_response->status_code);
}

#status_code=(code) ⇒ Object



36
37
38
39
40
41
# File 'ext/plamo/plamo_response.c', line 36

static VALUE set_status_code(VALUE self, VALUE code) {
  PlamoResponse *plamo_response;
  TypedData_Get_Struct(self, PlamoResponse, &rb_plamo_response_type, plamo_response);
  plamo_response->status_code = FIX2UINT(code);
  return code;
}