adyen 0.3.8 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/.gitignore +4 -0
  2. data/.kick +35 -0
  3. data/LICENSE +3 -2
  4. data/README.rdoc +8 -4
  5. data/Rakefile +10 -0
  6. data/TODO +14 -4
  7. data/adyen.gemspec +9 -15
  8. data/lib/adyen.rb +10 -59
  9. data/lib/adyen/api.rb +281 -0
  10. data/lib/adyen/api/cacert.pem +3509 -0
  11. data/lib/adyen/api/payment_service.rb +258 -0
  12. data/lib/adyen/api/recurring_service.rb +126 -0
  13. data/lib/adyen/api/response.rb +54 -0
  14. data/lib/adyen/api/simple_soap_client.rb +118 -0
  15. data/lib/adyen/api/templates/payment_service.rb +103 -0
  16. data/lib/adyen/api/templates/recurring_service.rb +34 -0
  17. data/lib/adyen/api/test_helpers.rb +133 -0
  18. data/lib/adyen/api/xml_querier.rb +94 -0
  19. data/lib/adyen/configuration.rb +139 -0
  20. data/lib/adyen/form.rb +37 -109
  21. data/lib/adyen/formatter.rb +0 -10
  22. data/lib/adyen/matchers.rb +1 -1
  23. data/lib/adyen/notification_generator.rb +30 -0
  24. data/lib/adyen/railtie.rb +13 -0
  25. data/lib/adyen/templates/notification_migration.rb +29 -0
  26. data/lib/adyen/templates/notification_model.rb +70 -0
  27. data/spec/adyen_spec.rb +3 -45
  28. data/spec/api/api_spec.rb +139 -0
  29. data/spec/api/payment_service_spec.rb +439 -0
  30. data/spec/api/recurring_service_spec.rb +105 -0
  31. data/spec/api/response_spec.rb +35 -0
  32. data/spec/api/simple_soap_client_spec.rb +91 -0
  33. data/spec/api/spec_helper.rb +417 -0
  34. data/spec/api/test_helpers_spec.rb +83 -0
  35. data/spec/form_spec.rb +27 -23
  36. data/spec/functional/api_spec.rb +90 -0
  37. data/spec/functional/initializer.rb.sample +3 -0
  38. data/spec/spec_helper.rb +5 -5
  39. data/tasks/github-gem.rake +49 -55
  40. data/yard_extensions.rb +16 -0
  41. metadata +63 -82
  42. data/init.rb +0 -1
  43. data/lib/adyen/notification.rb +0 -151
  44. data/lib/adyen/soap.rb +0 -649
  45. data/spec/notification_spec.rb +0 -97
  46. data/spec/soap_spec.rb +0 -340
@@ -0,0 +1,83 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'api/spec_helper'
4
+ require 'adyen/api/test_helpers'
5
+
6
+ describe "Test helpers" do
7
+ include APISpecHelper
8
+
9
+ after do
10
+ Net::HTTP.stubbing_enabled = false
11
+ end
12
+
13
+ describe Adyen::API::PaymentService do
14
+ before do
15
+ @params = {
16
+ :reference => 'order-id',
17
+ :amount => {
18
+ :currency => 'EUR',
19
+ :value => '1234',
20
+ },
21
+ :shopper => {
22
+ :email => 's.hopper@example.com',
23
+ :reference => 'user-id',
24
+ :ip => '61.294.12.12',
25
+ },
26
+ :card => {
27
+ :expiry_month => 12,
28
+ :expiry_year => 2012,
29
+ :holder_name => 'Simon わくわく Hopper',
30
+ :number => '4444333322221111',
31
+ :cvc => '737',
32
+ # Maestro UK/Solo only
33
+ #:issue_number => ,
34
+ #:start_month => ,
35
+ #:start_year => ,
36
+ }
37
+ }
38
+ @payment = @object = Adyen::API::PaymentService.new(@params)
39
+ end
40
+
41
+ it "returns an `authorized' response" do
42
+ stub_net_http(AUTHORISATION_DECLINED_RESPONSE)
43
+ Adyen::API::PaymentService.stub_success!
44
+ @payment.authorise_payment.should be_authorized
45
+
46
+ @payment.authorise_payment.should_not be_authorized
47
+ end
48
+
49
+ it "returns a `refused' response" do
50
+ stub_net_http(AUTHORISE_RESPONSE)
51
+ Adyen::API::PaymentService.stub_refused!
52
+ response = @payment.authorise_payment
53
+ response.should_not be_authorized
54
+ response.should_not be_invalid_request
55
+
56
+ @payment.authorise_payment.should be_authorized
57
+ end
58
+
59
+ it "returns a `invalid request' response" do
60
+ stub_net_http(AUTHORISE_RESPONSE)
61
+ Adyen::API::PaymentService.stub_invalid!
62
+ response = @payment.authorise_payment
63
+ response.should_not be_authorized
64
+ response.should be_invalid_request
65
+
66
+ @payment.authorise_payment.should be_authorized
67
+ end
68
+ end
69
+
70
+ describe Adyen::API::RecurringService do
71
+ before do
72
+ @params = { :shopper => { :reference => 'user-id' } }
73
+ @recurring = @object = Adyen::API::RecurringService.new(@params)
74
+ end
75
+
76
+ it "returns a `disabled' response" do
77
+ stub_net_http(DISABLE_RESPONSE % 'nope')
78
+ Adyen::API::RecurringService.stub_disabled!
79
+ @recurring.disable.should be_disabled
80
+ @recurring.disable.should_not be_disabled
81
+ end
82
+ end
83
+ end
@@ -1,35 +1,38 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'spec_helper'
4
+ require 'adyen/form'
2
5
 
3
6
  describe Adyen::Form do
4
7
 
5
8
  before(:all) do
6
- Adyen::Form.register_skin(:testing, '4aD37dJA', 'Kah942*$7sdp0)')
7
- Adyen::Form.default_parameters[:merchant_account] = 'TestMerchant'
9
+ Adyen.configuration.register_form_skin(:testing, '4aD37dJA', 'Kah942*$7sdp0)')
10
+ Adyen.configuration.default_form_params[:merchant_account] = 'TestMerchant'
8
11
  end
9
12
 
10
13
  describe 'Action URLs' do
11
14
 
12
15
  before(:each) do
13
16
  # Use autodetection for the environment unless otherwise specified
14
- Adyen.environment = nil
17
+ Adyen.configuration.environment = nil
15
18
  end
16
19
 
17
20
  it "should generate correct the testing url" do
18
- Adyen::Form.url.should eql('https://test.adyen.com/hpp/select.shtml')
21
+ Adyen::Form.url.should == 'https://test.adyen.com/hpp/select.shtml'
19
22
  end
20
23
 
21
24
  it "should generate a live url if the environemtn is set top live" do
22
- Adyen.environment = :live
23
- Adyen::Form.url.should eql('https://live.adyen.com/hpp/select.shtml')
25
+ Adyen.configuration.environment = :live
26
+ Adyen::Form.url.should == 'https://live.adyen.com/hpp/select.shtml'
24
27
  end
25
28
 
26
29
  it "should generate correct live url in a production environment" do
27
- Adyen.stub!(:autodetect_environment).and_return('live')
28
- Adyen::Form.url.should eql('https://live.adyen.com/hpp/select.shtml')
30
+ Adyen.configuration.stub!(:autodetect_environment).and_return('live')
31
+ Adyen::Form.url.should. == 'https://live.adyen.com/hpp/select.shtml'
29
32
  end
30
33
 
31
34
  it "should generate correct live url if explicitely asked for" do
32
- Adyen::Form.url(:live).should eql('https://live.adyen.com/hpp/select.shtml')
35
+ Adyen::Form.url(:live).should == 'https://live.adyen.com/hpp/select.shtml'
33
36
  end
34
37
  end
35
38
 
@@ -44,11 +47,11 @@ describe Adyen::Form do
44
47
  end
45
48
 
46
49
  it "should calculate the signature string correctly" do
47
- Adyen::Form.redirect_signature_string(@params).should eql('AUTHORISED1211992213193029Internet Order 123454aD37dJA')
50
+ Adyen::Form.redirect_signature_string(@params).should == 'AUTHORISED1211992213193029Internet Order 123454aD37dJA'
48
51
  end
49
52
 
50
53
  it "should calculate the signature correctly" do
51
- Adyen::Form.redirect_signature(@params).should eql(@params[:merchantSig])
54
+ Adyen::Form.redirect_signature(@params).should == @params[:merchantSig]
52
55
  end
53
56
 
54
57
  it "should check the signature correctly with explicit shared signature" do
@@ -74,7 +77,7 @@ describe Adyen::Form do
74
77
  before(:each) do
75
78
  @attributes = { :currency_code => 'GBP', :payment_amount => 10000, :ship_before_date => Date.today,
76
79
  :merchant_reference => 'Internet Order 12345', :skin => :testing,
77
- :session_validity => 1.hour.from_now }
80
+ :session_validity => Time.now + 3600 }
78
81
 
79
82
  @redirect_url = Adyen::Form.redirect_url(@attributes)
80
83
  end
@@ -85,7 +88,7 @@ describe Adyen::Form do
85
88
 
86
89
  it "should include all provided attributes" do
87
90
  params = @redirect_url.split('?', 2).last.split('&').map { |param| param.split('=', 2).first }
88
- params.should include(*(@attributes.keys.map { |k| k.to_s.camelize(:lower) }))
91
+ params.should include(*(@attributes.keys.map { |k| Adyen::Form.camelize(k) }))
89
92
  end
90
93
 
91
94
  it "should include the merchant signature" do
@@ -96,17 +99,18 @@ describe Adyen::Form do
96
99
 
97
100
  describe 'hidden fields generation' do
98
101
 
99
- include ActionView::Helpers::TagHelper
100
-
101
102
  before(:each) do
102
103
  @attributes = { :currency_code => 'GBP', :payment_amount => 10000, :ship_before_date => Date.today,
103
104
  :merchant_reference => 'Internet Order 12345', :skin => :testing,
104
- :session_validity => 1.hour.from_now }
105
+ :session_validity => Time.now + 3600 }
105
106
  end
106
107
 
107
108
  it "should generate a valid payment form" do
108
- content_tag(:form, Adyen::Form.hidden_fields(@attributes),
109
- :action => Adyen::Form.url, :method => :post).should have_adyen_payment_form
109
+ html_snippet = <<-HTML
110
+ <form action="#{CGI.escapeHTML(Adyen::Form.url)}" method="post">#{Adyen::Form.hidden_fields(@attributes)}</form>
111
+ HTML
112
+
113
+ html_snippet.should have_adyen_payment_form
110
114
  end
111
115
  end
112
116
 
@@ -125,12 +129,12 @@ describe Adyen::Form do
125
129
 
126
130
  it "should construct the signature string correctly" do
127
131
  signature_string = Adyen::Form.calculate_signature_string(@parameters)
128
- signature_string.should eql("10000GBP2007-10-20Internet Order 123454aD37dJATestMerchant2007-10-11T11:00:00Z")
132
+ signature_string.should == "10000GBP2007-10-20Internet Order 123454aD37dJATestMerchant2007-10-11T11:00:00Z"
129
133
  end
130
134
 
131
135
  it "should calculate the signature correctly" do
132
136
  signature = Adyen::Form.calculate_signature(@parameters)
133
- signature.should eql('x58ZcRVL1H6y+XSeBGrySJ9ACVo=')
137
+ signature.should == 'x58ZcRVL1H6y+XSeBGrySJ9ACVo='
134
138
  end
135
139
 
136
140
  it "should calculate the signature correctly for a recurring payment" do
@@ -138,7 +142,7 @@ describe Adyen::Form do
138
142
  @parameters.merge!(:recurring_contract => 'DEFAULT', :shopper_reference => 'grasshopper52', :shopper_email => 'gras.shopper@somewhere.org')
139
143
 
140
144
  signature_string = Adyen::Form.calculate_signature_string(@parameters)
141
- signature_string.should eql("10000GBP2007-10-20Internet Order 123454aD37dJATestMerchant2007-10-11T11:00:00Zgras.shopper@somewhere.orggrasshopper52DEFAULT")
145
+ signature_string.should == "10000GBP2007-10-20Internet Order 123454aD37dJATestMerchant2007-10-11T11:00:00Zgras.shopper@somewhere.orggrasshopper52DEFAULT"
142
146
  end
143
147
 
144
148
  it "should calculate the signature correctly for a recurring payment" do
@@ -146,7 +150,7 @@ describe Adyen::Form do
146
150
  @parameters.merge!(:recurring_contract => 'DEFAULT', :shopper_reference => 'grasshopper52', :shopper_email => 'gras.shopper@somewhere.org')
147
151
 
148
152
  signature = Adyen::Form.calculate_signature(@parameters)
149
- signature.should eql('F2BQEYbE+EUhiRGuPtcD16Gm7JY=')
153
+ signature.should == 'F2BQEYbE+EUhiRGuPtcD16Gm7JY='
150
154
  end
151
155
  end
152
- end
156
+ end
@@ -0,0 +1,90 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ require 'rubygems'
5
+ require 'nokogiri'
6
+
7
+ API_SPEC_INITIALIZER = File.expand_path("../initializer.rb", __FILE__)
8
+
9
+ if File.exist?(API_SPEC_INITIALIZER)
10
+
11
+ describe Adyen::API, "with an actual remote connection" do
12
+ before :all do
13
+ require API_SPEC_INITIALIZER
14
+ Net::HTTP.stubbing_enabled = false
15
+ @order_id = @user_id = Time.now.to_i
16
+ perform_payment_request
17
+ end
18
+
19
+ after :all do
20
+ Net::HTTP.stubbing_enabled = true
21
+ end
22
+
23
+ def perform_payment_request
24
+ @payment_response = Adyen::API.authorise_payment(
25
+ @order_id,
26
+ { :currency => 'EUR', :value => '1234' },
27
+ { :email => "#{@user_id}@example.com", :reference => @user_id },
28
+ { :expiry_month => 12, :expiry_year => 2012, :holder_name => "Simon #{@user_id} Hopper", :number => '4444333322221111', :cvc => '737' },
29
+ true
30
+ )
31
+ end
32
+
33
+ it "performs a payment request" do
34
+ @payment_response.should be_authorized
35
+ @payment_response.psp_reference.should_not be_empty
36
+ end
37
+
38
+ it "performs a recurring payment request" do
39
+ response = Adyen::API.authorise_recurring_payment(
40
+ @order_id,
41
+ { :currency => 'EUR', :value => '1234' },
42
+ { :email => "#{@user_id}@example.com", :reference => @user_id }
43
+ )
44
+ response.should be_authorized
45
+ response.psp_reference.should_not be_empty
46
+ end
47
+
48
+ it "performs a one-click payment request" do
49
+ detail = Adyen::API.list_recurring_details(@user_id).references.last
50
+ response = Adyen::API.authorise_one_click_payment(
51
+ @order_id,
52
+ { :currency => 'EUR', :value => '1234' },
53
+ { :email => "#{@user_id}@example.com", :reference => @user_id },
54
+ '737',
55
+ detail
56
+ )
57
+ response.should be_authorized
58
+ response.psp_reference.should_not be_empty
59
+ end
60
+
61
+ it "captures a payment" do
62
+ response = Adyen::API.capture_payment(@payment_response.psp_reference, { :currency => 'EUR', :value => '1234' })
63
+ response.should be_success
64
+ end
65
+
66
+ it "refunds a payment" do
67
+ response = Adyen::API.refund_payment(@payment_response.psp_reference, { :currency => 'EUR', :value => '1234' })
68
+ response.should be_success
69
+ end
70
+
71
+ it "cancels or refunds a payment" do
72
+ response = Adyen::API.cancel_or_refund_payment(@payment_response.psp_reference)
73
+ response.should be_success
74
+ end
75
+
76
+ it "cancels a payment" do
77
+ response = Adyen::API.cancel_payment(@payment_response.psp_reference)
78
+ response.should be_success
79
+ end
80
+
81
+ it "disables a recurring contract" do
82
+ response = Adyen::API.disable_recurring_contract(@user_id)
83
+ response.should be_success
84
+ response.should be_disabled
85
+ end
86
+ end
87
+
88
+ else
89
+ puts "[!] To run the functional tests you'll need to create `spec/functional/initializer.rb' and configure with your test account settings. See `spec/functional/initializer.rb.sample'."
90
+ end
@@ -0,0 +1,3 @@
1
+ Adyen.configuration.default_api_params = { :merchant_account => 'SuperShopper' }
2
+ Adyen.configuration.api_username = 'SuperShopper'
3
+ Adyen.configuration.api_password = 'secret'
@@ -1,13 +1,13 @@
1
- require 'spec_helper'
1
+ # encoding: UTF-8
2
2
 
3
3
  require 'rubygems'
4
- require 'spec'
5
- require 'spec/autorun'
6
- require 'active_support'
4
+ require 'rspec'
5
+
6
+ $:.unshift File.expand_path('../../lib', __FILE__)
7
7
 
8
8
  require 'adyen'
9
9
  require 'adyen/matchers'
10
10
 
11
- Spec::Runner.configure do |config|
11
+ RSpec.configure do |config|
12
12
  config.include Adyen::Matchers
13
13
  end
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'rake/tasklib'
4
4
  require 'date'
5
- require 'git'
5
+ require 'set'
6
6
 
7
7
  module GithubGem
8
8
 
@@ -24,7 +24,7 @@ module GithubGem
24
24
 
25
25
  class RakeTasks
26
26
 
27
- attr_reader :gemspec, :modified_files, :git
27
+ attr_reader :gemspec, :modified_files
28
28
  attr_accessor :gemspec_file, :task_namespace, :main_include, :root_dir, :spec_pattern, :test_pattern, :remote, :remote_branch, :local_branch
29
29
 
30
30
  # Initializes the settings, yields itself for configuration
@@ -33,7 +33,7 @@ module GithubGem
33
33
  @gemspec_file = GithubGem.detect_gemspec_file
34
34
  @task_namespace = task_namespace
35
35
  @main_include = GithubGem.detect_main_include
36
- @modified_files = []
36
+ @modified_files = Set.new
37
37
  @root_dir = Dir.pwd
38
38
  @test_pattern = 'test/**/*_test.rb'
39
39
  @spec_pattern = 'spec/**/*_spec.rb'
@@ -43,13 +43,16 @@ module GithubGem
43
43
 
44
44
  yield(self) if block_given?
45
45
 
46
- @git = Git.open(@root_dir)
47
46
  load_gemspec!
48
47
  define_tasks!
49
48
  end
50
49
 
51
50
  protected
52
51
 
52
+ def git
53
+ @git ||= ENV['GIT'] || 'git'
54
+ end
55
+
53
56
  # Define Unit test tasks
54
57
  def define_test_tasks!
55
58
  require 'rake/testtask'
@@ -68,23 +71,23 @@ module GithubGem
68
71
 
69
72
  # Defines RSpec tasks
70
73
  def define_rspec_tasks!
71
- require 'spec/rake/spectask'
74
+ require 'rspec/core/rake_task'
72
75
 
73
76
  namespace(:spec) do
74
77
  desc "Verify all RSpec examples for #{gemspec.name}"
75
- Spec::Rake::SpecTask.new(:basic) do |t|
76
- t.spec_files = FileList[spec_pattern]
78
+ RSpec::Core::RakeTask.new(:basic) do |t|
79
+ t.pattern = spec_pattern
77
80
  end
78
81
 
79
82
  desc "Verify all RSpec examples for #{gemspec.name} and output specdoc"
80
- Spec::Rake::SpecTask.new(:specdoc) do |t|
81
- t.spec_files = FileList[spec_pattern]
82
- t.spec_opts << '--format' << 'specdoc' << '--color'
83
+ RSpec::Core::RakeTask.new(:specdoc) do |t|
84
+ t.pattern = spec_pattern
85
+ t.rspec_opts = ['--format', 'documentation', '--color']
83
86
  end
84
87
 
85
88
  desc "Run RCov on specs for #{gemspec.name}"
86
- Spec::Rake::SpecTask.new(:rcov) do |t|
87
- t.spec_files = FileList[spec_pattern]
89
+ RSpec::Core::RakeTask.new(:rcov) do |t|
90
+ t.pattern = spec_pattern
88
91
  t.rcov = true
89
92
  t.rcov_opts = ['--exclude', '"spec/*,gems/*"', '--rails']
90
93
  end
@@ -165,7 +168,7 @@ module GithubGem
165
168
  # in the repository and the spec/test file pattern.
166
169
  def manifest_task
167
170
  # Load all the gem's files using "git ls-files"
168
- repository_files = git.ls_files.keys
171
+ repository_files = `#{git} ls-files`.split("\n")
169
172
  test_files = Dir[test_pattern] + Dir[spec_pattern]
170
173
 
171
174
  update_gemspec(:files, repository_files)
@@ -180,7 +183,7 @@ module GithubGem
180
183
  end
181
184
 
182
185
  def newest_version
183
- git.tags.map { |tag| tag.name.split('-').last }.compact.map { |v| Gem::Version.new(v) }.max || Gem::Version.new('0.0.0')
186
+ `#{git} tag`.split("\n").map { |tag| tag.split('-').last }.compact.map { |v| Gem::Version.new(v) }.max || Gem::Version.new('0.0.0')
184
187
  end
185
188
 
186
189
  def next_version(increment = nil)
@@ -217,72 +220,58 @@ module GithubGem
217
220
 
218
221
  def check_version_task
219
222
  raise "#{ENV['VERSION']} is not a valid version number!" if ENV['VERSION'] && !Gem::Version.correct?(ENV['VERSION'])
220
- proposed_version = Gem::Version.new(ENV['VERSION'].dup || gemspec.version)
223
+ proposed_version = Gem::Version.new((ENV['VERSION'] || gemspec.version).dup)
221
224
  raise "This version (#{proposed_version}) is not higher than the highest tagged version (#{newest_version})" if newest_version >= proposed_version
222
225
  end
223
226
 
224
227
  # Checks whether the current branch is not diverged from the remote branch
225
228
  def check_not_diverged_task
226
- raise "The current branch is diverged from the remote branch!" if git.log.between('HEAD', git.remote(remote).branch(remote_branch).gcommit).any?
229
+ raise "The current branch is diverged from the remote branch!" if `#{git} rev-list HEAD..#{remote}/#{remote_branch}`.split("\n").any?
227
230
  end
228
231
 
229
232
  # Checks whether the repository status ic clean
230
233
  def check_clean_status_task
231
- raise "The current working copy contains modifications" if git.status.changed.any?
234
+ raise "The current working copy contains modifications" if `#{git} ls-files -m`.split("\n").any?
232
235
  end
233
236
 
234
237
  # Checks whether the current branch is correct
235
238
  def check_current_branch_task
236
- raise "Currently not on #{local_branch} branch!" unless git.branch.name == local_branch.to_s
239
+ raise "Currently not on #{local_branch} branch!" unless `#{git} branch`.split("\n").detect { |b| /^\* / =~ b } == "* #{local_branch}"
237
240
  end
238
241
 
239
242
  # Fetches the latest updates from Github
240
243
  def fetch_origin_task
241
- git.fetch('origin')
244
+ sh git, 'fetch', remote
242
245
  end
243
246
 
244
247
  # Commits every file that has been changed by the release task.
245
248
  def commit_modified_files_task
246
- if modified_files.any?
247
- modified_files.each { |file| git.add(file) }
248
- git.commit("Released #{gemspec.name} gem version #{gemspec.version}")
249
+ really_modified = `#{git} ls-files -m #{modified_files.entries.join(' ')}`.split("\n")
250
+ if really_modified.any?
251
+ really_modified.each { |file| sh git, 'add', file }
252
+ sh git, 'commit', '-m', "Released #{gemspec.name} gem version #{gemspec.version}."
249
253
  end
250
254
  end
251
255
 
252
256
  # Adds a tag for the released version
253
257
  def tag_version_task
254
- git.add_tag("#{gemspec.name}-#{gemspec.version}")
258
+ sh git, 'tag', '-a', "#{gemspec.name}-#{gemspec.version}", '-m', "Released #{gemspec.name} gem version #{gemspec.version}."
255
259
  end
256
260
 
257
261
  # Pushes the changes and tag to github
258
262
  def github_release_task
259
- git.push(remote, remote_branch, true)
263
+ sh git, 'push', '--tags', remote, remote_branch
260
264
  end
261
265
 
262
- # # Checks whether Rubyforge is configured properly
263
- # def check_rubyforge_task
264
- # # Login no longer necessary when using rubyforge 2.0.0 gem
265
- # # raise "Could not login on rubyforge!" unless `rubyforge login 2>&1`.strip.empty?
266
- # output = `rubyforge names`.split("\n")
267
- # raise "Rubyforge group not found!" unless output.any? { |line| %r[^groups\s*\:.*\b#{Regexp.quote(gemspec.rubyforge_project)}\b.*] =~ line }
268
- # raise "Rubyforge package not found!" unless output.any? { |line| %r[^packages\s*\:.*\b#{Regexp.quote(gemspec.name)}\b.*] =~ line }
269
- # end
270
-
271
- # # Task to release the .gem file toRubyforge.
272
- # def rubyforge_release_task
273
- # sh 'rubyforge', 'add_release', gemspec.rubyforge_project, gemspec.name, gemspec.version.to_s, "pkg/#{gemspec.name}-#{gemspec.version}.gem"
274
- # end
275
-
276
266
  def gemcutter_release_task
277
- sh "gem push pkg/#{gemspec.name}-#{gemspec.version}.gem"
267
+ sh "gem", 'push', "pkg/#{gemspec.name}-#{gemspec.version}.gem"
278
268
  end
279
269
 
280
270
  # Gem release task.
281
271
  # All work is done by the task's dependencies, so just display a release completed message.
282
272
  def release_task
283
273
  puts
284
- puts '------------------------------------------------------------'
285
- puts "Released #{gemspec.name} version #{gemspec.version}"
274
+ puts "Release successful."
286
275
  end
287
276
 
288
277
  private
@@ -342,30 +331,35 @@ module GithubGem
342
331
 
343
332
  # Reload the gemspec so the changes are incorporated
344
333
  load_gemspec!
334
+
335
+ # Also mark the Gemfile.lock file as changed because of the new version.
336
+ modified_files << 'Gemfile.lock' if File.exist?(File.join(root_dir, 'Gemfile.lock'))
345
337
  end
346
338
  end
347
339
 
348
340
  # Updates the tasks file using the latest file found on Github
349
341
  def update_tasks_task
350
- require 'net/http'
342
+ require 'net/https'
343
+ require 'uri'
351
344
 
352
- server = 'github.com'
353
- path = '/wvanbergen/github-gem/raw/master/tasks/github-gem.rake'
345
+ uri = URI.parse('https://github.com/wvanbergen/github-gem/raw/master/tasks/github-gem.rake')
346
+ http = Net::HTTP.new(uri.host, uri.port)
347
+ http.use_ssl = true
348
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
349
+ response = http.request(Net::HTTP::Get.new(uri.path))
354
350
 
355
- Net::HTTP.start(server) do |http|
356
- response = http.get(path)
351
+ if Net::HTTPSuccess === response
357
352
  open(__FILE__, "w") { |file| file.write(response.body) }
358
- end
359
-
360
- relative_file = File.expand_path(__FILE__).sub(%r[^#{git.dir.path}/], '')
361
- if git.status[relative_file] && git.status[relative_file].type == 'M'
362
- git.add(relative_file)
363
- git.commit("Updated to latest gem release management tasks.")
364
- puts "Updated to latest version of gem release management tasks."
353
+ relative_file = File.expand_path(__FILE__).sub(%r[^#{@root_dir}/], '')
354
+ if `#{git} ls-files -m #{relative_file}`.split("\n").any?
355
+ sh git, 'add', relative_file
356
+ sh git, 'commit', '-m', "Updated to latest gem release management tasks."
357
+ else
358
+ puts "Release managament tasks already are at the latest version."
359
+ end
365
360
  else
366
- puts "Release managament tasks already are at the latest version."
361
+ raise "Download failed with HTTP status #{response.code}!"
367
362
  end
368
363
  end
369
-
370
364
  end
371
365
  end