redline 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/README.rdoc +19 -2
  2. data/Rakefile +1 -0
  3. data/VERSION +1 -1
  4. data/lib/redline.rb +48 -0
  5. data/redline.gemspec +5 -2
  6. metadata +12 -2
data/README.rdoc CHANGED
@@ -1,6 +1,23 @@
1
- = redline
1
+ = RedLine
2
2
 
3
- Description goes here.
3
+ Braintree via Redline: riding the rails
4
+
5
+ Automatically makes creation/deletion/update scripts for your model, translating and syncing them with a Braintree customer profile.
6
+
7
+ Planning on adding extremely light-weight subscription support.
8
+
9
+
10
+ class User < ActiveRecord::Base
11
+ acts_as_braintree_customer :business_name => :company, :firstname => :first_name, :lastname => :last_name
12
+ attr_accessible :firstname, :lastname, :website, :email, :business_name, :password, :password_confirmation
13
+ end
14
+
15
+ acts_as_braintree_customer takes an optional series of attributes that represent an attribute[] mapper
16
+
17
+ james = User.find(1) #=> <User id: 1, firstname: "James", lastname: "Daniels", business_name: "MarginLeft, LLC", email: 'james@jamesdaniels.net', website: 'http://www.marginleft.com', crypted_password: "45fres8...", persistence_token: "4jsdf88...", ...>
18
+ james.customer #=> <Braintree::Customer id: "9999999", first_name: "James", last_name: "Daniels", company: "MarginLeft, LLC", email: "james@jamesdaniels.net", website: "http://www.marginleft.com", ..., addresses: [], credit_cards: []>
19
+
20
+ More to come.
4
21
 
5
22
  == Note on Patches/Pull Requests
6
23
 
data/Rakefile CHANGED
@@ -12,6 +12,7 @@ begin
12
12
  gem.authors = ["James Daniels"]
13
13
  gem.add_development_dependency "rspec", ">= 1.2.9"
14
14
  gem.add_development_dependency "braintree"
15
+ gem.add_development_dependency "active_record"
15
16
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
17
  end
17
18
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.1.0
data/lib/redline.rb CHANGED
@@ -0,0 +1,48 @@
1
+ class Hash
2
+ def rewrite mapping
3
+ inject({}) do |rewritten_hash, (original_key, value)|
4
+ rewritten_hash[mapping.fetch(original_key, original_key)] = value
5
+ rewritten_hash
6
+ end
7
+ end
8
+ end
9
+
10
+ module RedLine
11
+ def acts_as_braintree_customer(attribute_rewriting)
12
+ send :include, RedLine::Customer
13
+ send 'braintree_customer=', attribute_rewriting
14
+ end
15
+ module Customer
16
+ def self.included(base)
17
+ base.class_eval do
18
+ send :extend, ActiveSupport::Memoizable
19
+ send :include, InstanceMethods
20
+ memoize :customer
21
+ before_create :create_customer
22
+ before_update :update_customer
23
+ before_destroy :delete_customer
24
+ cattr_accessor :braintree_customer
25
+ end
26
+ end
27
+ module InstanceMethods
28
+ def braintree_customer_attributes
29
+ wanted_attributes = Braintree::Customer._create_signature.reject{|a| a.is_a? Hash}.reject{|a| a == :id}
30
+ attributes.symbolize_keys.rewrite(self.class.braintree_customer || {}).reject{|key, value| !wanted_attributes.include?(key)}
31
+ end
32
+ def customer
33
+ Braintree::Customer.find(customer_id)
34
+ end
35
+ def create_customer
36
+ self.customer_id = Braintree::Customer.create!(braintree_customer_attributes).id
37
+ end
38
+ def update_customer
39
+ Braintree::Customer.update!(customer_id, braintree_customer_attributes) && flush_cache(:customer)
40
+ end
41
+ def delete_customer
42
+ Braintree::Customer.delete(customer_id)
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ ActiveRecord::Base.extend RedLine
data/redline.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{redline}
8
- s.version = "0.0.0"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["James Daniels"]
12
- s.date = %q{2010-01-18}
12
+ s.date = %q{2010-01-19}
13
13
  s.description = %q{Manual subscriptions via the Braintree gem}
14
14
  s.email = %q{james@jamesdaniels.net}
15
15
  s.extra_rdoc_files = [
@@ -46,13 +46,16 @@ Gem::Specification.new do |s|
46
46
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
47
47
  s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
48
48
  s.add_development_dependency(%q<braintree>, [">= 0"])
49
+ s.add_development_dependency(%q<active_record>, [">= 0"])
49
50
  else
50
51
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
51
52
  s.add_dependency(%q<braintree>, [">= 0"])
53
+ s.add_dependency(%q<active_record>, [">= 0"])
52
54
  end
53
55
  else
54
56
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
55
57
  s.add_dependency(%q<braintree>, [">= 0"])
58
+ s.add_dependency(%q<active_record>, [">= 0"])
56
59
  end
57
60
  end
58
61
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Daniels
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-18 00:00:00 -05:00
12
+ date: 2010-01-19 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -32,6 +32,16 @@ dependencies:
32
32
  - !ruby/object:Gem::Version
33
33
  version: "0"
34
34
  version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: active_record
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
35
45
  description: Manual subscriptions via the Braintree gem
36
46
  email: james@jamesdaniels.net
37
47
  executables: []