poundpay 0.0.2 → 0.1.0

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/.autotest ADDED
@@ -0,0 +1,2 @@
1
+ require 'autotest/bundler'
2
+ require 'autotest/growl'
data/.rspec ADDED
File without changes
data/Rakefile CHANGED
@@ -1,2 +1,7 @@
1
1
  require 'bundler'
2
- Bundler::GemHelper.install_tasks
2
+ require "rspec"
3
+ require "rspec/core/rake_task"
4
+
5
+ Bundler::GemHelper.install_tasks
6
+
7
+ Rspec::Core::RakeTask.new(:spec)
@@ -0,0 +1,22 @@
1
+ require 'poundpay/resource'
2
+
3
+ class PaymentReleaseException < Exception
4
+ end
5
+
6
+ module Poundpay
7
+ class Developer < Resource
8
+ def self.me
9
+ find(self.user)
10
+ end
11
+ end
12
+
13
+ class Payment < Resource
14
+ def release
15
+ unless status == 'ESCROWED'
16
+ raise PaymentReleaseException.new "Payment status is #{status}. Only ESCROWED payments may be released"
17
+ end
18
+ status = 'RELEASED'
19
+ save
20
+ end
21
+ end
22
+ end
@@ -11,19 +11,20 @@ module Poundpay
11
11
 
12
12
  # Modified default to not use an extension
13
13
  def element_path(id, prefix_options = {}, query_options = nil)
14
- prefix_options, query_options = split_options(prefix_options) if query_options.nil?
15
- "#{prefix(prefix_options)}#{collection_name}/#{URI.escape id.to_s}#{query_string(query_options)}"
14
+ path = super(id, prefix_options, query_options)
15
+ remove_extension(path)
16
16
  end
17
17
 
18
18
  # Modified default to not use an extension
19
19
  def new_element_path(prefix_options = {})
20
- "#{prefix(prefix_options)}#{collection_name}/new"
20
+ path = super(prefix_options)
21
+ remove_extension(path)
21
22
  end
22
23
 
23
24
  # Modified default to not use an extension
24
25
  def collection_path(prefix_options = {}, query_options = nil)
25
- prefix_options, query_options = split_options(prefix_options) if query_options.nil?
26
- "#{prefix(prefix_options)}#{collection_name}#{query_string(query_options)}"
26
+ path = super(prefix_options, query_options)
27
+ remove_extension(path)
27
28
  end
28
29
 
29
30
  # Handle paginated collections
@@ -32,6 +33,11 @@ module Poundpay
32
33
  collection = collection[collection_name]
33
34
  super(collection, prefix_options)
34
35
  end
36
+
37
+ protected
38
+ def remove_extension(path)
39
+ path.sub /(\.#{format.extension})$/, ""
40
+ end
35
41
  end
36
42
 
37
43
  # Poundpay accepts urlencoded form parameters
@@ -1,3 +1,3 @@
1
1
  module Poundpay
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/poundpay.rb CHANGED
@@ -1,33 +1,20 @@
1
1
  require 'poundpay/resource'
2
+ require 'poundpay/elements'
2
3
 
3
4
  module Poundpay
4
5
  API_URL = "https://api.poundpay.com"
5
- VERSION = "silver"
6
+ API_VERSION = "silver"
6
7
 
7
8
  class << self
8
- def configure(developer_sid, auth_token, api_url=API_URL, version=VERSION)
9
+ def configure(developer_sid, auth_token, api_url=API_URL, version=API_VERSION)
9
10
  unless developer_sid.start_with? "DV"
10
- raise ArgumentError.new "developer_sid should start with DV. Make sure " \
11
+ raise ArgumentError.new "developer_sid should start with 'DV'. Make sure " \
11
12
  "you're using the right developer_sid"
12
13
  end
14
+ api_url.sub! /(\/)$/, "" # Remove trailing backslash
13
15
  Resource.site = "#{api_url}/#{version}/"
14
16
  Resource.user = developer_sid
15
17
  Resource.password = auth_token
16
18
  end
17
19
  end
18
-
19
- class Developer < Resource
20
- class << self
21
- def me
22
- find(self.user)
23
- end
24
- end
25
- end
26
-
27
- class Payment < Resource
28
- def release
29
- self.status = 'RELEASED'
30
- self.save
31
- end
32
- end
33
20
  end
data/poundpay.gemspec CHANGED
@@ -16,6 +16,8 @@ Gem::Specification.new do |s|
16
16
 
17
17
  s.add_dependency("activeresource", ">= 3.0")
18
18
 
19
+ s.add_development_dependency("rspec", ">= 2.0")
20
+
19
21
  s.files = `git ls-files`.split("\n")
20
22
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
23
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
@@ -0,0 +1,13 @@
1
+ module Poundpay
2
+ module DeveloperFixture
3
+ def developer_attributes
4
+ {
5
+ "sid" => "DV0383d447360511e0bbac00264a09ff3c",
6
+ "created_at" => "2011-01-21T01:48:18.649355Z",
7
+ "balance" => 500000,
8
+ "name" => "Awesome Marketplace",
9
+ "callback_url" => "http://awesomemarketplace.com/poundpay_callback",
10
+ }
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,69 @@
1
+ module Poundpay
2
+ module PaymentFixture
3
+ def created_payment_attributes
4
+ {
5
+ "amount" => 20000,
6
+ "payer_fee_amount" => 0,
7
+ "payer_email_address" => "goliath@example.com",
8
+ "recipient_fee_amount" => 500,
9
+ "recipient_email_address" => "david@example.com",
10
+ "description" => "Beats by Dr. Dre",
11
+ "sid" => "PY1d82752a361211e0bce31231400042c7",
12
+ "status" => "STAGED",
13
+ "amount_to_credit_developer" => 550,
14
+ "updated_at" => "2011-02-11T19:07:05.332356Z",
15
+ "recipient_sid" => nil,
16
+ "payer_sid" => nil,
17
+ "developer_sid" => "DV8539761e250011e0a81d1231400042c7",
18
+ "poundpay_fee_amount" => 450,
19
+ "created_at" => "2011-02-11T19:07:05.332356Z",
20
+ "amount_to_credit_recipient" => 19500,
21
+ "amount_to_charge_payer" => 20000,
22
+ }
23
+ end
24
+
25
+ def escrowed_payment_attributes
26
+ {
27
+ "amount" => 20000,
28
+ "payer_fee_amount" => 0,
29
+ "payer_email_address" => "goliath@example.com",
30
+ "recipient_fee_amount" => 500,
31
+ "recipient_email_address" => "david@example.com",
32
+ "description" => "Beats by Dr. Dre",
33
+ "sid" => "PY1d82752a361211e0bce31231400042c7",
34
+ "status" => "ESCROWED",
35
+ "amount_to_credit_developer" => 550,
36
+ "updated_at" => "2011-02-11T19:07:05.332356Z",
37
+ "recipient_sid" => nil,
38
+ "payer_sid" => "US552595ee364111e0b18800264a09ff3c",
39
+ "developer_sid" => "DV8539761e250011e0a81d1231400042c7",
40
+ "poundpay_fee_amount" => 450,
41
+ "created_at" => "2011-02-11T19:07:05.332356Z",
42
+ "amount_to_credit_recipient" => 19500,
43
+ "amount_to_charge_payer" => 20000,
44
+ }
45
+ end
46
+
47
+ def released_payment_attributes
48
+ {
49
+ "amount" => 20000,
50
+ "payer_fee_amount" => 0,
51
+ "payer_email_address" => "goliath@example.com",
52
+ "recipient_fee_amount" => 500,
53
+ "recipient_email_address" => "david@example.com",
54
+ "description" => "Beats by Dr. Dre",
55
+ "sid" => "PY1d82752a361211e0bce31231400042c7",
56
+ "status" => "RELEASED",
57
+ "amount_to_credit_developer" => 550,
58
+ "updated_at" => "2011-02-11T19:07:05.332356Z",
59
+ "recipient_sid" => nil,
60
+ "payer_sid" => "US552595ee364111e0b18800264a09ff3c",
61
+ "developer_sid" => "DV8539761e250011e0a81d1231400042c7",
62
+ "poundpay_fee_amount" => 450,
63
+ "created_at" => "2011-02-11T19:07:05.332356Z",
64
+ "amount_to_credit_recipient" => 19500,
65
+ "amount_to_charge_payer" => 20000,
66
+ }
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,50 @@
1
+ require 'poundpay'
2
+ require 'poundpay/elements'
3
+ require 'fixtures/payments'
4
+ require 'fixtures/developers'
5
+
6
+ include Poundpay
7
+
8
+ describe Developer do
9
+ include DeveloperFixture
10
+
11
+ before (:all) do
12
+ Poundpay.configure(
13
+ "DV0383d447360511e0bbac00264a09ff3c",
14
+ "c31155b9f944d7aed204bdb2a253fef13b4fdcc6ae1540200449cc4526b2381a",
15
+ )
16
+ end
17
+
18
+ describe "#me" do
19
+ it "should return the developer's information" do
20
+ Developer.should_receive(:find).with(Developer.user).and_return(Developer.new developer_attributes)
21
+ @developer = Developer.me
22
+ end
23
+ end
24
+ end
25
+
26
+ describe Payment do
27
+ include PaymentFixture
28
+
29
+ before (:all) do
30
+ Poundpay.configure(
31
+ "DV0383d447360511e0bbac00264a09ff3c",
32
+ "c31155b9f944d7aed204bdb2a253fef13b4fdcc6ae1540200449cc4526b2381a",
33
+ )
34
+ end
35
+
36
+ describe "#release" do
37
+ it "should not be able to release a STAGED payment" do
38
+ @created_payment = Payment.new created_payment_attributes
39
+ expect {@created_payment.release}.to raise_error(PaymentReleaseException)
40
+ end
41
+
42
+ it "should release a ESCROWED payment" do
43
+ @escrowed_payment = Payment.new escrowed_payment_attributes
44
+ @escrowed_payment.should_receive(:save).and_return(Payment.new released_payment_attributes)
45
+
46
+ @escrowed_payment.release
47
+ @escrowed_payment.status.should == 'ESCROWED'
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,15 @@
1
+ require 'active_resource/formats'
2
+ require 'poundpay/formats'
3
+ include Poundpay
4
+
5
+ describe Formats::UrlencodedJsonFormat do
6
+ describe "#mime_type" do
7
+ it "should have a content type for a urlencoded form" do
8
+ Formats::UrlencodedJsonFormat.mime_type.should == "application/x-www-form-urlencoded"
9
+ end
10
+
11
+ it "should extend from active_resource JsonFormat" do
12
+ Formats::UrlencodedJsonFormat.should be_a ActiveResource::Formats::JsonFormat
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,53 @@
1
+ require 'poundpay/resource'
2
+ include Poundpay
3
+
4
+ class FakeElement < Resource
5
+ self.site = "http://api.example.com/version/"
6
+ end
7
+
8
+ describe Resource do
9
+ describe "#self.primary_key" do
10
+ it "should default to 'sid'" do
11
+ Resource.primary_key.should == "sid"
12
+ end
13
+ end
14
+
15
+ describe "#self.element_path" do
16
+ it "should not add a extension to the element_path" do
17
+ FakeElement.element_path(1).should == "/version/fake_elements/1"
18
+ end
19
+ end
20
+
21
+ describe "#self.new_element_path" do
22
+ it "should not add a extension to the new_element_path" do
23
+ FakeElement.new_element_path.should == "/version/fake_elements/new"
24
+ end
25
+ end
26
+
27
+ describe "#self.collection_path" do
28
+ it "should not add a extension to the collection_path" do
29
+ FakeElement.collection_path.should == "/version/fake_elements"
30
+ end
31
+ end
32
+
33
+ describe "#self.instantiate_collection" do
34
+ it "should handle paginated responses" do
35
+ collection = {"fake_elements" => [{"sid" => 1}, {"sid" => 2}]}
36
+ fake_elements = FakeElement.instantiate_collection(collection)
37
+ fake_elements.should == [FakeElement.new(:sid => 1), FakeElement.new(:sid => 2)]
38
+ end
39
+ end
40
+
41
+ describe "#encode" do
42
+ it "should urlencode the attributes" do
43
+ fake_element = FakeElement.new(:foo => "bar baz")
44
+ fake_element.encode.should == "foo=bar+baz"
45
+ end
46
+ end
47
+
48
+ describe "#collection_name" do
49
+ it "should get the collection_name" do
50
+ FakeElement.new.collection_name.should == "fake_elements"
51
+ end
52
+ end
53
+ end
@@ -1,34 +1,42 @@
1
1
  require 'poundpay'
2
2
 
3
- describe Poundpay do
4
- describe "#configure" do
5
- it "should require developer_sid to start with DV" do
6
- expect {
7
- # Pass developer_sid and auth_token in wrong order
8
- Poundpay.configure(
9
- "c31155b9f944d7aed204bdb2a253fef13b4fdcc6ae1540200449cc4526b2381a",
10
- "DV0383d447360511e0bbac00264a09ff3c",
11
- )
12
- }.to raise_error(ArgumentError, /DV/)
13
- end
14
-
15
- it "should be configured with default api_url and version" do
16
- developer_sid = "DV0383d447360511e0bbac00264a09ff3c"
17
- auth_token = "c31155b9f944d7aed204bdb2a253fef13b4fdcc6ae1540200449cc4526b2381a"
18
- Poundpay.configure(developer_sid, auth_token)
19
- Poundpay::Resource.user.should == developer_sid
20
- Poundpay::Resource.password.should == auth_token
21
- Poundpay::Resource.site.to_s.should == "https://api.poundpay.com/silver/"
22
- end
23
-
24
- it "should accept optional api_url and version" do
3
+ describe Poundpay, ".configure" do
4
+ it "should require developer_sid to start with 'DV'" do
5
+ expect {
6
+ # Pass developer_sid and auth_token in wrong order
25
7
  Poundpay.configure(
26
- "DV0383d447360511e0bbac00264a09ff3c",
27
8
  "c31155b9f944d7aed204bdb2a253fef13b4fdcc6ae1540200449cc4526b2381a",
28
- api_url="https://api-sandbox.poundpay.com",
29
- version="gold",
9
+ "DV0383d447360511e0bbac00264a09ff3c",
30
10
  )
31
- Poundpay::Resource.site.to_s.should == "https://api-sandbox.poundpay.com/gold/"
32
- end
11
+ }.to raise_error(ArgumentError, /DV/)
12
+ end
13
+
14
+ it "should be configured with default api_url and version" do
15
+ developer_sid = "DV0383d447360511e0bbac00264a09ff3c"
16
+ auth_token = "c31155b9f944d7aed204bdb2a253fef13b4fdcc6ae1540200449cc4526b2381a"
17
+ Poundpay.configure(developer_sid, auth_token)
18
+ Poundpay::Resource.user.should == developer_sid
19
+ Poundpay::Resource.password.should == auth_token
20
+ Poundpay::Resource.site.to_s.should == "https://api.poundpay.com/silver/"
21
+ end
22
+
23
+ it "should accept optional api_url and version" do
24
+ Poundpay.configure(
25
+ "DV0383d447360511e0bbac00264a09ff3c",
26
+ "c31155b9f944d7aed204bdb2a253fef13b4fdcc6ae1540200449cc4526b2381a",
27
+ api_url="https://api-sandbox.poundpay.com",
28
+ version="gold",
29
+ )
30
+ Poundpay::Resource.site.to_s.should == "https://api-sandbox.poundpay.com/gold/"
31
+ end
32
+
33
+ it "should allow api_url to have a trailing backslash" do
34
+ Poundpay.configure(
35
+ "DV0383d447360511e0bbac00264a09ff3c",
36
+ "c31155b9f944d7aed204bdb2a253fef13b4fdcc6ae1540200449cc4526b2381a",
37
+ api_url="https://api-sandbox.poundpay.com/",
38
+ version="gold",
39
+ )
40
+ Poundpay::Resource.site.to_s.should == "https://api-sandbox.poundpay.com/gold/"
33
41
  end
34
42
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
+ - 1
7
8
  - 0
8
- - 2
9
- version: 0.0.2
9
+ version: 0.1.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Matin Tamizi
@@ -31,6 +31,20 @@ dependencies:
31
31
  version: "3.0"
32
32
  type: :runtime
33
33
  version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rspec
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 2
44
+ - 0
45
+ version: "2.0"
46
+ type: :development
47
+ version_requirements: *id002
34
48
  description: Payments platform for marketplaces
35
49
  email: devsupport@poundpay.com
36
50
  executables: []
@@ -40,7 +54,9 @@ extensions: []
40
54
  extra_rdoc_files: []
41
55
 
42
56
  files:
57
+ - .autotest
43
58
  - .gitignore
59
+ - .rspec
44
60
  - .rvmrc
45
61
  - Gemfile
46
62
  - README
@@ -53,10 +69,16 @@ files:
53
69
  - examples/simple_application/config.ru
54
70
  - examples/simple_application/index.html.erb
55
71
  - lib/poundpay.rb
72
+ - lib/poundpay/elements.rb
56
73
  - lib/poundpay/formats.rb
57
74
  - lib/poundpay/resource.rb
58
75
  - lib/poundpay/version.rb
59
76
  - poundpay.gemspec
77
+ - spec/fixtures/developers.rb
78
+ - spec/fixtures/payments.rb
79
+ - spec/poundpay/elements_spec.rb
80
+ - spec/poundpay/formats_spec.rb
81
+ - spec/poundpay/resource_spec.rb
60
82
  - spec/poundpay_spec.rb
61
83
  has_rdoc: true
62
84
  homepage: http://github.com/poundpay/poundpay-ruby
@@ -91,4 +113,9 @@ signing_key:
91
113
  specification_version: 3
92
114
  summary: Poundpay Ruby library
93
115
  test_files:
116
+ - spec/fixtures/developers.rb
117
+ - spec/fixtures/payments.rb
118
+ - spec/poundpay/elements_spec.rb
119
+ - spec/poundpay/formats_spec.rb
120
+ - spec/poundpay/resource_spec.rb
94
121
  - spec/poundpay_spec.rb