rspreedly 0.1.11 → 0.1.14

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,48 +1,80 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "rspreedly"
8
- gem.summary = %Q{Ruby library for the Spreedly API}
9
- gem.email = "richard@livsey.org"
10
- gem.homepage = "http://github.com/rlivsey/rspreedly"
11
- gem.authors = ["Richard Livsey"]
12
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
13
- end
14
-
15
- rescue LoadError
16
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17
- end
1
+ require "rubygems"
2
+ require "rubygems/package_task"
3
+ require "rdoc/task"
18
4
 
19
- require 'spec/rake/spectask'
20
- Spec::Rake::SpecTask.new(:spec) do |spec|
21
- spec.libs << 'lib' << 'spec'
22
- spec.spec_files = FileList['spec/**/*_spec.rb']
5
+ require "rspec"
6
+ require "rspec/core/rake_task"
7
+ RSpec::Core::RakeTask.new do |t|
8
+ t.rspec_opts = %w(--format documentation --colour)
23
9
  end
24
10
 
25
- Spec::Rake::SpecTask.new(:rcov) do |spec|
26
- spec.libs << 'lib' << 'spec'
27
- spec.pattern = 'spec/**/*_spec.rb'
28
- spec.rcov = true
11
+
12
+ task :default => ["spec"]
13
+
14
+ # This builds the actual gem. For details of what all these options
15
+ # mean, and other ones you can add, check the documentation here:
16
+ #
17
+ # http://rubygems.org/read/chapter/20
18
+ #
19
+ spec = Gem::Specification.new do |s|
20
+
21
+ # Change these as appropriate
22
+ s.name = "rspreedly"
23
+ s.version = "0.1.14"
24
+ s.summary = "Ruby library for the Spreedly API"
25
+ s.author = "Richard Livsey"
26
+ s.email = "richard@livsey.org"
27
+ s.homepage = "http://github.com/rlivsey/rspreedly"
28
+
29
+ s.has_rdoc = true
30
+ s.extra_rdoc_files = %w(README.rdoc)
31
+ s.rdoc_options = %w(--main README.rdoc)
32
+
33
+ # Add any extra files to include in the gem
34
+ s.files = %w(LICENSE Rakefile README.rdoc rspreedly.gemspec) + Dir.glob("{spec,lib}/**/*")
35
+ s.require_paths = ["lib"]
36
+
37
+ # If you want to depend on other gems, add them here, along with any
38
+ # relevant versions
39
+ s.add_dependency("httparty", ">= 0.5.0")
40
+
41
+ # If your tests use any gems, include them here
42
+ s.add_development_dependency("rspec")
43
+ s.add_development_dependency("webmock")
29
44
  end
30
45
 
46
+ # This task actually builds the gem. We also regenerate a static
47
+ # .gemspec file, which is useful if something (i.e. GitHub) will
48
+ # be automatically building a gem for this project. If you're not
49
+ # using GitHub, edit as appropriate.
50
+ #
51
+ # To publish your gem online, install the 'gemcutter' gem; Read more
52
+ # about that here: http://gemcutter.org/pages/gem_docs
53
+ Gem::PackageTask.new(spec) do |pkg|
54
+ pkg.gem_spec = spec
55
+ end
31
56
 
32
- task :default => :spec
57
+ desc "Build the gemspec file #{spec.name}.gemspec"
58
+ task :gemspec do
59
+ file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
60
+ File.open(file, "w") {|f| f << spec.to_ruby }
61
+ end
33
62
 
34
- require 'rake/rdoctask'
35
- Rake::RDocTask.new do |rdoc|
36
- if File.exist?('VERSION.yml')
37
- config = YAML.load(File.read('VERSION.yml'))
38
- version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
39
- else
40
- version = ""
41
- end
63
+ # If you don't want to generate the .gemspec file, just remove this line. Reasons
64
+ # why you might want to generate a gemspec:
65
+ # - using bundler with a git source
66
+ # - building the gem without rake (i.e. gem build blah.gemspec)
67
+ # - maybe others?
68
+ task :package => :gemspec
42
69
 
43
- rdoc.rdoc_dir = 'rdoc'
44
- rdoc.title = "RSpreedly #{version}"
45
- rdoc.rdoc_files.include('README*')
46
- rdoc.rdoc_files.include('lib/**/*.rb')
70
+ # Generate documentation
71
+ RDoc::Task.new do |rd|
72
+ rd.main = "README.rdoc"
73
+ rd.rdoc_files.include("README.rdoc", "lib/**/*.rb")
74
+ rd.rdoc_dir = "rdoc"
47
75
  end
48
76
 
77
+ desc 'Clear out RDoc and generated packages'
78
+ task :clean => [:clobber_rdoc, :clobber_package] do
79
+ rm "#{spec.name}.gemspec"
80
+ end
data/lib/rspreedly.rb CHANGED
@@ -4,6 +4,7 @@ require 'httparty'
4
4
  require 'rspreedly/error'
5
5
  require 'rspreedly/config'
6
6
  require 'rspreedly/base'
7
+ require 'rspreedly/credit'
7
8
  require 'rspreedly/invoice'
8
9
  require 'rspreedly/line_item'
9
10
  require 'rspreedly/subscriber'
@@ -12,6 +13,7 @@ require 'rspreedly/payment_method'
12
13
  require 'rspreedly/complimentary_subscription'
13
14
  require 'rspreedly/complimentary_time_extension'
14
15
  require 'rspreedly/lifetime_complimentary_subscription'
16
+ require 'rspreedly/transaction'
15
17
 
16
18
  module RSpreedly
17
19
 
@@ -8,8 +8,8 @@ module RSpreedly
8
8
  attr_reader :errors
9
9
 
10
10
  def self.api_request(type, path, options={})
11
- site_name = RSpreedly::Config.site_name.class == Array ? RSpreedly::Config.site_name.first : RSpreedly::Config.site_name
12
- api_key = RSpreedly::Config.api_key.class == Array ? RSpreedly::Config.api_key.first : RSpreedly::Config.api_key
11
+ site_name = RSpreedly::Config.site_name
12
+ api_key = RSpreedly::Config.api_key
13
13
  path = "/#{site_name}#{path}"
14
14
 
15
15
  options.merge!({
@@ -1,26 +1,26 @@
1
1
  require 'pp'
2
2
  module RSpreedly
3
- module Config
3
+ module Config
4
4
  class << self
5
-
5
+
6
6
  # the configuration hash itself
7
7
  def configuration
8
8
  @configuration ||= defaults
9
9
  end
10
-
10
+
11
11
  def defaults
12
12
  {
13
13
  :logger => defined?(RAILS_DEFAULT_LOGGER) ? RAILS_DEFAULT_LOGGER : Logger.new(STDOUT),
14
14
  :debug => false,
15
15
  :site_name => "your-site-name",
16
- :api_key => "your-api-key"
16
+ :api_key => "your-api-key"
17
17
  }
18
18
  end
19
-
19
+
20
20
  def [](key)
21
21
  configuration[key]
22
22
  end
23
-
23
+
24
24
  def []=(key, val)
25
25
  configuration[key] = val
26
26
  end
@@ -29,57 +29,58 @@ module RSpreedly
29
29
  def delete(key)
30
30
  configuration.delete(key)
31
31
  end
32
-
32
+
33
33
  # Return the value of the key, or the default if doesn't exist
34
- #
34
+ #
35
35
  # ==== Examples
36
- #
36
+ #
37
37
  # RSpreedly::Config.fetch(:monkey, false)
38
38
  # => false
39
- #
39
+ #
40
40
  def fetch(key, default)
41
41
  configuration.fetch(key, default)
42
42
  end
43
43
 
44
44
  def to_hash
45
45
  configuration
46
- end
46
+ end
47
47
 
48
48
  # Yields the configuration.
49
- #
49
+ #
50
50
  # ==== Examples
51
51
  # RSpreedly::Config.use do |config|
52
52
  # config[:debug] = true
53
53
  # config.something = false
54
54
  # end
55
- #
55
+ #
56
56
  def setup
57
57
  yield self
58
58
  nil
59
- end
59
+ end
60
60
 
61
61
  def clear
62
62
  @configuration = {}
63
63
  end
64
-
64
+
65
65
  def reset
66
66
  @configuration = defaults
67
67
  end
68
-
68
+
69
69
  # allow getting and setting properties via RSpreedly::Config.xxx
70
- #
70
+ #
71
71
  # ==== Examples
72
72
  # RSpreedly::Config.debug
73
73
  # RSpreedly::Config.debug = false
74
- #
74
+ #
75
75
  def method_missing(method, *args)
76
76
  if method.to_s[-1,1] == '='
77
- configuration[method.to_s.tr('=','').to_sym] = *args
77
+ # splat with 1 item is just the item in 1.8, but an array in 1.9
78
+ configuration[method.to_s.tr('=','').to_sym] = args.is_a?(Array) ? args.first : args
78
79
  else
79
80
  configuration[method]
80
81
  end
81
- end
82
-
83
- end
82
+ end
83
+
84
+ end
84
85
  end
85
86
  end
@@ -0,0 +1,5 @@
1
+ module RSpreedly
2
+ class Credit < Base
3
+ attr_accessor :amount
4
+ end
5
+ end
@@ -6,5 +6,10 @@ module RSpreedly
6
6
  :address1, :address2, :city, :state, :zip, :country,
7
7
  :phone_number
8
8
  end
9
+ class OnFile < Base
10
+ def to_xml(opts=nil)
11
+ "<payment> <account-type>on-file</account-type> </payment>"
12
+ end
13
+ end
9
14
  end
10
15
  end
@@ -19,6 +19,7 @@ module RSpreedly
19
19
  :on_trial,
20
20
  :payment_method,
21
21
  :ready_to_renew,
22
+ :ready_to_renew_since,
22
23
  :recurring,
23
24
  :screen_name,
24
25
  :store_credit,
@@ -130,7 +131,16 @@ module RSpreedly
130
131
  def comp_time_extension(extension)
131
132
  result = api_request(:post, "/subscribers/#{self.customer_id}/complimentary_time_extensions.xml", :body => extension.to_xml)
132
133
  self.attributes = result["subscriber"]
133
- true
134
+ true
135
+ end
136
+
137
+ # Give a subscriber a credit (or reduce credit by supplying a negative value (more)
138
+ # POST /api/v4[short site name]/subscribers/[subscriber id]/credit.xml
139
+ def credit(amount)
140
+ credit = Credit.new(:amount => amount)
141
+ result = api_request(:post, "/subscribers/#{self.customer_id}/credit.xml", :body => credit.to_xml)
142
+ self.store_credit = (self.store_credit || 0) + amount
143
+ true
134
144
  end
135
145
 
136
146
  # Programatically Stopping Auto Renew of a Subscriber (more)
@@ -172,7 +182,7 @@ module RSpreedly
172
182
  :grace_until, :in_grace_period, :lifetime_subscription,
173
183
  :on_trial, :ready_to_renew, :recurring,
174
184
  :store_credit, :store_credit_currency_code, :subscription_plan_name,
175
- :token, :updated_at
185
+ :token, :updated_at, :ready_to_renew_since
176
186
  ]
177
187
 
178
188
  opts[:exclude] ||= []
@@ -26,7 +26,7 @@ module RSpreedly
26
26
  # there's no API method for just getting one plan, so we fake it!
27
27
  def self.find(id)
28
28
  return all if id == :all
29
- all.find{|plan| plan.id == id}
29
+ all.find{|plan| plan.id == id.to_i}
30
30
  end
31
31
 
32
32
  # Get a list of all subscription plans (more)
@@ -36,5 +36,12 @@ module RSpreedly
36
36
  return [] unless response.has_key?("subscription_plans")
37
37
  response["subscription_plans"].collect{|data| SubscriptionPlan.new(data)}
38
38
  end
39
+
40
+ # Get a list of all active subscription plans (more)
41
+ # GET /api/v4/[short site name]/subscription_plans.xml
42
+ def self.active
43
+ all.reject { |plan| !plan.enabled }
44
+ end
45
+
39
46
  end
40
- end
47
+ end
@@ -0,0 +1,39 @@
1
+ module RSpreedly
2
+
3
+ class Transaction < Base
4
+
5
+ attr_accessor :active,
6
+ :amount,
7
+ :created_at,
8
+ :currency_code,
9
+ :description,
10
+ :detail_type,
11
+ :expires,
12
+ :id,
13
+ :invoice_id,
14
+ :start_time,
15
+ :terms,
16
+ :updated_at,
17
+ :price,
18
+ :subscriber_customer_id,
19
+ :detail
20
+
21
+ class << self
22
+
23
+ # Get a list of 50 transactions
24
+ # Passing :since => id will get the 50 transactions since that one
25
+ # GET /api/v4/[short site name]/transactions.xml
26
+ def all(opts={})
27
+ query_opts = {}
28
+ if opts[:since]
29
+ query_opts[:query] = {:since_id => opts[:since]}
30
+ end
31
+
32
+ response = api_request(:get, "/transactions.xml", query_opts)
33
+ return [] unless response.has_key?("transactions")
34
+ response["transactions"].collect{|data| Transaction.new(data)}
35
+ end
36
+
37
+ end
38
+ end
39
+ end
data/rspreedly.gemspec CHANGED
@@ -1,101 +1,36 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
1
  # -*- encoding: utf-8 -*-
5
2
 
6
3
  Gem::Specification.new do |s|
7
4
  s.name = %q{rspreedly}
8
- s.version = "0.1.11"
5
+ s.version = "0.1.14"
9
6
 
10
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
8
  s.authors = ["Richard Livsey"]
12
- s.date = %q{2010-01-20}
9
+ s.date = %q{2011-07-21}
13
10
  s.email = %q{richard@livsey.org}
14
- s.extra_rdoc_files = [
15
- "LICENSE",
16
- "README.rdoc"
17
- ]
18
- s.files = [
19
- ".document",
20
- ".gitignore",
21
- "LICENSE",
22
- "README.rdoc",
23
- "Rakefile",
24
- "VERSION",
25
- "lib/rspreedly.rb",
26
- "lib/rspreedly/base.rb",
27
- "lib/rspreedly/complimentary_subscription.rb",
28
- "lib/rspreedly/complimentary_time_extension.rb",
29
- "lib/rspreedly/config.rb",
30
- "lib/rspreedly/error.rb",
31
- "lib/rspreedly/invoice.rb",
32
- "lib/rspreedly/lifetime_complimentary_subscription.rb",
33
- "lib/rspreedly/line_item.rb",
34
- "lib/rspreedly/payment_method.rb",
35
- "lib/rspreedly/subscriber.rb",
36
- "lib/rspreedly/subscription_plan.rb",
37
- "rspreedly.gemspec",
38
- "spec/base_spec.rb",
39
- "spec/config_spec.rb",
40
- "spec/fixtures/complimentary_failed_active.xml",
41
- "spec/fixtures/complimentary_failed_inactive.xml",
42
- "spec/fixtures/complimentary_not_valid.xml",
43
- "spec/fixtures/complimentary_success.xml",
44
- "spec/fixtures/create_subscriber.xml",
45
- "spec/fixtures/error.xml",
46
- "spec/fixtures/error_string.txt",
47
- "spec/fixtures/errors.xml",
48
- "spec/fixtures/existing_subscriber.xml",
49
- "spec/fixtures/feature_level_blank.xml",
50
- "spec/fixtures/free_plan_not_elligable.xml",
51
- "spec/fixtures/free_plan_not_free.xml",
52
- "spec/fixtures/free_plan_not_set.xml",
53
- "spec/fixtures/free_plan_success.xml",
54
- "spec/fixtures/invalid_subscriber.xml",
55
- "spec/fixtures/invalid_update.xml",
56
- "spec/fixtures/invoice_created.xml",
57
- "spec/fixtures/invoice_invalid.xml",
58
- "spec/fixtures/lifetime_subscription_success.xml",
59
- "spec/fixtures/no_plans.xml",
60
- "spec/fixtures/no_subscribers.xml",
61
- "spec/fixtures/payment_already_paid.xml",
62
- "spec/fixtures/payment_invalid.xml",
63
- "spec/fixtures/payment_not_found.xml",
64
- "spec/fixtures/payment_success.xml",
65
- "spec/fixtures/plan_disabled.xml",
66
- "spec/fixtures/plan_not_found.xml",
67
- "spec/fixtures/subscriber.xml",
68
- "spec/fixtures/subscriber_not_found.xml",
69
- "spec/fixtures/subscribers.xml",
70
- "spec/fixtures/subscription_plan_list.xml",
71
- "spec/invoice_spec.rb",
72
- "spec/spec_helper.rb",
73
- "spec/subscriber_spec.rb",
74
- "spec/subscription_plan_spec.rb"
75
- ]
11
+ s.extra_rdoc_files = ["README.rdoc"]
12
+ s.files = ["LICENSE", "Rakefile", "README.rdoc", "rspreedly.gemspec", "spec/base_spec.rb", "spec/config_spec.rb", "spec/fixtures", "spec/fixtures/complimentary_failed_active.xml", "spec/fixtures/complimentary_failed_inactive.xml", "spec/fixtures/complimentary_not_valid.xml", "spec/fixtures/complimentary_success.xml", "spec/fixtures/create_subscriber.xml", "spec/fixtures/credit_not_valid.xml", "spec/fixtures/credit_success.xml", "spec/fixtures/error.xml", "spec/fixtures/error_string.txt", "spec/fixtures/errors.xml", "spec/fixtures/existing_subscriber.xml", "spec/fixtures/feature_level_blank.xml", "spec/fixtures/free_plan_not_elligable.xml", "spec/fixtures/free_plan_not_free.xml", "spec/fixtures/free_plan_not_set.xml", "spec/fixtures/free_plan_success.xml", "spec/fixtures/invalid_subscriber.xml", "spec/fixtures/invalid_update.xml", "spec/fixtures/invoice_created.xml", "spec/fixtures/invoice_invalid.xml", "spec/fixtures/lifetime_subscription_success.xml", "spec/fixtures/no_plans.xml", "spec/fixtures/no_subscribers.xml", "spec/fixtures/no_transactions.xml", "spec/fixtures/payment_already_paid.xml", "spec/fixtures/payment_invalid.xml", "spec/fixtures/payment_not_found.xml", "spec/fixtures/payment_success.xml", "spec/fixtures/plan_disabled.xml", "spec/fixtures/plan_not_found.xml", "spec/fixtures/subscriber.xml", "spec/fixtures/subscriber_not_found.xml", "spec/fixtures/subscribers.xml", "spec/fixtures/subscription_plan_list.xml", "spec/fixtures/transactions.xml", "spec/invoice_spec.rb", "spec/spec_helper.rb", "spec/subscriber_spec.rb", "spec/subscription_plan_spec.rb", "spec/transaction_spec.rb", "lib/rspreedly", "lib/rspreedly/base.rb", "lib/rspreedly/complimentary_subscription.rb", "lib/rspreedly/complimentary_time_extension.rb", "lib/rspreedly/config.rb", "lib/rspreedly/credit.rb", "lib/rspreedly/error.rb", "lib/rspreedly/invoice.rb", "lib/rspreedly/lifetime_complimentary_subscription.rb", "lib/rspreedly/line_item.rb", "lib/rspreedly/payment_method.rb", "lib/rspreedly/subscriber.rb", "lib/rspreedly/subscription_plan.rb", "lib/rspreedly/transaction.rb", "lib/rspreedly.rb"]
76
13
  s.homepage = %q{http://github.com/rlivsey/rspreedly}
77
- s.rdoc_options = ["--charset=UTF-8"]
14
+ s.rdoc_options = ["--main", "README.rdoc"]
78
15
  s.require_paths = ["lib"]
79
- s.rubygems_version = %q{1.3.5}
16
+ s.rubygems_version = %q{1.6.2}
80
17
  s.summary = %q{Ruby library for the Spreedly API}
81
- s.test_files = [
82
- "spec/base_spec.rb",
83
- "spec/config_spec.rb",
84
- "spec/invoice_spec.rb",
85
- "spec/spec_helper.rb",
86
- "spec/subscriber_spec.rb",
87
- "spec/subscription_plan_spec.rb"
88
- ]
89
- s.add_dependency('httparty', '>= 0.5.0')
90
18
 
91
19
  if s.respond_to? :specification_version then
92
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
93
20
  s.specification_version = 3
94
21
 
95
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
22
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
23
+ s.add_runtime_dependency(%q<httparty>, [">= 0.5.0"])
24
+ s.add_development_dependency(%q<rspec>, [">= 0"])
25
+ s.add_development_dependency(%q<webmock>, [">= 0"])
96
26
  else
27
+ s.add_dependency(%q<httparty>, [">= 0.5.0"])
28
+ s.add_dependency(%q<rspec>, [">= 0"])
29
+ s.add_dependency(%q<webmock>, [">= 0"])
97
30
  end
98
31
  else
32
+ s.add_dependency(%q<httparty>, [">= 0.5.0"])
33
+ s.add_dependency(%q<rspec>, [">= 0"])
34
+ s.add_dependency(%q<webmock>, [">= 0"])
99
35
  end
100
36
  end
101
-