-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Catch up with API capabilities by adding new objects (coupons, letter…
…s, notes, tasks, tax rates, text messages) and endpoints (voids, subscription previews, invoice consolidation, performing charges) (#14)
- Loading branch information
1 parent
8c2fe4c
commit 60b1cb1
Showing
24 changed files
with
707 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
Gemfile.lock | ||
example.rb | ||
/invoiced-*.gem | ||
/coverage | ||
/coverage | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module Invoiced | ||
class Coupon < Object | ||
include Invoiced::Operations::List | ||
include Invoiced::Operations::Create | ||
include Invoiced::Operations::Update | ||
include Invoiced::Operations::Delete | ||
|
||
OBJECT_NAME = 'coupon' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Invoiced | ||
class Letter < Object | ||
OBJECT_NAME = 'letter' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module Invoiced | ||
class Note < Object | ||
include Invoiced::Operations::List | ||
include Invoiced::Operations::Create | ||
include Invoiced::Operations::Update | ||
include Invoiced::Operations::Delete | ||
|
||
OBJECT_NAME = 'note' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module Invoiced | ||
class Task < Object | ||
include Invoiced::Operations::List | ||
include Invoiced::Operations::Create | ||
include Invoiced::Operations::Update | ||
include Invoiced::Operations::Delete | ||
|
||
OBJECT_NAME = 'task' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module Invoiced | ||
class TaxRate < Object | ||
include Invoiced::Operations::List | ||
include Invoiced::Operations::Create | ||
include Invoiced::Operations::Update | ||
include Invoiced::Operations::Delete | ||
|
||
OBJECT_NAME = 'tax_rate' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Invoiced | ||
class TextMessage < Object | ||
OBJECT_NAME = 'text_message' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
require File.expand_path('../../test_helper', __FILE__) | ||
|
||
module Invoiced | ||
class CouponTest < Test::Unit::TestCase | ||
should "return the api endpoint" do | ||
coupon = Coupon.new(@client, "test") | ||
assert_equal('/coupons/test', coupon.endpoint()) | ||
end | ||
|
||
should "create a coupon" do | ||
mockResponse = mock('RestClient::Response') | ||
mockResponse.stubs(:code).returns(201) | ||
mockResponse.stubs(:body).returns('{"id":"test","name":"Test Coupon"}') | ||
mockResponse.stubs(:headers).returns({}) | ||
|
||
RestClient::Request.any_instance.expects(:execute).returns(mockResponse) | ||
|
||
coupon = @client.Coupon.create({:name => "Test Coupon"}) | ||
|
||
assert_instance_of(Invoiced::Coupon, coupon) | ||
assert_equal("test", coupon.id) | ||
assert_equal('Test Coupon', coupon.name) | ||
end | ||
|
||
should "retrieve a coupon" do | ||
mockResponse = mock('RestClient::Response') | ||
mockResponse.stubs(:code).returns(200) | ||
mockResponse.stubs(:body).returns('{"id":"test","name":"Test Coupon"}') | ||
mockResponse.stubs(:headers).returns({}) | ||
|
||
RestClient::Request.any_instance.expects(:execute).returns(mockResponse) | ||
|
||
coupon = @client.Coupon.retrieve("test") | ||
|
||
assert_instance_of(Invoiced::Coupon, coupon) | ||
assert_equal("test", coupon.id) | ||
assert_equal('Test Coupon', coupon.name) | ||
end | ||
|
||
should "not update a coupon when no params" do | ||
coupon = Coupon.new(@client, "test") | ||
assert_false(coupon.save) | ||
end | ||
|
||
should "update a coupon" do | ||
mockResponse = mock('RestClient::Response') | ||
mockResponse.stubs(:code).returns(200) | ||
mockResponse.stubs(:body).returns('{"id":"test","name":"Testing Coupon"}') | ||
mockResponse.stubs(:headers).returns({}) | ||
|
||
RestClient::Request.any_instance.expects(:execute).returns(mockResponse) | ||
|
||
coupon = Coupon.new(@client, "test") | ||
coupon.name = "Testing Coupon" | ||
assert_true(coupon.save) | ||
|
||
assert_equal(coupon.name, "Testing Coupon") | ||
end | ||
|
||
should "list all coupons" do | ||
mockResponse = mock('RestClient::Response') | ||
mockResponse.stubs(:code).returns(200) | ||
mockResponse.stubs(:body).returns('[{"id":"test","name":"Test Coupon"}]') | ||
mockResponse.stubs(:headers).returns(:x_total_count => 15, :link => '<https://api.invoiced.com/catalog_items?per_page=25&page=1>; rel="self", <https://api.invoiced.com/catalog_items?per_page=25&page=1>; rel="first", <https://api.invoiced.com/catalog_items?per_page=25&page=1>; rel="last"') | ||
|
||
RestClient::Request.any_instance.expects(:execute).returns(mockResponse) | ||
|
||
coupons, metadata = @client.Coupon.list | ||
|
||
assert_instance_of(Array, coupons) | ||
assert_equal(1, coupons.length) | ||
assert_equal("test", coupons[0].id) | ||
|
||
assert_instance_of(Invoiced::List, metadata) | ||
assert_equal(15, metadata.total_count) | ||
end | ||
|
||
should "delete a coupon" do | ||
mockResponse = mock('RestClient::Response') | ||
mockResponse.stubs(:code).returns(204) | ||
mockResponse.stubs(:body).returns('') | ||
mockResponse.stubs(:headers).returns({}) | ||
|
||
RestClient::Request.any_instance.expects(:execute).returns(mockResponse) | ||
|
||
coupon = Coupon.new(@client, "test") | ||
assert_true(coupon.delete) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.