| 1 | package Data::Riak::Request::StoreObject; | ||
| 2 | { | ||
| 3 | $Data::Riak::Request::StoreObject::VERSION = '2.0'; | ||
| 4 | } | ||
| 5 | |||
| 6 | use Moose; | ||
| 7 | use Data::Riak::Result::SingleObject; | ||
| 8 | use Data::Riak::Exception::ConditionFailed; | ||
| 9 | use Data::Riak::Exception::MultipleSiblingsAvailable; | ||
| 10 | use namespace::autoclean; | ||
| 11 | |||
| 12 | has value => ( | ||
| 13 | is => 'ro', | ||
| 14 | required => 1, | ||
| 15 | ); | ||
| 16 | |||
| 17 | has links => ( | ||
| 18 | is => 'ro', | ||
| 19 | isa => 'HTTP::Headers::ActionPack::LinkList', | ||
| 20 | required => 1, | ||
| 21 | ); | ||
| 22 | |||
| 23 | has return_body => ( | ||
| 24 | is => 'ro', | ||
| 25 | isa => 'Bool', | ||
| 26 | default => 0, | ||
| 27 | ); | ||
| 28 | |||
| 29 | has content_type => ( | ||
| 30 | is => 'ro', | ||
| 31 | isa => 'Str', | ||
| 32 | predicate => 'has_content_type', | ||
| 33 | ); | ||
| 34 | |||
| 35 | has indexes => ( | ||
| 36 | is => 'ro', | ||
| 37 | isa => 'ArrayRef', | ||
| 38 | predicate => 'has_indexes', | ||
| 39 | ); | ||
| 40 | |||
| 41 | sub as_http_request_args { | ||
| 42 | my ($self) = @_; | ||
| 43 | |||
| 44 | return { | ||
| 45 | method => 'PUT', | ||
| 46 | uri => sprintf('buckets/%s/keys/%s', $self->bucket_name, $self->key), | ||
| 47 | data => $self->value, | ||
| 48 | links => $self->links, | ||
| 49 | ($self->return_body ? | ||
| 50 | (query => { returnbody => 'true' }) | ||
| 51 | : ()), | ||
| 52 | ($self->has_content_type | ||
| 53 | ? (content_type => $self->content_type) : ()), | ||
| 54 | ($self->has_indexes | ||
| 55 | ? (indexes => $self->indexes) : ()), | ||
| 56 | headers => { | ||
| 57 | ($self->has_vector_clock | ||
| 58 | ? ('x-riak-vclock' => $self->vector_clock) : ()), | ||
| 59 | ($self->has_if_unmodified_since | ||
| 60 | ? ('if-unmodified-since' => $self->if_unmodified_since) : ()), | ||
| 61 | ($self->has_if_match | ||
| 62 | ? ('if-match' => $self->if_match) : ()), | ||
| 63 | }, | ||
| 64 | }; | ||
| 65 | } | ||
| 66 | |||
| 67 | sub _build_http_exception_classes { | ||
| 68 | return { | ||
| 69 | 300 => Data::Riak::Exception::MultipleSiblingsAvailable::, | ||
| 70 | 412 => Data::Riak::Exception::ConditionFailed::, | ||
| 71 | }; | ||
| 72 | } | ||
| 73 | |||
| 74 | with 'Data::Riak::Request::WithObject', | ||
| 75 | 'Data::Riak::Request::WithHTTPExceptionHandling'; | ||
| 76 | |||
| 77 | has '+result_class' => ( | ||
| 78 | default => Data::Riak::Result::SingleObject::, | ||
| 79 | ); | ||
| 80 | |||
| 81 | __PACKAGE__->meta->make_immutable; | ||
| 82 | |||
| 83 | 1; | ||
| 84 | |||
| 85 | __END__ |