-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
133 additions
and
0 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
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,39 @@ | ||
module RSpreedly | ||
|
||
class Transaction < Base | ||
|
||
attr_accessor :active, | ||
:amount, | ||
:created_at, | ||
:currency_code, | ||
:description, | ||
:detail_type, | ||
:expires, | ||
:id, | ||
:invoice_id, | ||
:start_time, | ||
:terms, | ||
:updated_at, | ||
:price, | ||
:subscriber_customer_id, | ||
:detail | ||
|
||
class << self | ||
|
||
# Get a list of 50 transactions | ||
# Passing :since => id will get the 50 transactions since that one | ||
# GET /api/v4/[short site name]/transactions.xml | ||
def all(opts={}) | ||
query_opts = {} | ||
if opts[:since] | ||
query_opts[:query] = {:since_id => opts[:since]} | ||
end | ||
|
||
response = api_request(:get, "/transactions.xml", query_opts) | ||
return [] unless response.has_key?("transactions") | ||
response["transactions"].collect{|data| Transaction.new(data)} | ||
end | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<nil-classes type="array"/> |
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,63 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<transactions type="array"> | ||
<transaction> | ||
<amount type="decimal">24.0</amount> | ||
<created-at type="datetime">2009-09-26T03:06:30Z</created-at> | ||
<currency-code>USD</currency-code> | ||
<description>Subscription</description> | ||
<detail-type>Subscription</detail-type> | ||
<expires-at type="datetime">2009-12-26T04:06:30Z</expires-at> | ||
<id type="integer">20</id> | ||
<invoice-id type="integer">64</invoice-id> | ||
<start-time type="datetime">2009-09-26T03:06:30Z</start-time> | ||
<terms>3 months</terms> | ||
<updated-at type="datetime">2009-09-26T03:06:30Z</updated-at> | ||
<price>$24.00</price> | ||
<subscriber-customer-id>39053</subscriber-customer-id> | ||
<detail> | ||
<payment-method>visa</payment-method> | ||
<recurring type="boolean">false</recurring> | ||
<feature-level type="string">example</feature-level> | ||
</detail> | ||
</transaction> | ||
<transaction> | ||
<amount type="decimal">24.0</amount> | ||
<created-at type="datetime">2009-09-26T03:06:30Z</created-at> | ||
<currency-code>USD</currency-code> | ||
<description>Subscription</description> | ||
<detail-type>Subscription</detail-type> | ||
<expires-at type="datetime">2009-12-26T04:06:30Z</expires-at> | ||
<id type="integer">20</id> | ||
<invoice-id type="integer">64</invoice-id> | ||
<start-time type="datetime">2009-09-26T03:06:30Z</start-time> | ||
<terms>3 months</terms> | ||
<updated-at type="datetime">2009-09-26T03:06:30Z</updated-at> | ||
<price>$24.00</price> | ||
<subscriber-customer-id>39053</subscriber-customer-id> | ||
<detail> | ||
<payment-method>visa</payment-method> | ||
<recurring type="boolean">false</recurring> | ||
<feature-level type="string">example</feature-level> | ||
</detail> | ||
</transaction> | ||
<transaction> | ||
<amount type="decimal">24.0</amount> | ||
<created-at type="datetime">2009-09-26T03:06:30Z</created-at> | ||
<currency-code>USD</currency-code> | ||
<description>Subscription</description> | ||
<detail-type>Subscription</detail-type> | ||
<expires-at type="datetime">2009-12-26T04:06:30Z</expires-at> | ||
<id type="integer">20</id> | ||
<invoice-id type="integer">64</invoice-id> | ||
<start-time type="datetime">2009-09-26T03:06:30Z</start-time> | ||
<terms>3 months</terms> | ||
<updated-at type="datetime">2009-09-26T03:06:30Z</updated-at> | ||
<price>$24.00</price> | ||
<subscriber-customer-id>39053</subscriber-customer-id> | ||
<detail> | ||
<payment-method>visa</payment-method> | ||
<recurring type="boolean">false</recurring> | ||
<feature-level type="string">example</feature-level> | ||
</detail> | ||
</transaction> | ||
</transactions> |
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,28 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/spec_helper') | ||
describe RSpreedly::Transaction do | ||
|
||
describe ".all" do | ||
it "should return an empty array if there are no transactions" do | ||
stub_request(:get, spreedly_url("/transactions.xml")). | ||
to_return(:body => fixture("no_transactions.xml"), :status => 200) | ||
|
||
RSpreedly::Transaction.all.should == [] | ||
end | ||
|
||
it "should return an array of transactions if there are any to find" do | ||
stub_request(:get, spreedly_url("/transactions.xml")). | ||
to_return(:body => fixture("transactions.xml"), :status => 200) | ||
|
||
RSpreedly::Transaction.all.size.should == 3 # there are 3 in the fixture | ||
RSpreedly::Transaction.all.select{|x| x.is_a?(RSpreedly::Transaction )}.size.should == 3 | ||
end | ||
|
||
it "should allow specifying the ID of the transaction to start (since_id)" do | ||
stub_request(:get, spreedly_url("/transactions.xml?since_id=123")). | ||
to_return(:body => fixture("transactions.xml"), :status => 200) | ||
|
||
RSpreedly::Transaction.all(:since => 123) | ||
WebMock.should have_requested(:get, spreedly_url("/transactions.xml?since_id=123")) | ||
end | ||
end | ||
end |