simplificator-billboard-api 0.7.2 → 0.9.1

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/Rakefile CHANGED
@@ -10,7 +10,7 @@ begin
10
10
  gem.email = "info@simplificator.com"
11
11
  gem.homepage = "http://github.com/simplificator/billboard-api"
12
12
  gem.authors = ["simplificator"]
13
- gem.add_development_dependency "thoughtbot-shoulda"
13
+ gem.add_development_dependency "shoulda"
14
14
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
15
  end
16
16
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.2
1
+ 0.9.1
@@ -1,8 +1,8 @@
1
- require 'rubygems'
2
- require 'activeresource'
3
- require 'singleton'
1
+ require "rubygems"
2
+ require "active_resource"
3
+ require "singleton"
4
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)
5
+ %w[config remote_resource order customer payment_method currency tax].each do |name|
6
+ require File.join(File.dirname(__FILE__), "billboard-api", name)
7
7
  end
8
8
 
@@ -1,83 +1,29 @@
1
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
2
  class Config
32
3
  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
4
+
5
+ attr_reader :url
6
+ attr_accessor :paypal_service_url
7
+
8
+ def initialize
9
+ if production?
10
+ self.url = "https://simplebillboard.com"
11
+ self.paypal_service_url = "https://www.paypal.com/cgi-bin/webscr?"
52
12
  else
53
- super(m, args)
13
+ self.url = "https://simplebillboard.com.simplificator.com"
14
+ self.paypal_service_url = "https://www.sandbox.paypal.com/cgi-bin/webscr?"
54
15
  end
55
16
  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?
17
+
18
+ def url=(value)
19
+ RemoteResource.site = value
20
+ @url = value
76
21
  end
77
-
22
+
78
23
  private
79
- def settings
80
- @settings ||= {}
24
+
25
+ def production?
26
+ !(defined? Rails) || Rails.env.production?
81
27
  end
82
28
  end
83
29
  end
@@ -1,5 +1,4 @@
1
1
  module BillboardApi
2
- class Currency < ActiveResource::Base
3
- # self.site = "http://billboard.garden.u2.simplificator.com"
2
+ class Currency < RemoteResource
4
3
  end
5
4
  end
@@ -1,5 +1,4 @@
1
1
  module BillboardApi
2
- class Customer < ActiveResource::Base
3
- # self.site = "http://billboard.garden.u2.simplificator.com"
2
+ class Customer < RemoteResource
4
3
  end
5
4
  end
@@ -1,42 +1,4 @@
1
1
  module BillboardApi
2
- class Order < ActiveResource::Base
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.business_id}_#{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
2
+ class Order < RemoteResource
41
3
  end
42
4
  end
@@ -1,5 +1,4 @@
1
1
  module BillboardApi
2
- class PaymentMethod < ActiveResource::Base
3
- # self.site = "http://billboard.garden.u2.simplificator.com"
2
+ class PaymentMethod < RemoteResource
4
3
  end
5
4
  end
@@ -0,0 +1,16 @@
1
+ module BillboardApi
2
+ class Queue < ActiveRecord::Base
3
+ serialize :serialized_order
4
+ serialize :serialized_customer
5
+
6
+
7
+ # name retry is a keyword in ruby
8
+ def try_again
9
+ customer = self.serialized_customer
10
+ order = self.serialized_order
11
+ order.customer_id = customer.id # ID from Billboard
12
+
13
+ order.save # request to billboard
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,6 @@
1
+ module BillboardApi
2
+ # Common superclass to all ActiveResources in Billboard.
3
+ class RemoteResource < ActiveResource::Base
4
+ self.site = BillboardApi::Config.instance.url
5
+ end
6
+ end
@@ -1,4 +1,4 @@
1
1
  module BillboardApi
2
- class Tax < ActiveResource::Base
2
+ class Tax < RemoteResource
3
3
  end
4
4
  end
@@ -0,0 +1,61 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{simplificator-billboard-api}
8
+ s.version = "0.9.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["simplificator"]
12
+ s.date = %q{2011-03-11}
13
+ s.description = %q{Billboard-API is needed to add the additional models for the billboard application.}
14
+ s.email = %q{info@simplificator.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "lib/billboard-api.rb",
26
+ "lib/billboard-api/config.rb",
27
+ "lib/billboard-api/currency.rb",
28
+ "lib/billboard-api/customer.rb",
29
+ "lib/billboard-api/order.rb",
30
+ "lib/billboard-api/payment_method.rb",
31
+ "lib/billboard-api/queue.rb",
32
+ "lib/billboard-api/remote_resource.rb",
33
+ "lib/billboard-api/tax.rb",
34
+ "simplificator-billboard-api.gemspec",
35
+ "test/billboard-api_test.rb",
36
+ "test/config_test.rb",
37
+ "test/test_helper.rb"
38
+ ]
39
+ s.homepage = %q{http://github.com/simplificator/billboard-api}
40
+ s.require_paths = ["lib"]
41
+ s.rubygems_version = %q{1.5.0}
42
+ s.summary = %q{Billboard API gem}
43
+ s.test_files = [
44
+ "test/billboard-api_test.rb",
45
+ "test/config_test.rb",
46
+ "test/test_helper.rb"
47
+ ]
48
+
49
+ if s.respond_to? :specification_version then
50
+ s.specification_version = 3
51
+
52
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
53
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
54
+ else
55
+ s.add_dependency(%q<shoulda>, [">= 0"])
56
+ end
57
+ else
58
+ s.add_dependency(%q<shoulda>, [">= 0"])
59
+ end
60
+ end
61
+
@@ -2,60 +2,13 @@ require 'test_helper'
2
2
  require 'uri'
3
3
  class ConfigTest < Test::Unit::TestCase
4
4
  include BillboardApi
5
+
5
6
  def setup
6
7
  @config = Config.instance
7
- @config.clear!
8
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'
9
+
10
+ should 'set url to Tax and Order' do
11
+ Config.instance.url = 'http://foo.bar.com'
59
12
  assert_equal 'http://foo.bar.com', Order.site.to_s
60
13
  assert_equal 'http://foo.bar.com', Tax.site.to_s
61
14
  end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplificator-billboard-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 9
8
+ - 1
9
+ version: 0.9.1
5
10
  platform: ruby
6
11
  authors:
7
12
  - simplificator
@@ -9,19 +14,21 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2009-11-04 00:00:00 +01:00
17
+ date: 2011-03-11 00:00:00 +01:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
- name: thoughtbot-shoulda
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
21
+ name: shoulda
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
23
29
  version: "0"
24
- version:
30
+ type: :development
31
+ version_requirements: *id001
25
32
  description: Billboard-API is needed to add the additional models for the billboard application.
26
33
  email: info@simplificator.com
27
34
  executables: []
@@ -33,20 +40,20 @@ extra_rdoc_files:
33
40
  - README.rdoc
34
41
  files:
35
42
  - .document
36
- - .gitignore
37
43
  - LICENSE
38
44
  - README.rdoc
39
45
  - Rakefile
40
46
  - VERSION
41
- - billboard-api.gemspec
42
47
  - lib/billboard-api.rb
43
48
  - lib/billboard-api/config.rb
44
49
  - lib/billboard-api/currency.rb
45
50
  - lib/billboard-api/customer.rb
46
- - lib/billboard-api/default_config.rb
47
51
  - lib/billboard-api/order.rb
48
52
  - lib/billboard-api/payment_method.rb
53
+ - lib/billboard-api/queue.rb
54
+ - lib/billboard-api/remote_resource.rb
49
55
  - lib/billboard-api/tax.rb
56
+ - simplificator-billboard-api.gemspec
50
57
  - test/billboard-api_test.rb
51
58
  - test/config_test.rb
52
59
  - test/test_helper.rb
@@ -55,26 +62,28 @@ homepage: http://github.com/simplificator/billboard-api
55
62
  licenses: []
56
63
 
57
64
  post_install_message:
58
- rdoc_options:
59
- - --charset=UTF-8
65
+ rdoc_options: []
66
+
60
67
  require_paths:
61
68
  - lib
62
69
  required_ruby_version: !ruby/object:Gem::Requirement
63
70
  requirements:
64
71
  - - ">="
65
72
  - !ruby/object:Gem::Version
73
+ segments:
74
+ - 0
66
75
  version: "0"
67
- version:
68
76
  required_rubygems_version: !ruby/object:Gem::Requirement
69
77
  requirements:
70
78
  - - ">="
71
79
  - !ruby/object:Gem::Version
80
+ segments:
81
+ - 0
72
82
  version: "0"
73
- version:
74
83
  requirements: []
75
84
 
76
85
  rubyforge_project:
77
- rubygems_version: 1.3.5
86
+ rubygems_version: 1.3.6
78
87
  signing_key:
79
88
  specification_version: 3
80
89
  summary: Billboard API gem
data/.gitignore DELETED
@@ -1,6 +0,0 @@
1
- *.sw?
2
- .DS_Store
3
- coverage
4
- rdoc
5
- pkg
6
- nbproject
@@ -1,63 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{billboard-api}
8
- s.version = "0.7.1"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["simplificator"]
12
- s.date = %q{2009-08-28}
13
- s.description = %q{Billboard-API is needed to add the additional models for the billboard application.}
14
- s.email = %q{info@simplificator.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "billboard-api.gemspec",
27
- "lib/billboard-api.rb",
28
- "lib/billboard-api/config.rb",
29
- "lib/billboard-api/currency.rb",
30
- "lib/billboard-api/customer.rb",
31
- "lib/billboard-api/default_config.rb",
32
- "lib/billboard-api/order.rb",
33
- "lib/billboard-api/payment_method.rb",
34
- "lib/billboard-api/tax.rb",
35
- "test/billboard-api_test.rb",
36
- "test/config_test.rb",
37
- "test/test_helper.rb"
38
- ]
39
- s.has_rdoc = true
40
- s.homepage = %q{http://github.com/simplificator/billboard-api}
41
- s.rdoc_options = ["--charset=UTF-8"]
42
- s.require_paths = ["lib"]
43
- s.rubygems_version = %q{1.3.1}
44
- s.summary = %q{TODO: one-line summary of your gem}
45
- s.test_files = [
46
- "test/billboard-api_test.rb",
47
- "test/config_test.rb",
48
- "test/test_helper.rb"
49
- ]
50
-
51
- if s.respond_to? :specification_version then
52
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
53
- s.specification_version = 2
54
-
55
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
56
- s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
57
- else
58
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
59
- end
60
- else
61
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
62
- end
63
- end
@@ -1,20 +0,0 @@
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