simplificator-billboard-api 0.4.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/billboard-api.gemspec +8 -7
- data/lib/billboard-api.rb +8 -5
- data/lib/billboard-api/config.rb +83 -0
- data/lib/billboard-api/currency.rb +1 -1
- data/lib/billboard-api/customer.rb +1 -1
- data/lib/billboard-api/default_config.rb +20 -0
- data/lib/billboard-api/order.rb +38 -1
- data/lib/billboard-api/tax.rb +0 -1
- data/test/config_test.rb +62 -0
- metadata +7 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.6.1
|
data/billboard-api.gemspec
CHANGED
@@ -1,15 +1,12 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
1
|
# -*- encoding: utf-8 -*-
|
5
2
|
|
6
3
|
Gem::Specification.new do |s|
|
7
4
|
s.name = %q{billboard-api}
|
8
|
-
s.version = "0.
|
5
|
+
s.version = "0.6.1"
|
9
6
|
|
10
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
8
|
s.authors = ["simplificator"]
|
12
|
-
s.date = %q{2009-08-
|
9
|
+
s.date = %q{2009-08-25}
|
13
10
|
s.description = %q{Billboard-API is needed to add the additional models for the billboard application.}
|
14
11
|
s.email = %q{info@simplificator.com}
|
15
12
|
s.extra_rdoc_files = [
|
@@ -25,28 +22,32 @@ Gem::Specification.new do |s|
|
|
25
22
|
"VERSION",
|
26
23
|
"billboard-api.gemspec",
|
27
24
|
"lib/billboard-api.rb",
|
25
|
+
"lib/billboard-api/config.rb",
|
28
26
|
"lib/billboard-api/currency.rb",
|
29
27
|
"lib/billboard-api/customer.rb",
|
28
|
+
"lib/billboard-api/default_config.rb",
|
30
29
|
"lib/billboard-api/order.rb",
|
31
30
|
"lib/billboard-api/payment_method.rb",
|
32
31
|
"lib/billboard-api/tax.rb",
|
33
32
|
"test/billboard-api_test.rb",
|
33
|
+
"test/config_test.rb",
|
34
34
|
"test/test_helper.rb"
|
35
35
|
]
|
36
36
|
s.has_rdoc = true
|
37
37
|
s.homepage = %q{http://github.com/simplificator/billboard-api}
|
38
38
|
s.rdoc_options = ["--charset=UTF-8"]
|
39
39
|
s.require_paths = ["lib"]
|
40
|
-
s.rubygems_version = %q{1.3.
|
40
|
+
s.rubygems_version = %q{1.3.2}
|
41
41
|
s.summary = %q{TODO: one-line summary of your gem}
|
42
42
|
s.test_files = [
|
43
43
|
"test/billboard-api_test.rb",
|
44
|
+
"test/config_test.rb",
|
44
45
|
"test/test_helper.rb"
|
45
46
|
]
|
46
47
|
|
47
48
|
if s.respond_to? :specification_version then
|
48
49
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
49
|
-
s.specification_version =
|
50
|
+
s.specification_version = 3
|
50
51
|
|
51
52
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
52
53
|
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
data/lib/billboard-api.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
|
5
|
-
|
1
|
+
require 'rubygems'
|
2
|
+
require 'activeresource'
|
3
|
+
require 'singleton'
|
4
|
+
|
5
|
+
%w[order customer payment_method currency tax config default_config].each do |name|
|
6
|
+
require File.join(File.dirname(__FILE__), 'billboard-api', name)
|
7
|
+
end
|
8
|
+
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module BillboardApi
|
2
|
+
|
3
|
+
#
|
4
|
+
# Following Settings are required:
|
5
|
+
# * return_after_payment_url
|
6
|
+
# * paypal_service_url
|
7
|
+
# * paypal_notify_url
|
8
|
+
# * paypal_receiver_email
|
9
|
+
# * site_url
|
10
|
+
|
11
|
+
|
12
|
+
#
|
13
|
+
# Config is a singleton instance which can be used in two ways:
|
14
|
+
# Config.instance.setting_name1 = 12
|
15
|
+
# Config.instance.setting_name2 = 24
|
16
|
+
# or the (shorter, depending on amount of settings) form with a block
|
17
|
+
# Config.configure do |config|
|
18
|
+
# config.setting_name1= 12
|
19
|
+
# config.setting_name2= 24
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
#
|
23
|
+
# the accessors have possibility to override
|
24
|
+
# settings. This is useful for custom settings on a lower level
|
25
|
+
#
|
26
|
+
# config.setting_name1(12)
|
27
|
+
# => will return 12 all the time which does not make much sense...
|
28
|
+
# config.setting_name(options[:override_setting_name1]) will return the not-nil value from options has
|
29
|
+
# or the setting stored in config.
|
30
|
+
#
|
31
|
+
class Config
|
32
|
+
include Singleton
|
33
|
+
|
34
|
+
REQUIRED_SETTINGS = [:return_after_payment_url, :paypal_service_url, :paypal_notify_url, :paypal_receiver_email, :site_url]
|
35
|
+
|
36
|
+
# Overwrite site urls since they are directly applied to the
|
37
|
+
# Order class' class variable 'site'
|
38
|
+
def site_url(override = nil)
|
39
|
+
override || ActiveResource::Base.site
|
40
|
+
end
|
41
|
+
def site_url=(value)
|
42
|
+
ActiveResource::Base.site= value
|
43
|
+
end
|
44
|
+
|
45
|
+
# Allow access for arbitrary settings
|
46
|
+
def method_missing(m, *args)
|
47
|
+
if !m.to_s.ends_with?('=') && args.length <= 1
|
48
|
+
# return override or setting
|
49
|
+
args.first || settings[m.to_s]
|
50
|
+
elsif m.to_s.ends_with?('=') && args.length == 1
|
51
|
+
settings[m.to_s[0...-1]] = args.first
|
52
|
+
else
|
53
|
+
super(m, args)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# Helper method to ensure all settings are present.
|
58
|
+
# Will raise a StandardError if Config is invalid.
|
59
|
+
def validate!
|
60
|
+
REQUIRED_SETTINGS.each do |name|
|
61
|
+
raise "Settings '#{name}' is required. Use 'Config.instance.#{name}= VALUE' to set a value" unless self.send(name)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def clear!
|
66
|
+
@settings = {}
|
67
|
+
site_url = nil
|
68
|
+
nil
|
69
|
+
end
|
70
|
+
|
71
|
+
# Configure with a block
|
72
|
+
# will yield the instance of Config to the block.
|
73
|
+
def self.configure(&block)
|
74
|
+
config = Config.instance
|
75
|
+
yield(instance) if block_given?
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
def settings
|
80
|
+
@settings ||= {}
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
puts "default config"
|
2
|
+
BillboardApi::Config.configure do |config|
|
3
|
+
|
4
|
+
# if running from rails, then set values depending on environment
|
5
|
+
if defined? RAILS_ENV
|
6
|
+
if RAILS_ENV == 'test'
|
7
|
+
config.paypal_service_url = "https://www.sandbox.paypal.com/cgi-bin/webscr?"
|
8
|
+
elsif RAILS_ENV == 'development'
|
9
|
+
config.paypal_service_url = "https://www.sandbox.paypal.com/cgi-bin/webscr?"
|
10
|
+
elsif RAILS_ENV == 'staging'
|
11
|
+
config.paypal_service_url = "https://www.sandbox.paypal.com/cgi-bin/webscr?"
|
12
|
+
elsif RAILS_ENV == 'production'
|
13
|
+
config.paypal_service_url = "https://www.paypal.com/cgi-bin/webscr?"
|
14
|
+
end
|
15
|
+
else
|
16
|
+
puts "Not in rails, no defaults set"
|
17
|
+
end
|
18
|
+
# default values
|
19
|
+
config.site_url = 'http://billboard.garden.u2.simplificator.com'
|
20
|
+
end
|
data/lib/billboard-api/order.rb
CHANGED
@@ -1,5 +1,42 @@
|
|
1
1
|
module BillboardApi
|
2
2
|
class Order < ActiveResource::Base
|
3
|
-
|
3
|
+
|
4
|
+
# Create an URL which can be used to redirect the client to paypal.
|
5
|
+
# It will include information about the order (id), amount, currency and so on.
|
6
|
+
# Some options can be overriden by using the options hash.
|
7
|
+
# * paypal_notify_url
|
8
|
+
# * paypal_receiver_email
|
9
|
+
# * return_after_payment_url
|
10
|
+
#
|
11
|
+
def paypal_url(options = {})
|
12
|
+
values = {
|
13
|
+
:business => BillboardApi::Config.instance.paypal_receiver_email(options[:paypal_receiver_email]),
|
14
|
+
:return => BillboardApi::Config.instance.return_after_payment_url(options[:return_after_payment_url]),
|
15
|
+
:invoice => self.id,
|
16
|
+
:cmd => '_cart',
|
17
|
+
:upload => 1,
|
18
|
+
:currency_code => self.currency,
|
19
|
+
}
|
20
|
+
values[:notify_url] = BillboardApi::Config.instance.paypal_notify_url(options[:paypal_notify_url])
|
21
|
+
|
22
|
+
self.line_items_attributes.each_with_index do |line_item, index|
|
23
|
+
values.merge!({
|
24
|
+
"amount_#{index + 1}" => "%0.2f" % line_item.price_francs.to_f,
|
25
|
+
"item_name_#{index + 1}" => line_item.description,
|
26
|
+
"item_number_#{index + 1}" => line_item.id,
|
27
|
+
"quantity_#{index + 1}" => line_item.amount
|
28
|
+
})
|
29
|
+
end
|
30
|
+
|
31
|
+
unless self.vat_total == 0
|
32
|
+
values.merge!({
|
33
|
+
"amount_#{self.line_items.size + 1}" => "%0.2f" % (self.vat_total.to_f / 100),
|
34
|
+
"item_name_#{self.line_items.size + 1}" => "MwSt.",
|
35
|
+
"quantity_#{self.line_items.size + 1}" => 1
|
36
|
+
})
|
37
|
+
end
|
38
|
+
|
39
|
+
"#{BillboardApi::Config.instance.paypal_service_url}?#{values.to_query}"
|
40
|
+
end
|
4
41
|
end
|
5
42
|
end
|
data/lib/billboard-api/tax.rb
CHANGED
data/test/config_test.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'uri'
|
3
|
+
class ConfigTest < Test::Unit::TestCase
|
4
|
+
include BillboardApi
|
5
|
+
def setup
|
6
|
+
@config = Config.instance
|
7
|
+
@config.clear!
|
8
|
+
end
|
9
|
+
should "Return nil on unknown config" do
|
10
|
+
assert_equal nil, @config.test_property
|
11
|
+
end
|
12
|
+
|
13
|
+
should 'return the value upon set operation' do
|
14
|
+
assert 'test', (@config.test_property= 'test')
|
15
|
+
end
|
16
|
+
|
17
|
+
should 'store and return a setting' do
|
18
|
+
assert 'test', (@config.test_property= 'test')
|
19
|
+
assert 'test', @config.test_property
|
20
|
+
end
|
21
|
+
|
22
|
+
should 'update an existing property' do
|
23
|
+
assert 'bla', (@config.test_property= 'bla')
|
24
|
+
assert 'bla', @config.test_property
|
25
|
+
assert 'test', (@config.test_property= 'test')
|
26
|
+
assert 'test', @config.test_property
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
should 'Allow configuration trough block' do
|
31
|
+
Config.configure do |conf|
|
32
|
+
conf.foobar= 'http://foo.bar'
|
33
|
+
end
|
34
|
+
assert_equal 'http://foo.bar', @config.foobar
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
should 'allow override of setting' do
|
39
|
+
@config.bla = 12
|
40
|
+
assert_equal 13, @config.bla(13)
|
41
|
+
end
|
42
|
+
|
43
|
+
should 'validate! only if all required settings are present' do
|
44
|
+
assert_raises RuntimeError do
|
45
|
+
Config.instance.validate!
|
46
|
+
end
|
47
|
+
Config.configure do |config|
|
48
|
+
config.return_after_payment_url= '1'
|
49
|
+
config.paypal_service_url= 2
|
50
|
+
config.paypal_notify_url= 3
|
51
|
+
config.paypal_receiver_email= 4
|
52
|
+
config.site_url = 'http://localhost:3000'
|
53
|
+
end
|
54
|
+
Config.instance.validate!
|
55
|
+
end
|
56
|
+
|
57
|
+
should 'set site_url to Tax and Order' do
|
58
|
+
Config.instance.site_url = 'http://foo.bar.com'
|
59
|
+
assert_equal 'http://foo.bar.com', Order.site.to_s
|
60
|
+
assert_equal 'http://foo.bar.com', Tax.site.to_s
|
61
|
+
end
|
62
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simplificator-billboard-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- simplificator
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-08-
|
12
|
+
date: 2009-08-25 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -40,12 +40,15 @@ files:
|
|
40
40
|
- VERSION
|
41
41
|
- billboard-api.gemspec
|
42
42
|
- lib/billboard-api.rb
|
43
|
+
- lib/billboard-api/config.rb
|
43
44
|
- lib/billboard-api/currency.rb
|
44
45
|
- lib/billboard-api/customer.rb
|
46
|
+
- lib/billboard-api/default_config.rb
|
45
47
|
- lib/billboard-api/order.rb
|
46
48
|
- lib/billboard-api/payment_method.rb
|
47
49
|
- lib/billboard-api/tax.rb
|
48
50
|
- test/billboard-api_test.rb
|
51
|
+
- test/config_test.rb
|
49
52
|
- test/test_helper.rb
|
50
53
|
has_rdoc: true
|
51
54
|
homepage: http://github.com/simplificator/billboard-api
|
@@ -72,8 +75,9 @@ requirements: []
|
|
72
75
|
rubyforge_project:
|
73
76
|
rubygems_version: 1.3.5
|
74
77
|
signing_key:
|
75
|
-
specification_version:
|
78
|
+
specification_version: 3
|
76
79
|
summary: "TODO: one-line summary of your gem"
|
77
80
|
test_files:
|
78
81
|
- test/billboard-api_test.rb
|
82
|
+
- test/config_test.rb
|
79
83
|
- test/test_helper.rb
|