From f1cf5426e907db5c4d80347a5b9c34584d5da45f Mon Sep 17 00:00:00 2001 From: mattsprig Date: Fri, 19 May 2017 16:05:15 -0700 Subject: [PATCH] Support add tip endpoint --- README.md | 12 ++++++++++-- lib/postmates/client.rb | 12 +++++++++++- spec/client_spec.rb | 22 +++++++++++++++++++++- spec/fixtures/add_tip_params.json | 3 +++ 4 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 spec/fixtures/add_tip_params.json diff --git a/README.md b/README.md index 7737380..dbd00ea 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,15 @@ Cancel an ongoing delivery prior to pickup. Returns a `Postmates::Delivery` obje Cancel an ongoing delivery that was already picked up and create a delivery that is a reverse of the original. The items will get returned to the original pickup location. Returns a `Postmates::Delivery` object. ```ruby -@client.cancel('del_K9gEsDNuPJ-lLV') +@client.return('del_K9gEsDNuPJ-lLV') +``` + +#### POST /v1/customers/:customer_id/deliveries/:delivery_id + +Add a tip (in cents) to a delivery (after the delivery has been completed). Returns a `Postmates::Delivery` object. + +```ruby +@client.add_tip('del_K9gEsDNuPJ-lLV', tip_by_customer: 295) ``` ## Contributing @@ -134,4 +142,4 @@ Cancel an ongoing delivery that was already picked up and create a delivery that 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) -5. Create a new Pull Request \ No newline at end of file +5. Create a new Pull Request diff --git a/lib/postmates/client.rb b/lib/postmates/client.rb index 7d3cdb1..5d2c463 100644 --- a/lib/postmates/client.rb +++ b/lib/postmates/client.rb @@ -77,5 +77,15 @@ def cancel(delivery_id) def return(delivery_id) post("customers/#{customer_id}/deliveries/#{delivery_id}/return") end + + # POST /v1/customers/:customer_id/deliveries/:delivery_id + # + # tip_by_customer=495 + # + # Returns a Delivery object or the raw Faraday response + # if raw_response = true + def add_tip(delivery_id, options = {}) + post("customers/#{customer_id}/deliveries/#{delivery_id}", options) + end end -end \ No newline at end of file +end diff --git a/spec/client_spec.rb b/spec/client_spec.rb index ca7e186..1cef844 100644 --- a/spec/client_spec.rb +++ b/spec/client_spec.rb @@ -112,5 +112,25 @@ expect(client.return(delivery_id)).to be_a Postmates::Delivery end end + + describe '#add_tip' do + let(:delivery_id) { 'del_K9LFxVVbl5sac-' } + let(:path) { path_to "deliveries/#{delivery_id}" } + let(:params) { payload 'add_tip_params.json' } + before { stub_post path, returns: 'delivery.json' } + + it 'returns a single delivery by id' do + expect(client.add_tip(delivery_id, params).id).to eq 'del_K9LFxVVbl5sac-' + expect(client.add_tip(delivery_id, params).quote_id).to eq 'dqt_K9LFfpSZCdAJsk' + expect(client.add_tip(delivery_id, params).status).to eq 'pending' + expect(client.add_tip(delivery_id, params).manifest['description']) + .to eq 'a box of kittens' + expect(client.add_tip(delivery_id, params).delivered?).to be false + end + + it 'returns a Postmates::Delivery' do + expect(client.add_tip(delivery_id, params)).to be_a Postmates::Delivery + end + end end -end \ No newline at end of file +end diff --git a/spec/fixtures/add_tip_params.json b/spec/fixtures/add_tip_params.json new file mode 100644 index 0000000..0a48746 --- /dev/null +++ b/spec/fixtures/add_tip_params.json @@ -0,0 +1,3 @@ +{ + "tip_by_customer": 295 +}