kelredd-wesabe 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -19,8 +19,7 @@ spec = Gem::Specification.new do |s|
19
19
  s.files = %w(README.rdoc Rakefile) + Dir.glob("{lib,test}/**/*")
20
20
  # s.executables = ['wesabe']
21
21
 
22
- s.add_dependency('nokogiri', '> 1.2.3')
23
- s.add_dependency('rest-client', '> 0.9.2')
22
+ s.add_dependency('kelredd-resourceful', '>= 0.3.0')
24
23
  end
25
24
 
26
25
  Rake::GemPackageTask.new(spec) do |pkg|
@@ -34,7 +33,7 @@ Rake::TestTask.new do |t|
34
33
  end
35
34
 
36
35
  desc 'Generate the gemspec to serve this Gem from Github'
37
- task :github do
36
+ task :gemspec do
38
37
  file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
39
38
  File.open(file, 'w') {|f| f << spec.to_ruby }
40
39
  puts "Created gemspec: #{file}"
@@ -1,8 +1,4 @@
1
1
  module Wesabe
2
2
  class NotConfigured < StandardError
3
3
  end
4
- class ResourceAPIError < StandardError
5
- end
6
- class ResourceParseError < StandardError
7
- end
8
4
  end
@@ -9,21 +9,21 @@ module Wesabe
9
9
  def self.find(id)
10
10
  case id
11
11
  when :all
12
- find_collection("/accounts", "//accounts/account")
12
+ get_collection("/accounts", {}, "//accounts/account")
13
13
  else
14
- super("/accounts/#{id}", "//account")
14
+ get("/accounts/#{id}", {}, "//account")
15
15
  end
16
16
  end
17
17
 
18
- attribute :id, :integer, :path => "id"
18
+ attribute :id, :integer
19
19
  attribute :key, :string, :path => "guid"
20
20
  attribute :number, :string, :path => "account-number"
21
- attribute :name, :string, :path => "name"
21
+ attribute :name, :string
22
22
  attribute :account_type, :string, :path => "account-type"
23
23
  attribute :balance, :float, :path => "current-balance"
24
24
  attribute :last_uploaded_at, :datetime, :path => "last-uploaded-at"
25
- attribute :oldest_transaction_on, :date, :path => "oldest-txaction"
26
- attribute :newest_transaction_on, :date, :path => "newest-txaction"
25
+ attribute :oldest_txaction_on, :date, :path => "oldest-txaction"
26
+ attribute :newest_txaction_on, :date, :path => "newest-txaction"
27
27
 
28
28
  def institution
29
29
  @institution ||= Wesabe::Model::Institution.new(get_node('./financial-institution'))
@@ -1,136 +1,31 @@
1
- %w(rubygems rest_client nokogiri).each do |lib|
2
- require lib
3
- end
4
- %w(configuration exceptions extensions).each do |file|
5
- require File.join(File.dirname(__FILE__), "..", "#{file}.rb")
6
- end
7
-
8
1
  module Wesabe
9
2
  module Model
10
-
11
- class Base
12
- @@user = nil
13
- @@password = nil
14
- @@content_type = Wesabe::API_DEFAULT_CONTENT_TYPE
15
-
16
- def self.resource
17
- RestClient::Resource.new(Wesabe::API_SITE, :user => @@user, :password => @@password, :content_type => @@content_type)
18
- end
19
- @@api = resource
20
- @@api_cache = {}
3
+ class Base < Resourceful::Model::Xml
21
4
 
22
- attr_reader :xml
23
-
24
5
  def self.configure(opts={})
25
- @@user = opts[:user]
26
- @@password = opts[:password]
27
- @@content_type = opts[:content_type] if opts[:content_type] && Wesabe::API_CONTENT_TYPES.include?(opts[:content_type])
28
- @@api = resource
6
+ raise Wesabe::NotConfigured, "No user provided to access the Wesabe API" if blank?(opts[:user])
7
+ raise Wesabe::NotConfigured, "No password provided to access the Wesabe API" if blank?(opts[:password])
8
+ agent RestClient::Resource.new('https://www.wesabe.com', :user => opts[:user], :password => opts[:password])
29
9
  end
30
10
 
31
- def self.find(path, xpath)
32
- new(get_xml(path).xpath(xpath))
33
- end
34
- def self.find_collection(path, xpath)
35
- get_xml(path).xpath(xpath).collect{|item_xml| new(item_xml)}
36
- end
37
-
38
- def initialize(xml)
39
- @xml = xml
40
- end
41
-
42
11
  protected
43
-
44
- def self.get_xml(path)
45
- self.resource_xml(:get, path)
46
- end
47
- def self.resource_xml(verb, path, force=false)
48
- summary = "#{verb.to_s.upcase} #{@@api.url}#{path}"
49
- key = cache_key(verb, path)
50
- begin
51
- resp = @@api_cache[key]
52
- if resp.nil? || force
53
- base_config_check
54
- p "** Wesabe API: #{summary}"
55
- resp = case verb.to_sym
56
- when :get
57
- @@api["#{path}"].get
58
- end
59
- @@api_cache[key] = resp
60
- else
61
- p "** Wesabe API: [cache] #{summary}."
62
- end
63
- rescue Exception => err
64
- raise Wesabe::ResourceAPIError, "error with API resource: #{summary}: #{err.message}"
65
- end
66
- begin
67
- xml = Nokogiri::XML(resp.to_s)
68
- rescue Exception => err
69
- raise Wesabe::ResourceParseError, "error parsing API resource [#{@@content_type}]: #{summary}: #{err.message}: Response: #{resp.to_s}"
70
- end
71
- xml
72
- end
73
12
 
74
- def self.attribute(name, type, config)
75
- raise Wesabe::NotConfigured, "no path provided for selecting the attribute '#{name}'." unless config[:path]
76
- content_method = case type.to_sym
77
- when :string
78
- 'to_s'
79
- when :integer
80
- 'to_i'
81
- when :float
82
- 'to_f'
83
- when :date
84
- 'to_date'
85
- when :datetime
86
- 'to_datetime'
87
- else
88
- 'to_s'
89
- end
90
- define_method(name) do
91
- instance_variable_get("@#{name}") || instance_variable_set("@#{name}", get_node("./#{config[:path]}").content.send(content_method))
92
- end
93
- end
94
- def self.get_node(xml, path)
95
- xml.xpath(path.to_s).first
96
- end
97
- def get_node(path)
98
- self.class.get_node(@xml, path)
13
+ def self.get(resource, params, xpath)
14
+ raise Wesabe::NotConfigured, "Wesabe not configured to access the API." if blank?(@agent)
15
+ super(resource, params, xpath)
99
16
  end
100
17
 
101
- def self.xml_root_name(xml)
102
- xml.root.name
103
- end
104
- def xml_root_name
105
- self.class.xml_root_name(@xml)
18
+ def self.get_collection(resource, params, xpath)
19
+ raise Wesabe::NotConfigured, "Wesabe not configured to access the API." if blank?(@agent)
20
+ super(resource, params, xpath)
106
21
  end
107
22
 
108
- def self.cache_key(path, verb)
109
- "#{verb}_#{path}"
110
- end
23
+ private
111
24
 
112
- def self.clear_cache
113
- @@api_cache = {}
114
- end
115
-
116
- def self.base_config_check
117
- raise Wesabe::NotConfigured, "No user provided to access the Wesabe API" if blank?(@@user)
118
- raise Wesabe::NotConfigured, "No password provided to access the Wesabe API" if blank?(@@password)
119
- raise Wesabe::NotConfigured, "Wesabe not configured to access the API." if blank?(@@api)
120
- end
121
- def base_config_check
122
- self.class.base_config_check
123
- end
124
-
125
25
  def self.blank?(value)
126
26
  value.nil? || (value.respond_to?('empty?') ? value.empty? : false)
127
27
  end
128
- def blank?(value)
129
- self.class.blank?(value)
130
- end
131
-
132
28
 
133
29
  end
134
-
135
30
  end
136
31
  end
@@ -8,7 +8,7 @@ module Wesabe
8
8
  class Institution < Wesabe::Model::Base
9
9
 
10
10
  attribute :key, :string, :path => "id"
11
- attribute :name, :string, :path => "name"
11
+ attribute :name, :string
12
12
 
13
13
  end
14
14
 
@@ -8,7 +8,7 @@ module Wesabe
8
8
  class Merchant < Wesabe::Model::Base
9
9
 
10
10
  attribute :key, :string, :path => "id"
11
- attribute :name, :string, :path => "name"
11
+ attribute :name, :string
12
12
 
13
13
  end
14
14
 
@@ -8,20 +8,18 @@ module Wesabe
8
8
 
9
9
  def self.find(opts={})
10
10
  acct = opts.delete(:account)
11
- path = (acct ? "/accounts/#{acct.to_s}.xml" : "/transactions.xml")
12
- path += opts.to_http_query_str if opts.respond_to?('to_http_query_str')
13
- find_collection(path, "//txactions/txaction")
11
+ get_collection((acct ? "/accounts/#{acct.to_s}" : "/transactions"), opts, "//txactions/txaction")
14
12
  end
15
13
 
16
14
  attribute :key, :string, :path => "guid"
17
15
  attribute :account_id, :string, :path => "account-id"
18
- attribute :date, :date, :path => "date"
16
+ attribute :date, :date
19
17
  attribute :original_date, :date, :path => "original-date"
20
- attribute :amount, :float, :path => "amount"
18
+ attribute :amount, :float
21
19
  attribute :display_name, :string, :path => "display-name"
22
20
  attribute :raw_name, :string, :path => "raw-name"
23
21
  attribute :raw_type, :string, :path => "raw-txntype"
24
- attribute :memo, :string, :path => "memo"
22
+ attribute :memo, :string
25
23
  attribute :transfer_key, :string, :path => "transfer/guid"
26
24
 
27
25
  def account
@@ -2,8 +2,8 @@ module Wesabe
2
2
  module Version
3
3
 
4
4
  MAJOR = 0
5
- MINOR = 0
6
- TINY = 2
5
+ MINOR = 1
6
+ TINY = 0
7
7
 
8
8
  def self.to_s # :nodoc:
9
9
  [MAJOR, MINOR, TINY].join('.')
data/lib/wesabe.rb CHANGED
@@ -1,4 +1,7 @@
1
- $:.unshift File.dirname(__FILE__)
2
-
3
- require 'wesabe/model'
1
+ %w(rubygems resourceful).each do |lib|
2
+ require lib
3
+ end
4
4
 
5
+ %w(exceptions model).each do |file|
6
+ require File.join(File.dirname(__FILE__), 'wesabe', "#{file}.rb")
7
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kelredd-wesabe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelly Redding
@@ -9,28 +9,18 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-15 00:00:00 -07:00
12
+ date: 2009-07-24 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: nokogiri
16
+ name: kelredd-resourceful
17
17
  type: :runtime
18
18
  version_requirement:
19
19
  version_requirements: !ruby/object:Gem::Requirement
20
20
  requirements:
21
- - - ">"
21
+ - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 1.2.3
24
- version:
25
- - !ruby/object:Gem::Dependency
26
- name: rest-client
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">"
32
- - !ruby/object:Gem::Version
33
- version: 0.9.2
23
+ version: 0.3.0
34
24
  version:
35
25
  description:
36
26
  email: kelly@kelredd.com
@@ -44,9 +34,7 @@ files:
44
34
  - README.rdoc
45
35
  - Rakefile
46
36
  - lib/wesabe
47
- - lib/wesabe/configuration.rb
48
37
  - lib/wesabe/exceptions.rb
49
- - lib/wesabe/extensions.rb
50
38
  - lib/wesabe/model
51
39
  - lib/wesabe/model/account.rb
52
40
  - lib/wesabe/model/base.rb
@@ -1,5 +0,0 @@
1
- module Wesabe
2
- API_SITE = 'https://www.wesabe.com'
3
- API_CONTENT_TYPES = ['application/xml']
4
- API_DEFAULT_CONTENT_TYPE = API_CONTENT_TYPES.first
5
- end
@@ -1,60 +0,0 @@
1
- require 'cgi'
2
-
3
- module Wesabe
4
- module Extensions
5
- module String
6
-
7
- module ClassMethods; end
8
- def self.included(klass)
9
- klass.extend(ClassMethods) if klass.kind_of?(Class)
10
- end
11
-
12
- module ClassMethods
13
- end
14
-
15
- def to_datetime
16
- DateTime.strptime(self) rescue nil
17
- end
18
- def to_date
19
- Date.strptime(self) rescue nil
20
- end
21
-
22
- end
23
- end
24
- end
25
-
26
- module Wesabe
27
- module Extensions
28
- module Hash
29
-
30
- module ClassMethods; end
31
- def self.included(klass)
32
- klass.extend(ClassMethods) if klass.kind_of?(Class)
33
- end
34
-
35
- module ClassMethods
36
- end
37
-
38
- # Returns string formatted for HTTP URL encoded name-value pairs.
39
- # For example,
40
- # {:id => 'thomas_hardy'}.to_http_str
41
- # # => "id=thomas_hardy"
42
- # {:id => 23423, :since => Time.now}.to_http_str
43
- # # => "since=Thu,%2021%20Jun%202007%2012:10:05%20-0500&id=23423"
44
- def to_http_query_str(opts = {})
45
- opts[:prepend] ||= '?'
46
- opts[:append] ||= ''
47
- self.empty? ? '' : "#{opts[:prepend]}#{self.collect{|key, val| "#{key.to_s}=#{CGI.escape(val.to_s)}"}.join('&')}#{opts[:append]}"
48
- end
49
-
50
- end
51
- end
52
- end
53
-
54
- class String
55
- include Wesabe::Extensions::String
56
- end
57
-
58
- class Hash
59
- include Wesabe::Extensions::Hash
60
- end