aggcat 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,8 +7,16 @@ module Aggcat
7
7
  class << self
8
8
  include Aggcat::Configurable
9
9
 
10
+ def scope(customer_id)
11
+ if !defined?(@customer_id) || @customer_id != customer_id
12
+ @customer_id = customer_id
13
+ @client = Aggcat::Client.new(options.merge({customer_id: customer_id}))
14
+ end
15
+ end
16
+
10
17
  def client
11
- @client ||= Aggcat::Client.new(options)
18
+ raise ArgumentError.new('set the client scope first by calling Aggcat.scope(customer_id)') unless defined?(@customer_id)
19
+ @client
12
20
  end
13
21
 
14
22
  private
@@ -25,18 +25,17 @@ module Aggcat
25
25
 
26
26
  protected
27
27
 
28
- def access_token(user_id)
29
- token = oauth_token(user_id)
28
+ def access_token
29
+ token = oauth_token
30
30
  consumer = OAuth::Consumer.new(@consumer_key, @consumer_secret, {:timeout => TIMEOUT})
31
31
  OAuth::AccessToken.new(consumer, token[:key], token[:secret])
32
32
  end
33
33
 
34
- def oauth_token(user_id)
34
+ def oauth_token
35
35
  now = Time.now.utc
36
- if @oauth_token.nil? || @oauth_token[:expire_at] <= now || @oauth_token[:user_id] != user_id
37
- @oauth_token = new_token(saml_message(user_id))
36
+ if @oauth_token.nil? || @oauth_token[:expire_at] <= now
37
+ @oauth_token = new_token(saml_message(@customer_id))
38
38
  @oauth_token[:expire_at] = now + 9 * 60 # 9 minutes
39
- @oauth_token[:user_id] = user_id
40
39
  end
41
40
  @oauth_token
42
41
  end
@@ -4,6 +4,7 @@ module Aggcat
4
4
  BASE_URL = 'https://financialdatafeed.platform.intuit.com/rest-war/v1'
5
5
 
6
6
  def initialize(options={})
7
+ raise ArgumentError.new('customer_id is required for scoping all requests') if options[:customer_id].nil? || options[:customer_id].to_s.empty?
7
8
  Aggcat::Configurable::KEYS.each do |key|
8
9
  instance_variable_set(:"@#{key}", options[key] || Aggcat.instance_variable_get(:"@#{key}"))
9
10
  end
@@ -21,7 +22,7 @@ module Aggcat
21
22
  def discover_and_add_accounts(institution_id, username, password)
22
23
  validate(institution_id: institution_id, username: username, password: password)
23
24
  body = credentials(institution_id, username, password)
24
- post("/institutions/#{institution_id}/logins", body, {user_id: "#{institution_id}-#{username}"})
25
+ post("/institutions/#{institution_id}/logins", body)
25
26
  end
26
27
 
27
28
  def accounts
@@ -47,19 +48,19 @@ module Aggcat
47
48
  delete("/accounts/#{account_id}")
48
49
  end
49
50
 
50
- def delete_customers
51
+ def delete_customer
51
52
  delete('/customers')
52
53
  end
53
54
 
54
55
  protected
55
56
 
56
- def get(uri, options = {:user_id => 'default'})
57
- response = access_token(options[:user_id]).get("#{BASE_URL}#{uri}")
57
+ def get(uri)
58
+ response = access_token.get("#{BASE_URL}#{uri}")
58
59
  {:response_code => response.code, :response => parse_xml(response.body)}
59
60
  end
60
61
 
61
- def post(uri, message, options = {})
62
- response = access_token(options[:user_id]).post("#{BASE_URL}#{uri}", message, {'Content-Type' => 'application/xml'})
62
+ def post(uri, message)
63
+ response = access_token.post("#{BASE_URL}#{uri}", message, {'Content-Type' => 'application/xml'})
63
64
  result = {:response_code => response.code, :response => parse_xml(response.body)}
64
65
  if response['challengeSessionId']
65
66
  result[:challenge_session_id] = response['challengeSessionId']
@@ -68,8 +69,8 @@ module Aggcat
68
69
  result
69
70
  end
70
71
 
71
- def delete(uri, options = {:user_id => 'default'})
72
- response = access_token(options[:user_id]).delete("#{BASE_URL}#{uri}")
72
+ def delete(uri)
73
+ response = access_token.delete("#{BASE_URL}#{uri}")
73
74
  {:response_code => response.code, :response => parse_xml(response.body)}
74
75
  end
75
76
 
@@ -78,7 +79,7 @@ module Aggcat
78
79
  def validate(args)
79
80
  args.each do |name, value|
80
81
  if value.nil? || value.to_s.empty?
81
- raise ArgumentError, "#{name} is required"
82
+ raise ArgumentError.new("#{name} is required")
82
83
  end
83
84
  end
84
85
  end
@@ -1,9 +1,9 @@
1
1
  module Aggcat
2
2
  module Configurable
3
3
 
4
- attr_writer :issuer_id, :consumer_key, :consumer_secret, :certificate_path
4
+ attr_writer :issuer_id, :consumer_key, :consumer_secret, :certificate_path, :customer_id
5
5
 
6
- KEYS = [:issuer_id, :consumer_key, :consumer_secret, :certificate_path]
6
+ KEYS = [:issuer_id, :consumer_key, :consumer_secret, :certificate_path, :customer_id]
7
7
 
8
8
  def configure
9
9
  yield self
@@ -1,3 +1,3 @@
1
1
  module Aggcat
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aggcat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: