rspreedly 0.1.14 → 0.1.15

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -20,7 +20,7 @@ spec = Gem::Specification.new do |s|
20
20
 
21
21
  # Change these as appropriate
22
22
  s.name = "rspreedly"
23
- s.version = "0.1.14"
23
+ s.version = "0.1.15"
24
24
  s.summary = "Ruby library for the Spreedly API"
25
25
  s.author = "Richard Livsey"
26
26
  s.email = "richard@livsey.org"
@@ -26,13 +26,14 @@ module RSpreedly
26
26
  :store_credit_currency_code,
27
27
  :subscription_plan_name,
28
28
  :token,
29
- :updated_at
29
+ :updated_at,
30
+ :invoices
30
31
 
31
32
  class << self
32
33
 
33
34
  # Get a subscriber’s details
34
- # GET /api/v4/[short site name]/subscribers/[subscriber id].xml
35
- def find(id)
35
+ # GET /api/v4/[short site name]/subscribers/[subscriber id].xml
36
+ def find(id)
36
37
  return all if id == :all
37
38
 
38
39
  begin
@@ -44,7 +45,7 @@ module RSpreedly
44
45
  end
45
46
 
46
47
  # Get a list of all subscribers (more)
47
- # GET /api/v4/[short site name]/subscribers.xml
48
+ # GET /api/v4/[short site name]/subscribers.xml
48
49
  def all
49
50
  response = api_request(:get, "/subscribers.xml")
50
51
  return [] unless response.has_key?("subscribers")
@@ -54,13 +55,23 @@ module RSpreedly
54
55
  # Clear all subscribers from a *test* site (more)
55
56
  # DELETE /api/v4/[short site name]/subscribers.xml
56
57
  def delete_all
57
- !! api_request(:delete, "/subscribers.xml")
58
+ !! api_request(:delete, "/subscribers.xml")
58
59
  end
59
60
 
60
61
  alias_method :destroy_all, :delete_all
61
62
 
62
63
  end
63
64
 
65
+ def invoices=(data)
66
+ @invoices = []
67
+ data.each do |item|
68
+ if item.is_a? Hash
69
+ item = RSpreedly::Invoice.new(item)
70
+ end
71
+ @invoices << item
72
+ end
73
+ end
74
+
64
75
  def new_record?
65
76
  !self.token
66
77
  end
@@ -74,7 +85,7 @@ module RSpreedly
74
85
  end
75
86
 
76
87
  # Create a subscriber (more)
77
- # POST /api/v4/[short site name]/subscribers.xml
88
+ # POST /api/v4/[short site name]/subscribers.xml
78
89
  def create!
79
90
  result = api_request(:post, "/subscribers.xml", :body => self.to_xml)
80
91
  self.attributes = result["subscriber"]
@@ -92,7 +103,7 @@ module RSpreedly
92
103
  end
93
104
 
94
105
  # Update a Subscriber (more)
95
- # PUT /api/v4/[short site name]/subscribers/[subscriber id].xml
106
+ # PUT /api/v4/[short site name]/subscribers/[subscriber id].xml
96
107
  def update!
97
108
  !! api_request(:put, "/subscribers/#{self.customer_id}.xml", :body => self.to_xml(:exclude => [:customer_id]))
98
109
  end
@@ -104,22 +115,22 @@ module RSpreedly
104
115
  # gulp those errors down
105
116
  # TODO - set self.errors or something?
106
117
  nil
107
- end
118
+ end
108
119
  end
109
120
 
110
121
  # Delete one subscriber from a *test* site (more)
111
- # DELETE /api/v4/[short site name]/subscribers/[subscriber id].xml
122
+ # DELETE /api/v4/[short site name]/subscribers/[subscriber id].xml
112
123
  def destroy
113
124
  begin
114
125
  !! api_request(:delete, "/subscribers/#{self.customer_id}.xml")
115
126
  rescue RSpreedly::Error::NotFound
116
127
  nil
117
- end
128
+ end
118
129
  end
119
130
  alias_method :delete, :destroy
120
131
 
121
132
  # Give a subscriber a complimentary subscription (more)
122
- # POST /api/v4/[short site name]/subscribers/[subscriber id]/complimentary_subscriptions.xml
133
+ # POST /api/v4/[short site name]/subscribers/[subscriber id]/complimentary_subscriptions.xml
123
134
  def comp_subscription(subscription)
124
135
  result = api_request(:post, "/subscribers/#{self.customer_id}/complimentary_subscriptions.xml", :body => subscription.to_xml)
125
136
  self.attributes = result["subscriber"]
@@ -154,7 +165,7 @@ module RSpreedly
154
165
  def subscribe_to_free_trial(plan)
155
166
  result = api_request(:post, "/subscribers/#{self.customer_id}/subscribe_to_free_trial.xml", :body => plan.to_xml)
156
167
  self.attributes = result["subscriber"]
157
- true
168
+ true
158
169
  end
159
170
 
160
171
  # Programatically Allow Another Free Trial (more)
@@ -162,33 +173,33 @@ module RSpreedly
162
173
  def allow_free_trial
163
174
  result = api_request(:post, "/subscribers/#{self.customer_id}/allow_free_trial.xml")
164
175
  self.attributes = result["subscriber"]
165
- true
176
+ true
166
177
  end
167
-
178
+
168
179
  def grant_lifetime_subscription(feature_level)
169
180
  subscription = LifetimeComplimentarySubscription.new(:feature_level => feature_level)
170
181
  result = api_request(:post, "/subscribers/#{self.customer_id}/lifetime_complimentary_subscriptions.xml", :body => subscription.to_xml)
171
182
  self.attributes = result["subscriber"]
172
183
  true
173
184
  end
174
-
185
+
175
186
  def to_xml(opts={})
176
-
187
+
177
188
  # the api doesn't let us send these things
178
189
  # so let's strip them out of the XML
179
190
  exclude = [
180
- :active, :active_until, :card_expires_before_next_auto_renew,
181
- :created_at, :eligible_for_free_trial, :feature_level,
182
- :grace_until, :in_grace_period, :lifetime_subscription,
183
- :on_trial, :ready_to_renew, :recurring,
184
- :store_credit, :store_credit_currency_code, :subscription_plan_name,
191
+ :active, :active_until, :card_expires_before_next_auto_renew,
192
+ :created_at, :eligible_for_free_trial, :feature_level,
193
+ :grace_until, :in_grace_period, :lifetime_subscription,
194
+ :on_trial, :ready_to_renew, :recurring,
195
+ :store_credit, :store_credit_currency_code, :subscription_plan_name,
185
196
  :token, :updated_at, :ready_to_renew_since
186
197
  ]
187
-
198
+
188
199
  opts[:exclude] ||= []
189
200
  opts[:exclude] |= exclude
190
-
191
- super(opts)
201
+
202
+ super(opts)
192
203
  end
193
204
  end
194
205
  end
data/rspreedly.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{rspreedly}
5
- s.version = "0.1.14"
5
+ s.version = "0.1.15"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Richard Livsey"]
@@ -22,4 +22,139 @@
22
22
  <in_grace_period type="boolean"></in_grace_period>
23
23
  <on-trial type="boolean">false</on-trial>
24
24
  <feature-level type="string"></feature-level>
25
+ <invoices type="array">
26
+ <invoice>
27
+ <closed type="boolean">true</closed>
28
+ <created-at type="datetime">2011-07-21T19:04:45Z</created-at>
29
+ <response-client-message nil="true"></response-client-message>
30
+ <response-customer-message nil="true"></response-customer-message>
31
+ <response-message nil="true"></response-message>
32
+ <token>46089ee32310b4983c6acb0bc02dec955886d411</token>
33
+ <updated-at type="datetime">2011-07-21T19:05:07Z</updated-at>
34
+ <price>$0.05</price>
35
+ <amount type="decimal">0.05</amount>
36
+ <currency-code>USD</currency-code>
37
+ <line-items type="array">
38
+ <line-item>
39
+ <amount type="decimal">99.0</amount>
40
+ <currency-code>USD</currency-code>
41
+ <description>Every 1 month</description>
42
+ <notes nil="true"></notes>
43
+ <price>$99.00</price>
44
+ </line-item>
45
+ <line-item>
46
+ <amount type="decimal">-48.99</amount>
47
+ <currency-code>USD</currency-code>
48
+ <description>Credit from current subscription</description>
49
+ <notes nil="true"></notes>
50
+ <price>$-48.99</price>
51
+ </line-item>
52
+ <line-item>
53
+ <amount type="decimal">-49.96</amount>
54
+ <currency-code>USD</currency-code>
55
+ <description>Your store credit</description>
56
+ <notes nil="true"></notes>
57
+ <price>$-49.96</price>
58
+ </line-item>
59
+ </line-items>
60
+ </invoice>
61
+ <invoice>
62
+ <closed type="boolean">true</closed>
63
+ <created-at type="datetime">2011-07-21T18:56:52Z</created-at>
64
+ <response-client-message nil="true"></response-client-message>
65
+ <response-customer-message nil="true"></response-customer-message>
66
+ <response-message nil="true"></response-message>
67
+ <token>4730937c43a57b333b78ba474e6384bfb434bee3</token>
68
+ <updated-at type="datetime">2011-07-21T18:57:12Z</updated-at>
69
+ <price>$-49.96</price>
70
+ <amount type="decimal">-49.96</amount>
71
+ <currency-code>USD</currency-code>
72
+ <line-items type="array">
73
+ <line-item>
74
+ <amount type="decimal">49.0</amount>
75
+ <currency-code>USD</currency-code>
76
+ <description>Every 1 month</description>
77
+ <notes nil="true"></notes>
78
+ <price>$49.00</price>
79
+ </line-item>
80
+ <line-item>
81
+ <amount type="decimal">-98.96</amount>
82
+ <currency-code>USD</currency-code>
83
+ <description>Credit from current subscription</description>
84
+ <notes nil="true"></notes>
85
+ <price>$-98.96</price>
86
+ </line-item>
87
+ </line-items>
88
+ </invoice>
89
+ <invoice>
90
+ <closed type="boolean">true</closed>
91
+ <created-at type="datetime">2011-07-21T18:39:17Z</created-at>
92
+ <response-client-message nil="true"></response-client-message>
93
+ <response-customer-message nil="true"></response-customer-message>
94
+ <response-message nil="true"></response-message>
95
+ <token>4bf20627d684dbaab231b349b1ed1ae6388f4ffc</token>
96
+ <updated-at type="datetime">2011-07-21T18:39:32Z</updated-at>
97
+ <price>$50.00</price>
98
+ <amount type="decimal">50.0</amount>
99
+ <currency-code>USD</currency-code>
100
+ <line-items type="array">
101
+ <line-item>
102
+ <amount type="decimal">99.0</amount>
103
+ <currency-code>USD</currency-code>
104
+ <description>Every 1 month</description>
105
+ <notes nil="true"></notes>
106
+ <price>$99.00</price>
107
+ </line-item>
108
+ <line-item>
109
+ <amount type="decimal">-49.0</amount>
110
+ <currency-code>USD</currency-code>
111
+ <description>Credit from current subscription</description>
112
+ <notes nil="true"></notes>
113
+ <price>$-49.00</price>
114
+ </line-item>
115
+ </line-items>
116
+ </invoice>
117
+ <invoice>
118
+ <closed type="boolean">true</closed>
119
+ <created-at type="datetime">2011-07-21T18:15:11Z</created-at>
120
+ <response-client-message nil="true"></response-client-message>
121
+ <response-customer-message nil="true"></response-customer-message>
122
+ <response-message nil="true"></response-message>
123
+ <token>a5190437c9651aa77ac6e39e9833b579bff4658e</token>
124
+ <updated-at type="datetime">2011-07-21T18:15:36Z</updated-at>
125
+ <price>$49.00</price>
126
+ <amount type="decimal">49.0</amount>
127
+ <currency-code>USD</currency-code>
128
+ <line-items type="array">
129
+ <line-item>
130
+ <amount type="decimal">49.0</amount>
131
+ <currency-code>USD</currency-code>
132
+ <description>Every 1 month</description>
133
+ <notes nil="true"></notes>
134
+ <price>$49.00</price>
135
+ </line-item>
136
+ </line-items>
137
+ </invoice>
138
+ <invoice>
139
+ <closed type="boolean">true</closed>
140
+ <created-at type="datetime">2011-07-21T18:14:07Z</created-at>
141
+ <response-client-message nil="true"></response-client-message>
142
+ <response-customer-message nil="true"></response-customer-message>
143
+ <response-message nil="true"></response-message>
144
+ <token>ea7a657f68908279fdc33c8cf1c7037c4a2eec2d</token>
145
+ <updated-at type="datetime">2011-07-21T18:14:32Z</updated-at>
146
+ <price>$0.00</price>
147
+ <amount type="decimal">0.0</amount>
148
+ <currency-code>USD</currency-code>
149
+ <line-items type="array">
150
+ <line-item>
151
+ <amount type="decimal">0.0</amount>
152
+ <currency-code>USD</currency-code>
153
+ <description>Initial 1 month</description>
154
+ <notes>Subsequent Time Periods are $49.00 every 1 month</notes>
155
+ <price>$0.00</price>
156
+ </line-item>
157
+ </line-items>
158
+ </invoice>
159
+ </invoices>
25
160
  </subscriber>
@@ -22,6 +22,15 @@ describe RSpreedly::Subscriber do
22
22
 
23
23
  RSpreedly::Subscriber.find(42).should be_a(RSpreedly::Subscriber)
24
24
  end
25
+
26
+ it "should include invoices on the Subscriber" do
27
+ stub_request(:get, spreedly_url("/subscribers/42.xml")).
28
+ to_return(:body => fixture("subscriber.xml"), :status => 200)
29
+
30
+ subscriber = RSpreedly::Subscriber.find(42)
31
+ subscriber.invoices.size.should == 5
32
+ subscriber.invoices.select{|x| x.is_a?(RSpreedly::Invoice )}.size.should == 5
33
+ end
25
34
  end
26
35
 
27
36
  describe ".all" do
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.14
4
+ version: 0.1.15
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: httparty
17
- requirement: &2165032460 !ruby/object:Gem::Requirement
17
+ requirement: &2164641520 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 0.5.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2165032460
25
+ version_requirements: *2164641520
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rspec
28
- requirement: &2165031860 !ruby/object:Gem::Requirement
28
+ requirement: &2164640940 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *2165031860
36
+ version_requirements: *2164640940
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: webmock
39
- requirement: &2165031220 !ruby/object:Gem::Requirement
39
+ requirement: &2164640420 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,7 +44,7 @@ dependencies:
44
44
  version: '0'
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *2165031220
47
+ version_requirements: *2164640420
48
48
  description:
49
49
  email: richard@livsey.org
50
50
  executables: []