rspreedly 0.1.10 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.10
1
+ 0.1.11
data/lib/rspreedly.rb CHANGED
@@ -11,7 +11,7 @@ require 'rspreedly/subscription_plan'
11
11
  require 'rspreedly/payment_method'
12
12
  require 'rspreedly/complimentary_subscription'
13
13
  require 'rspreedly/complimentary_time_extension'
14
-
14
+ require 'rspreedly/lifetime_complimentary_subscription'
15
15
 
16
16
  module RSpreedly
17
17
 
@@ -0,0 +1,5 @@
1
+ module RSpreedly
2
+ class LifetimeComplimentarySubscription < Base
3
+ attr_accessor :feature_level
4
+ end
5
+ end
@@ -155,6 +155,13 @@ module RSpreedly
155
155
  true
156
156
  end
157
157
 
158
+ def grant_lifetime_subscription(feature_level)
159
+ subscription = LifetimeComplimentarySubscription.new(:feature_level => feature_level)
160
+ result = api_request(:post, "/subscribers/#{self.customer_id}/lifetime_complimentary_subscriptions.xml", :body => subscription.to_xml)
161
+ self.attributes = result["subscriber"]
162
+ true
163
+ end
164
+
158
165
  def to_xml(opts={})
159
166
 
160
167
  # the api doesn't let us send these things
data/rspreedly.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rspreedly}
8
- s.version = "0.1.10"
8
+ s.version = "0.1.11"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Richard Livsey"]
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
29
29
  "lib/rspreedly/config.rb",
30
30
  "lib/rspreedly/error.rb",
31
31
  "lib/rspreedly/invoice.rb",
32
+ "lib/rspreedly/lifetime_complimentary_subscription.rb",
32
33
  "lib/rspreedly/line_item.rb",
33
34
  "lib/rspreedly/payment_method.rb",
34
35
  "lib/rspreedly/subscriber.rb",
@@ -45,6 +46,7 @@ Gem::Specification.new do |s|
45
46
  "spec/fixtures/error_string.txt",
46
47
  "spec/fixtures/errors.xml",
47
48
  "spec/fixtures/existing_subscriber.xml",
49
+ "spec/fixtures/feature_level_blank.xml",
48
50
  "spec/fixtures/free_plan_not_elligable.xml",
49
51
  "spec/fixtures/free_plan_not_free.xml",
50
52
  "spec/fixtures/free_plan_not_set.xml",
@@ -53,6 +55,7 @@ Gem::Specification.new do |s|
53
55
  "spec/fixtures/invalid_update.xml",
54
56
  "spec/fixtures/invoice_created.xml",
55
57
  "spec/fixtures/invoice_invalid.xml",
58
+ "spec/fixtures/lifetime_subscription_success.xml",
56
59
  "spec/fixtures/no_plans.xml",
57
60
  "spec/fixtures/no_subscribers.xml",
58
61
  "spec/fixtures/payment_already_paid.xml",
@@ -84,6 +87,7 @@ Gem::Specification.new do |s|
84
87
  "spec/subscription_plan_spec.rb"
85
88
  ]
86
89
  s.add_dependency('httparty', '>= 0.5.0')
90
+
87
91
  if s.respond_to? :specification_version then
88
92
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
89
93
  s.specification_version = 3
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <errors>
3
+ <error>Feature level can't be blank</error>
4
+ </errors>
@@ -0,0 +1,25 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <subscriber>
3
+ <active-until type="datetime" nil="true">2010-02-21T19:04:28Z</active-until>
4
+ <billing-first-name nil="true"></billing-first-name>
5
+ <billing-last-name nil="true"></billing-last-name>
6
+ <created-at type="datetime">2009-10-28T22:27:38Z</created-at>
7
+ <customer-id>42</customer-id>
8
+ <eligible-for-free-trial type="boolean">true</eligible-for-free-trial>
9
+ <email>new@email.com</email>
10
+ <grace-until type="datetime">2013-05-02T00:07:37Z</grace-until>
11
+ <lifetime-subscription type="boolean">true</lifetime-subscription>
12
+ <ready-to-renew type="boolean">false</ready-to-renew>
13
+ <screen-name>bob</screen-name>
14
+ <store-credit type="decimal">0.0</store-credit>
15
+ <store-credit-currency-code>USD</store-credit-currency-code>
16
+ <token>81ba778a5849f461ebc0d77e78b9221af2210c6b</token>
17
+ <updated-at type="datetime">2009-10-28T22:55:37Z</updated-at>
18
+ <recurring type="boolean">false</recurring>
19
+ <card-expires-before-next-auto-renew type="boolean">false</card-expires-before-next-auto-renew>
20
+ <subscription-plan-name></subscription-plan-name>
21
+ <active type="boolean">false</active>
22
+ <in_grace_period type="boolean"></in_grace_period>
23
+ <on-trial type="boolean">false</on-trial>
24
+ <feature-level type="string">Something</feature-level>
25
+ </subscriber>
@@ -495,4 +495,44 @@ describe RSpreedly::Subscriber do
495
495
  }.should raise_error(RSpreedly::Error::NotFound)
496
496
  end
497
497
  end
498
+
499
+ describe "#grant_lifetime_subscription" do
500
+
501
+ before(:each) do
502
+ @subscriber = RSpreedly::Subscriber.new(:customer_id => 42)
503
+ end
504
+
505
+ it "should return true if successful" do
506
+ stub_http_with_fixture("lifetime_subscription_success.xml", 200)
507
+ @subscriber.grant_lifetime_subscription("Something").should be_true
508
+ end
509
+
510
+ it "should update the subscriber's lifetime_subscription if successful" do
511
+ stub_http_with_fixture("lifetime_subscription_success.xml", 200)
512
+ lambda{
513
+ @subscriber.grant_lifetime_subscription("Something")
514
+ }.should change(@subscriber, :lifetime_subscription).to(true)
515
+ end
516
+
517
+ it "should update the subscriber's feature_level if successful" do
518
+ stub_http_with_fixture("lifetime_subscription_success.xml", 200)
519
+ lambda{
520
+ @subscriber.grant_lifetime_subscription("Something")
521
+ }.should change(@subscriber, :feature_level).to("Something")
522
+ end
523
+
524
+ it "should raise NotFound if the subscriber doesn't exist" do
525
+ stub_http_with_fixture("subscriber_not_found.xml", 404)
526
+ lambda{
527
+ @subscriber.grant_lifetime_subscription("Something")
528
+ }.should raise_error(RSpreedly::Error::NotFound)
529
+ end
530
+
531
+ it "should raise BadRequest if the feature level is blank" do
532
+ stub_http_with_fixture("feature_level_blank.xml", 422)
533
+ lambda{
534
+ @subscriber.grant_lifetime_subscription("Something")
535
+ }.should raise_error(RSpreedly::Error::BadRequest)
536
+ end
537
+ end
498
538
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspreedly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Livsey
@@ -45,6 +45,7 @@ files:
45
45
  - lib/rspreedly/config.rb
46
46
  - lib/rspreedly/error.rb
47
47
  - lib/rspreedly/invoice.rb
48
+ - lib/rspreedly/lifetime_complimentary_subscription.rb
48
49
  - lib/rspreedly/line_item.rb
49
50
  - lib/rspreedly/payment_method.rb
50
51
  - lib/rspreedly/subscriber.rb
@@ -61,6 +62,7 @@ files:
61
62
  - spec/fixtures/error_string.txt
62
63
  - spec/fixtures/errors.xml
63
64
  - spec/fixtures/existing_subscriber.xml
65
+ - spec/fixtures/feature_level_blank.xml
64
66
  - spec/fixtures/free_plan_not_elligable.xml
65
67
  - spec/fixtures/free_plan_not_free.xml
66
68
  - spec/fixtures/free_plan_not_set.xml
@@ -69,6 +71,7 @@ files:
69
71
  - spec/fixtures/invalid_update.xml
70
72
  - spec/fixtures/invoice_created.xml
71
73
  - spec/fixtures/invoice_invalid.xml
74
+ - spec/fixtures/lifetime_subscription_success.xml
72
75
  - spec/fixtures/no_plans.xml
73
76
  - spec/fixtures/no_subscribers.xml
74
77
  - spec/fixtures/payment_already_paid.xml