fastspring-saasy 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source :rubygems
2
+
3
+ gem 'httparty'
4
+ gem 'rake'
5
+
6
+ group :development do
7
+ gem 'bundler'
8
+ gem 'jeweler'
9
+ end
10
+
11
+ group :test do
12
+ gem 'rspec'
13
+ gem 'webmock'
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,39 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.2.6)
5
+ crack (0.3.1)
6
+ diff-lcs (1.1.3)
7
+ git (1.2.5)
8
+ httparty (0.8.1)
9
+ multi_json
10
+ multi_xml
11
+ jeweler (1.6.4)
12
+ bundler (~> 1.0)
13
+ git (>= 1.2.5)
14
+ rake
15
+ multi_json (1.0.3)
16
+ multi_xml (0.4.1)
17
+ rake (0.9.2)
18
+ rspec (2.7.0)
19
+ rspec-core (~> 2.7.0)
20
+ rspec-expectations (~> 2.7.0)
21
+ rspec-mocks (~> 2.7.0)
22
+ rspec-core (2.7.0)
23
+ rspec-expectations (2.7.0)
24
+ diff-lcs (~> 1.1.2)
25
+ rspec-mocks (2.7.0)
26
+ webmock (1.7.7)
27
+ addressable (~> 2.2, > 2.2.5)
28
+ crack (>= 0.1.7)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ bundler
35
+ httparty
36
+ jeweler
37
+ rake
38
+ rspec
39
+ webmock
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Richard Patching
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,23 @@
1
+ = fastspring-saasy
2
+
3
+ Ruby library to access the FastSpring Saasy API.
4
+
5
+ == Installation
6
+
7
+ gem install fastspring-saasy
8
+
9
+ == Usage
10
+
11
+ require 'fastspring-saasy'
12
+ FastSpring::Subscription.new('company', 'reference', 'user', 'password')
13
+
14
+ == Todo
15
+
16
+ * Support update
17
+ * Support the order API
18
+
19
+ == Copyright
20
+
21
+ Copyright (c) 2011 Richard Patching. See LICENSE.txt for
22
+ further details.
23
+
data/Rakefile ADDED
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ gem.name = "fastspring-saasy"
17
+ gem.homepage = "http://github.com/patchfx/fastspring"
18
+ gem.license = "MIT"
19
+ gem.summary = %Q{Ruby lib for using the FastSpring (Saasy) API}
20
+ gem.description = %Q{Ruby lib for using the FastSpring (Saas) subscription management API}
21
+ gem.email = "richard@justaddpixels.com"
22
+ gem.authors = ["Richard Patching"]
23
+ gem.add_development_dependency 'httparty', '~> 0.8.1'
24
+ end
25
+ Jeweler::RubygemsDotOrgTasks.new
26
+
27
+ require 'rake/rdoctask'
28
+ Rake::RDocTask.new do |rdoc|
29
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
30
+
31
+ rdoc.rdoc_dir = 'rdoc'
32
+ rdoc.title = "fastspring #{version}"
33
+ rdoc.rdoc_files.include('README*')
34
+ rdoc.rdoc_files.include('lib/**/*.rb')
35
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.3.0
@@ -0,0 +1,68 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "fastspring-saasy"
8
+ s.version = "0.3.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Richard Patching"]
12
+ s.date = "2011-11-10"
13
+ s.description = "Ruby lib for using the FastSpring (Saas) subscription management API"
14
+ s.email = "richard@justaddpixels.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "fastspring-saasy.gemspec",
29
+ "lib/fastspring-saasy.rb",
30
+ "lib/fastspring-saasy/customer.rb",
31
+ "lib/fastspring-saasy/error.rb",
32
+ "lib/fastspring-saasy/subscription.rb",
33
+ "spec/customer_spec.rb",
34
+ "spec/fixtures/basic_subscription.xml",
35
+ "spec/spec_helper.rb",
36
+ "spec/subscription_spec.rb"
37
+ ]
38
+ s.homepage = "http://github.com/patchfx/fastspring"
39
+ s.licenses = ["MIT"]
40
+ s.require_paths = ["lib"]
41
+ s.rubygems_version = "1.8.10"
42
+ s.summary = "Ruby lib for using the FastSpring (Saasy) API"
43
+
44
+ if s.respond_to? :specification_version then
45
+ s.specification_version = 3
46
+
47
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
+ s.add_runtime_dependency(%q<httparty>, [">= 0"])
49
+ s.add_runtime_dependency(%q<rake>, [">= 0"])
50
+ s.add_development_dependency(%q<bundler>, [">= 0"])
51
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
52
+ s.add_development_dependency(%q<httparty>, ["~> 0.8.1"])
53
+ else
54
+ s.add_dependency(%q<httparty>, [">= 0"])
55
+ s.add_dependency(%q<rake>, [">= 0"])
56
+ s.add_dependency(%q<bundler>, [">= 0"])
57
+ s.add_dependency(%q<jeweler>, [">= 0"])
58
+ s.add_dependency(%q<httparty>, ["~> 0.8.1"])
59
+ end
60
+ else
61
+ s.add_dependency(%q<httparty>, [">= 0"])
62
+ s.add_dependency(%q<rake>, [">= 0"])
63
+ s.add_dependency(%q<bundler>, [">= 0"])
64
+ s.add_dependency(%q<jeweler>, [">= 0"])
65
+ s.add_dependency(%q<httparty>, ["~> 0.8.1"])
66
+ end
67
+ end
68
+
@@ -0,0 +1,5 @@
1
+ require 'httparty'
2
+
3
+ require_relative 'fastspring-saasy/subscription'
4
+ require_relative 'fastspring-saasy/customer'
5
+ require_relative 'fastspring-saasy/error'
@@ -0,0 +1,14 @@
1
+ module FastSpring
2
+ class Customer
3
+ attr_accessor :first_name, :last_name, :company, :email, :phone_number
4
+
5
+ def initialize(details)
6
+ @first_name = details.fetch('firstName')
7
+ @last_name = details.fetch('lastName')
8
+ @company = details.fetch('company')
9
+ @email = details.fetch('email')
10
+ @phone_number = details.fetch('phoneNumber')
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ module FastSpring
2
+ module Error
3
+
4
+ class NotFound < StandardError
5
+ attr_reader :response
6
+
7
+ def initialize(response=nil)
8
+ @response = response
9
+ end
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,111 @@
1
+ require 'date'
2
+
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
11
+
12
+ # Get the subscription from Saasy
13
+ def initialize(company, reference, username, password)
14
+ @auth = {:username => username, :password => password}
15
+ @company = company
16
+ @reference = reference
17
+ @response = self.class.get(base_subscription_path, :basic_auth => @auth)
18
+ end
19
+
20
+ # Returns the base path for a subscription
21
+ def base_subscription_path
22
+ "/company/#{@company}/subscription/#{@reference}"
23
+ end
24
+
25
+ # Subscription status
26
+ def status
27
+ value_for('status')
28
+ end
29
+
30
+ # When the status was last changed
31
+ def status_changed
32
+ DateTime.parse(value_for('statusChanged'))
33
+ end
34
+
35
+ # The reason for a status change
36
+ def status_reason
37
+ value_for('statusReason')
38
+ end
39
+
40
+ # Is the subscription active?
41
+ def active?
42
+ status == 'active'
43
+ end
44
+
45
+ # Can the subscription be cancelled?
46
+ def cancelable?
47
+ value_for('cancelable') == 'true'
48
+ end
49
+
50
+ def referrer
51
+ value_for('referrer')
52
+ end
53
+
54
+ def source_name
55
+ value_for('sourceName')
56
+ end
57
+
58
+ def source_key
59
+ value_for('sourceKey')
60
+ end
61
+
62
+ def source_campaign
63
+ value_for('sourceCampaign')
64
+ end
65
+
66
+ # Subscription product name
67
+ def product_name
68
+ value_for('productName')
69
+ end
70
+
71
+ def next_period_date
72
+ Date.parse(value_for('nextPeriodDate'))
73
+ end
74
+
75
+ # The date the subscription ends on
76
+ def ends_on
77
+ Date.parse(value_for('end'))
78
+ end
79
+
80
+ # Returns a customer object
81
+ def customer
82
+ @customer ||= Customer.new(value_for('customer'))
83
+ end
84
+
85
+ # Cancel the subscription
86
+ def destroy
87
+ self.class.delete(base_subscription_path, :basic_auth => @auth)
88
+ end
89
+
90
+ def renew_path
91
+ "#{base_subscription_path}/renew"
92
+ end
93
+
94
+ # Renew the subscription
95
+ def renew
96
+ self.class.post(renew_path, :basic_auth => @auth)
97
+ end
98
+
99
+ private
100
+
101
+ def parsed_response
102
+ @response.parsed_response['subscription']
103
+ end
104
+
105
+ def value_for(attribute)
106
+ parsed_response.fetch(attribute)
107
+ end
108
+
109
+ end
110
+ end
111
+
@@ -0,0 +1,37 @@
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::Customer do
5
+ context 'new' do
6
+ let(:customer_details) {
7
+ {
8
+ "firstName" => "John",
9
+ "lastName" => "Doe",
10
+ "company" => "Doe Inc",
11
+ "email" => "john@example.com",
12
+ "phoneNumber" => "0123456789"
13
+ }
14
+ }
15
+ subject { FastSpring::Customer.new(customer_details) }
16
+
17
+ it 'has a first name' do
18
+ subject.first_name.should == 'John'
19
+ end
20
+
21
+ it 'has a last name' do
22
+ subject.last_name.should == 'Doe'
23
+ end
24
+
25
+ it 'has a company' do
26
+ subject.company.should == 'Doe Inc'
27
+ end
28
+
29
+ it 'has a email address' do
30
+ subject.email.should == 'john@example.com'
31
+ end
32
+
33
+ it 'has a phone number' do
34
+ subject.phone_number.should == '0123456789'
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,25 @@
1
+ <subscription>
2
+ <status>active</status>
3
+ <statusChanged>2010-08-15T00:00:00.000Z</statusChanged>
4
+ <statusReason>completed</statusReason>
5
+ <cancelable>true</cancelable>
6
+ <reference/>
7
+ <test>true</test>
8
+ <referrer>acme_app</referrer>
9
+ <sourceName>acme_source</sourceName>
10
+ <sourceKey>acme_source_key</sourceKey>
11
+ <sourceCampaign>acme_source_campaign</sourceCampaign>
12
+ <customer>
13
+ <firstName>John</firstName>
14
+ <lastName>Doe</lastName>
15
+ <company>Doe Inc</company>
16
+ <email>johndoe@example.com</email>
17
+ <phoneNumber>0123456789</phoneNumber>
18
+ </customer>
19
+ <customerUrl/>
20
+ <productName>Acme Inc Web</productName>
21
+ <tags/>
22
+ <quantity>0</quantity>
23
+ <nextPeriodDate>2010-08-15Z</nextPeriodDate>
24
+ <end>2010-08-15Z</end>
25
+ </subscription>
@@ -0,0 +1,35 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+ require "httparty"
3
+
4
+ require 'webmock/rspec'
5
+
6
+ def file_fixture(filename)
7
+ open(File.join(File.dirname(__FILE__), 'fixtures', "#{filename.to_s}")).read
8
+ end
9
+
10
+ def stub_http_response_with(filename)
11
+ format = filename.split('.').last.intern
12
+ data = file_fixture(filename)
13
+
14
+ response = Net::HTTPOK.new("1.1", 200, "Content for you")
15
+ response.stub!(:body).and_return(data)
16
+
17
+ http_request = HTTParty::Request.new(Net::HTTP::Get, 'http://localhost', :format => format)
18
+ http_request.stub_chain(:http, :request).and_return(response)
19
+
20
+ HTTParty::Request.should_receive(:new).and_return(http_request)
21
+ end
22
+
23
+ def stub_response(body, code = 200)
24
+ @request.options[:base_uri] ||= 'http://localhost'
25
+ unless defined?(@http) && @http
26
+ @http = Net::HTTP.new('localhost', 80)
27
+ @request.stub!(:http).and_return(@http)
28
+ end
29
+
30
+ response = Net::HTTPResponse::CODE_TO_OBJ[code.to_s].new("1.1", code, body)
31
+ response.stub!(:body).and_return(body)
32
+
33
+ @http.stub!(:request).and_return(response)
34
+ response
35
+ end
@@ -0,0 +1,92 @@
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::Subscription do
5
+ context 'url for subscriptions' do
6
+ subject { FastSpring::Subscription.new('acme', 'test_ref', 'admin', 'test') }
7
+ before do
8
+ stub_request(:get, "https://admin:test@api.fastspring.com/company/acme/subscription/test_ref").
9
+ to_return(:status => 200, :body => "", :headers => {})
10
+ end
11
+
12
+ it 'returns the path for the company and reference' do
13
+ subject.base_subscription_path.should == "/company/acme/subscription/test_ref"
14
+ end
15
+ end
16
+
17
+ context 'subscription details' do
18
+ subject { FastSpring::Subscription.new('acme', 'test_ref', 'admin', 'test') }
19
+ let(:customer) { mock(:customer) }
20
+ before do
21
+ stub_request(:get, "https://admin:test@api.fastspring.com/company/acme/subscription/test_ref").
22
+ to_return(stub_http_response_with('basic_subscription.xml'))
23
+ FastSpring::Customer.stub(:new => customer)
24
+ end
25
+
26
+ context 'when active' do
27
+ it 'returns the status' do
28
+ subject.status.should == 'active'
29
+ end
30
+
31
+ it 'returns the status changed date' do
32
+ subject.status_changed.should be_an_instance_of(DateTime)
33
+ end
34
+
35
+ it 'returns the reason for status change' do
36
+ subject.status_reason.should == 'completed'
37
+ end
38
+
39
+ it 'is active' do
40
+ subject.should be_active
41
+ end
42
+ end
43
+
44
+ it 'returns the cancelable state' do
45
+ subject.should be_cancelable
46
+ end
47
+
48
+ it 'returns the referrer' do
49
+ subject.referrer.should == 'acme_app'
50
+ end
51
+
52
+ it 'returns the source name' do
53
+ subject.source_name.should == 'acme_source'
54
+ end
55
+
56
+ it 'returns the source key' do
57
+ subject.source_key.should == 'acme_source_key'
58
+ end
59
+
60
+ it 'returns the source campaign' do
61
+ subject.source_campaign.should == 'acme_source_campaign'
62
+ end
63
+
64
+ it 'returns a customer' do
65
+ subject.customer.should == customer
66
+ end
67
+
68
+ it 'returns the product name' do
69
+ subject.product_name.should == 'Acme Inc Web'
70
+ end
71
+
72
+ it 'returns the next period date' do
73
+ subject.next_period_date.should be_an_instance_of(Date)
74
+ end
75
+
76
+ it 'returns the end date' do
77
+ subject.ends_on.should be_an_instance_of(Date)
78
+ end
79
+ end
80
+
81
+ context 'renew' do
82
+ subject { FastSpring::Subscription.new('acme', 'test_ref', 'admin', 'test') }
83
+ before do
84
+ stub_request(:get, "https://admin:test@api.fastspring.com/company/acme/subscription/test_ref").
85
+ to_return(stub_http_response_with('basic_subscription.xml'))
86
+ end
87
+
88
+ it 'returns a renewal path' do
89
+ subject.renew_path.should == "/company/acme/subscription/test_ref/renew"
90
+ end
91
+ end
92
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fastspring-saasy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Richard Patching
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-10 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: &70283465740340 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70283465740340
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &70283465738460 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70283465738460
36
+ - !ruby/object:Gem::Dependency
37
+ name: bundler
38
+ requirement: &70283465737120 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70283465737120
47
+ - !ruby/object:Gem::Dependency
48
+ name: jeweler
49
+ requirement: &70283465735680 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70283465735680
58
+ - !ruby/object:Gem::Dependency
59
+ name: httparty
60
+ requirement: &70283465731180 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 0.8.1
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70283465731180
69
+ description: Ruby lib for using the FastSpring (Saas) subscription management API
70
+ email: richard@justaddpixels.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files:
74
+ - LICENSE.txt
75
+ - README.rdoc
76
+ files:
77
+ - .document
78
+ - .rspec
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - LICENSE.txt
82
+ - README.rdoc
83
+ - Rakefile
84
+ - VERSION
85
+ - fastspring-saasy.gemspec
86
+ - lib/fastspring-saasy.rb
87
+ - lib/fastspring-saasy/customer.rb
88
+ - lib/fastspring-saasy/error.rb
89
+ - lib/fastspring-saasy/subscription.rb
90
+ - spec/customer_spec.rb
91
+ - spec/fixtures/basic_subscription.xml
92
+ - spec/spec_helper.rb
93
+ - spec/subscription_spec.rb
94
+ homepage: http://github.com/patchfx/fastspring
95
+ licenses:
96
+ - MIT
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ segments:
108
+ - 0
109
+ hash: 4132004254887174814
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 1.8.10
119
+ signing_key:
120
+ specification_version: 3
121
+ summary: Ruby lib for using the FastSpring (Saasy) API
122
+ test_files: []