Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
5. Create a new Pull Request
12 changes: 11 additions & 1 deletion lib/postmates/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
end
22 changes: 21 additions & 1 deletion spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
end
3 changes: 3 additions & 0 deletions spec/fixtures/add_tip_params.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"tip_by_customer": 295
}