fastspring-saasy 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.4.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "fastspring-saasy"
8
- s.version = "0.3.1"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Richard Patching"]
12
- s.date = "2011-11-11"
12
+ s.date = "2011-11-12"
13
13
  s.description = "Ruby lib for using the FastSpring (Saas) subscription management API"
14
14
  s.email = "richard@justaddpixels.com"
15
15
  s.extra_rdoc_files = [
@@ -28,12 +28,19 @@ Gem::Specification.new do |s|
28
28
  "fastspring-saasy.gemspec",
29
29
  "lib/fastspring-saasy.rb",
30
30
  "lib/fastspring-saasy/account.rb",
31
+ "lib/fastspring-saasy/address.rb",
32
+ "lib/fastspring-saasy/base.rb",
31
33
  "lib/fastspring-saasy/customer.rb",
32
34
  "lib/fastspring-saasy/error.rb",
35
+ "lib/fastspring-saasy/item.rb",
36
+ "lib/fastspring-saasy/order.rb",
37
+ "lib/fastspring-saasy/payment.rb",
33
38
  "lib/fastspring-saasy/subscription.rb",
34
39
  "spec/account_spec.rb",
35
40
  "spec/customer_spec.rb",
41
+ "spec/fixtures/basic_order.xml",
36
42
  "spec/fixtures/basic_subscription.xml",
43
+ "spec/order_spec.rb",
37
44
  "spec/spec_helper.rb",
38
45
  "spec/subscription_spec.rb"
39
46
  ]
@@ -1,6 +1,11 @@
1
1
  require 'httparty'
2
2
 
3
+ require_relative 'fastspring-saasy/base'
3
4
  require_relative 'fastspring-saasy/account'
4
5
  require_relative 'fastspring-saasy/subscription'
5
6
  require_relative 'fastspring-saasy/customer'
7
+ require_relative 'fastspring-saasy/order'
8
+ require_relative 'fastspring-saasy/item'
9
+ require_relative 'fastspring-saasy/payment'
10
+ require_relative 'fastspring-saasy/address'
6
11
  require_relative 'fastspring-saasy/error'
@@ -0,0 +1,16 @@
1
+ module FastSpring
2
+ class Address
3
+ attr_reader :address_line_1, :address_line_2, :city, :region,
4
+ :region_custom, :postal_code, :country
5
+
6
+ def initialize(options)
7
+ @address_line_1 = options.fetch('addressLine1')
8
+ @address_line_2 = options.fetch('addressLine2')
9
+ @city = options.fetch('city')
10
+ @region = options.fetch('region')
11
+ @region_custom = options.fetch('regionCustom')
12
+ @postal_code = options.fetch('postalCode')
13
+ @country = options.fetch('country')
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,58 @@
1
+ module FastSpring
2
+ class Base
3
+ include HTTParty
4
+ base_uri 'https://api.fastspring.com'
5
+ format :xml
6
+ #debug_output
7
+
8
+ attr_reader :customer
9
+
10
+ def initialize(reference)
11
+ @auth = {:username => FastSpring::Account.fetch(:username),
12
+ :password => FastSpring::Account.fetch(:password)}
13
+ @company = FastSpring::Account.fetch(:company)
14
+ @reference = reference
15
+ end
16
+
17
+ def self.find(reference)
18
+ self.new(reference).find
19
+ end
20
+
21
+ # Returns the current status
22
+ def status
23
+ value_for('status')
24
+ end
25
+
26
+ # When the status was last changed
27
+ def status_changed
28
+ DateTime.parse(value_for('statusChanged'))
29
+ end
30
+
31
+ def referrer
32
+ value_for('referrer')
33
+ end
34
+
35
+ def source_name
36
+ value_for('sourceName')
37
+ end
38
+
39
+ def source_key
40
+ value_for('sourceKey')
41
+ end
42
+
43
+ def source_campaign
44
+ value_for('sourceCampaign')
45
+ end
46
+
47
+ # Returns a customer object
48
+ def customer
49
+ @customer ||= Customer.new(value_for('customer'))
50
+ end
51
+
52
+ private
53
+ def value_for(attribute)
54
+ parsed_response.fetch(attribute)
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,11 @@
1
+ module FastSpring
2
+ class Item
3
+ attr_reader :product_display, :product_name, :quantity, :subscription_reference
4
+ def initialize(details)
5
+ @product_display = details.fetch('productDisplay')
6
+ @product_name = details.fetch('productName')
7
+ @quantity = details.fetch('quantity')
8
+ @subscription_reference = details.fetch('subscriptionReference')
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,76 @@
1
+ module FastSpring
2
+ class Order < Base
3
+ attr_reader :purchaser, :items
4
+ # Get the order from Saasy
5
+ def find
6
+ @response = self.class.get(base_order_path, :basic_auth => @auth)
7
+ self
8
+ end
9
+
10
+ def base_order_path
11
+ "/company/#{@company}/order/#{@reference}"
12
+ end
13
+
14
+ def items
15
+ @items ||= [Item.new(parsed_response['orderItems']['orderItem'])]
16
+ end
17
+
18
+ def payments
19
+ @payments ||= [Payment.new(parsed_response['payments']['payment'])]
20
+ end
21
+
22
+ def payment
23
+ payments[0]
24
+ end
25
+
26
+ # Return the order reference
27
+ def reference
28
+ value_for('reference')
29
+ end
30
+
31
+ # Was the order a test?
32
+ def test?
33
+ value_for('test') == 'true'
34
+ end
35
+
36
+ # Returns a DateTime object
37
+ def due
38
+ DateTime.parse(value_for('due'))
39
+ end
40
+
41
+ def currency
42
+ value_for('currency')
43
+ end
44
+
45
+ def origin_ip
46
+ value_for('originIp')
47
+ end
48
+
49
+ def purchaser
50
+ @purchaser ||= Customer.new(value_for('customer'))
51
+ end
52
+
53
+ def total
54
+ value_for('total').to_f
55
+ end
56
+
57
+ def tax
58
+ value_for('tax').to_f
59
+ end
60
+
61
+ def shipping
62
+ value_for('shipping').to_f
63
+ end
64
+
65
+ def address
66
+ @address ||= Address.new(value_for('address'))
67
+ end
68
+
69
+ private
70
+
71
+ def parsed_response
72
+ @response.parsed_response['order']
73
+ end
74
+
75
+ end
76
+ end
@@ -0,0 +1,14 @@
1
+ module FastSpring
2
+ class Payment
3
+ attr_reader :status, :status_changed, :method_type, :declined_reason,
4
+ :currency, :total
5
+
6
+ def initialize(details)
7
+ @status = details.fetch('status')
8
+ @status_changed = Date.parse(details.fetch('statusChanged'))
9
+ @declined_reason = details.fetch('declinedReason')
10
+ @currency = details.fetch('currency')
11
+ @total = details.fetch('total').to_f
12
+ end
13
+ end
14
+ end
@@ -1,26 +1,12 @@
1
1
  require 'date'
2
2
 
3
3
  module FastSpring
4
- class Subscription
5
- include HTTParty
6
- base_uri 'https://api.fastspring.com'
7
- format :xml
8
- #debug_output
9
-
10
- attr_reader :customer
4
+ class Subscription < Base
11
5
 
12
6
  # Get the subscription from Saasy
13
- def initialize(reference)
14
- @auth = {:username => FastSpring::Account.fetch(:username),
15
- :password => FastSpring::Account.fetch(:password)}
16
- @company = FastSpring::Account.fetch(:company)
17
- @reference = reference
7
+ def find
18
8
  @response = self.class.get(base_subscription_path, :basic_auth => @auth)
19
- end
20
-
21
- # Find a subscription by reference
22
- def self.find(reference)
23
- self.new(reference)
9
+ self
24
10
  end
25
11
 
26
12
  # Returns the base path for a subscription
@@ -28,16 +14,6 @@ module FastSpring
28
14
  "/company/#{@company}/subscription/#{@reference}"
29
15
  end
30
16
 
31
- # Subscription status
32
- def status
33
- value_for('status')
34
- end
35
-
36
- # When the status was last changed
37
- def status_changed
38
- DateTime.parse(value_for('statusChanged'))
39
- end
40
-
41
17
  # The reason for a status change
42
18
  def status_reason
43
19
  value_for('statusReason')
@@ -53,22 +29,6 @@ module FastSpring
53
29
  value_for('cancelable') == 'true'
54
30
  end
55
31
 
56
- def referrer
57
- value_for('referrer')
58
- end
59
-
60
- def source_name
61
- value_for('sourceName')
62
- end
63
-
64
- def source_key
65
- value_for('sourceKey')
66
- end
67
-
68
- def source_campaign
69
- value_for('sourceCampaign')
70
- end
71
-
72
32
  # Subscription product name
73
33
  def product_name
74
34
  value_for('productName')
@@ -83,11 +43,6 @@ module FastSpring
83
43
  Date.parse(value_for('end'))
84
44
  end
85
45
 
86
- # Returns a customer object
87
- def customer
88
- @customer ||= Customer.new(value_for('customer'))
89
- end
90
-
91
46
  # Cancel the subscription
92
47
  def destroy
93
48
  self.class.delete(base_subscription_path, :basic_auth => @auth)
@@ -108,10 +63,6 @@ module FastSpring
108
63
  @response.parsed_response['subscription']
109
64
  end
110
65
 
111
- def value_for(attribute)
112
- parsed_response.fetch(attribute)
113
- end
114
-
115
66
  end
116
67
  end
117
68
 
@@ -0,0 +1,57 @@
1
+ <order>
2
+ <reference>TEST-0RD3R</reference>
3
+ <status>completed</status>
4
+ <statusChanged>2010-08-15T00:00:00.000Z</statusChanged>
5
+ <test>false</test>
6
+ <due>2010-08-15T00:00:00.000Z</due>
7
+ <currency>GBP</currency>
8
+ <referrer>acme_web</referrer>
9
+ <originIp>123.456.789.0</originIp>
10
+ <total>10.00</total>
11
+ <tax>1.00</tax>
12
+ <shipping>0.0</shipping>
13
+ <sourceName/>
14
+ <sourceKey/>
15
+ <sourceCampaign/>
16
+ <customer>
17
+ <firstName/>
18
+ <lastName/>
19
+ <company/>
20
+ <email/>
21
+ <phoneNumber/>
22
+ </customer>
23
+ <purchaser>
24
+ <firstName/>
25
+ <lastName/>
26
+ <company/>
27
+ <email/>
28
+ <phoneNumber/>
29
+ </purchaser>
30
+ <address>
31
+ <addressLine1/>
32
+ <addressLine2/>
33
+ <city/>
34
+ <region/>
35
+ <regionCustom/>
36
+ <postalCode/>
37
+ <country/>
38
+ </address>
39
+ <orderItems>
40
+ <orderItem>
41
+ <productDisplay/>
42
+ <productName/>
43
+ <quantity>0</quantity>
44
+ <subscriptionReference/>
45
+ </orderItem>
46
+ </orderItems>
47
+ <payments>
48
+ <payment>
49
+ <status>open | request | requested | acceptance | accepted | fulfillment | fulfilled | completion | completed | canceled | failed</status>
50
+ <statusChanged>2010-08-15T00:00:00.000Z</statusChanged>
51
+ <methodType>paypal | creditcard | test | check | purchase-order | free</methodType>
52
+ <declinedReason>internal-error | unsupported-country | expired-card | declined | risk | processor-risk | connection | unknown | cc-address-verification | cc-cvv | voice-auth</declinedReason>
53
+ <currency/>
54
+ <total>0.0</total>
55
+ </payment>
56
+ </payments>
57
+ </order>
@@ -0,0 +1,105 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '../lib/fastspring-saasy.rb'))
2
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper.rb'))
3
+
4
+ describe FastSpring::Order do
5
+ before do
6
+ FastSpring::Account.setup do |config|
7
+ config[:username] = 'admin'
8
+ config[:password] = 'test'
9
+ config[:company] = 'acme'
10
+ end
11
+ end
12
+
13
+ context 'url for orders' do
14
+ subject { FastSpring::Order.find('test_ref') }
15
+ before do
16
+ stub_request(:get, "https://admin:test@api.fastspring.com/company/acme/order/test_ref").
17
+ to_return(:status => 200, :body => "", :headers => {})
18
+ end
19
+
20
+ it 'returns the path for the company and reference' do
21
+ subject.base_order_path.should == "/company/acme/order/test_ref"
22
+ end
23
+ end
24
+
25
+ context 'order details' do
26
+ subject { FastSpring::Order.find('test_ref') }
27
+ let(:customer) { mock(:customer) }
28
+ let(:address) { mock(:address) }
29
+ let(:item) { mock(:item) }
30
+ let(:payment) { mock(:payment) }
31
+
32
+ before do
33
+ stub_request(:get, "https://admin:test@api.fastspring.com/company/acme/order/test_ref").
34
+ to_return(stub_http_response_with('basic_order.xml'))
35
+ FastSpring::Customer.stub(:new => customer)
36
+ FastSpring::Address.stub(:new => address)
37
+ FastSpring::Item.stub(:new => item)
38
+ FastSpring::Payment.stub(:new => payment)
39
+ end
40
+
41
+ it 'returns the status' do
42
+ subject.status.should == 'completed'
43
+ end
44
+
45
+ it 'returns when the status was changed' do
46
+ subject.status_changed.should be_an_instance_of(DateTime)
47
+ end
48
+
49
+ it 'returns the order reference' do
50
+ subject.reference.should == 'TEST-0RD3R'
51
+ end
52
+
53
+ it 'returns the test status' do
54
+ subject.test?.should be_false
55
+ end
56
+
57
+ it 'returns the due date' do
58
+ subject.due.should be_an_instance_of(DateTime)
59
+ end
60
+
61
+ it 'returns the currency code' do
62
+ subject.currency.should == 'GBP'
63
+ end
64
+
65
+ it 'returns the referrer' do
66
+ subject.referrer.should == 'acme_web'
67
+ end
68
+
69
+ it 'returns the origin ip' do
70
+ subject.origin_ip.should == '123.456.789.0'
71
+ end
72
+
73
+ it 'returns the purchaser' do
74
+ subject.purchaser.should == customer
75
+ end
76
+
77
+ it 'returns the total' do
78
+ subject.total.should == 10.00
79
+ end
80
+
81
+ it 'returns the tax' do
82
+ subject.tax.should == 1.00
83
+ end
84
+
85
+ it 'returns the shipping' do
86
+ subject.shipping.should == 0.0
87
+ end
88
+
89
+ it 'returns the address' do
90
+ subject.address.should == address
91
+ end
92
+
93
+ context 'items' do
94
+ it 'has an order item' do
95
+ subject.items.should == [item]
96
+ end
97
+ end
98
+
99
+ it 'has a payment' do
100
+ subject.payment.should == payment
101
+ end
102
+
103
+ end
104
+
105
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastspring-saasy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-11 00:00:00.000000000Z
12
+ date: 2011-11-12 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
16
- requirement: &70301329265660 !ruby/object:Gem::Requirement
16
+ requirement: &70174611931540 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70301329265660
24
+ version_requirements: *70174611931540
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &70301329263260 !ruby/object:Gem::Requirement
27
+ requirement: &70174612187520 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70301329263260
35
+ version_requirements: *70174612187520
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &70301329261120 !ruby/object:Gem::Requirement
38
+ requirement: &70174612371500 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70301329261120
46
+ version_requirements: *70174612371500
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &70301329258540 !ruby/object:Gem::Requirement
49
+ requirement: &70174615205380 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70301329258540
57
+ version_requirements: *70174615205380
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: httparty
60
- requirement: &70301329256600 !ruby/object:Gem::Requirement
60
+ requirement: &70174615396940 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: 0.8.1
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70301329256600
68
+ version_requirements: *70174615396940
69
69
  description: Ruby lib for using the FastSpring (Saas) subscription management API
70
70
  email: richard@justaddpixels.com
71
71
  executables: []
@@ -85,12 +85,19 @@ files:
85
85
  - fastspring-saasy.gemspec
86
86
  - lib/fastspring-saasy.rb
87
87
  - lib/fastspring-saasy/account.rb
88
+ - lib/fastspring-saasy/address.rb
89
+ - lib/fastspring-saasy/base.rb
88
90
  - lib/fastspring-saasy/customer.rb
89
91
  - lib/fastspring-saasy/error.rb
92
+ - lib/fastspring-saasy/item.rb
93
+ - lib/fastspring-saasy/order.rb
94
+ - lib/fastspring-saasy/payment.rb
90
95
  - lib/fastspring-saasy/subscription.rb
91
96
  - spec/account_spec.rb
92
97
  - spec/customer_spec.rb
98
+ - spec/fixtures/basic_order.xml
93
99
  - spec/fixtures/basic_subscription.xml
100
+ - spec/order_spec.rb
94
101
  - spec/spec_helper.rb
95
102
  - spec/subscription_spec.rb
96
103
  homepage: http://github.com/patchfx/fastspring
@@ -108,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
115
  version: '0'
109
116
  segments:
110
117
  - 0
111
- hash: 4459669591776827499
118
+ hash: -4339639904534215693
112
119
  required_rubygems_version: !ruby/object:Gem::Requirement
113
120
  none: false
114
121
  requirements: