xero_gateway 2.4.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7df3847b8dad3d3d5c593510c72696d7a39763b3
4
- data.tar.gz: 5427008d5f2f9d14dfa3834a7125ad84af3db90c
3
+ metadata.gz: 9c288d4d30be0c8ce139ffd5b3c714f077835e47
4
+ data.tar.gz: b09d959c33ebacbf10a98509e59cf8e19d53b1f1
5
5
  SHA512:
6
- metadata.gz: 0fd76a237a99430e26b722736025353481263717be0cc0428e1c50180c6106c11b856f9aae2ea5af5452ebaf519f534f4d8e9638ac59a51b2c1cb8322ff66c73
7
- data.tar.gz: 874d4febc34ac826a6df223246c453ae8c74bdf35ecbdffd84d3d6a2ebd94f8d48d9358f8015a5a60118635558303c30ace9868e5732e996c83c48ac5d995ebc
6
+ metadata.gz: 56dc6a1fc73e3ad5118caa9c10662a64dafeef89e902dc9080053953042cd571895379622be61126c4ecfaeb79c99b5712e14230948aac614ae04dfc0dcc3800
7
+ data.tar.gz: d3906629a8c6acc8856ac23f3fb1e7f91fca06b9ad22d51d3feb6d455b69ef61cec9381deb8861530c9d860d65b8c5054c30638432e3efa895d3871a7aa20986
@@ -169,6 +169,7 @@ module XeroGateway
169
169
  request_params[:order] = options[:order] if options[:order]
170
170
  request_params[:ModifiedAfter] = options[:modified_since] if options[:modified_since]
171
171
  request_params[:ContactIDs] = Array(options[:contact_ids]).join(",") if options[:contact_ids]
172
+ request_params[:page] = options[:page] if options[:page]
172
173
 
173
174
  request_params[:where] = options[:where] if options[:where]
174
175
 
@@ -195,6 +195,7 @@ module XeroGateway
195
195
  end
196
196
  }
197
197
  b.Url url if url
198
+ b.SentToContact sent_to_contact unless sent_to_contact.nil?
198
199
  }
199
200
  end
200
201
 
@@ -22,14 +22,16 @@ module XeroGateway
22
22
  }.freeze
23
23
  end
24
24
 
25
- extend Forwardable
26
- def_delegators :access_token, :get, :post, :put, :delete
27
-
28
- attr_reader :ctoken, :csecret, :consumer_options, :authorization_expires_at
25
+ attr_reader :ctoken, :csecret, :consumer_options, :authorization_expires_at, :expires_at
29
26
  attr_accessor :session_handle
30
27
 
31
28
  def initialize(ctoken, csecret, options = {})
32
29
  @ctoken, @csecret = ctoken, csecret
30
+
31
+ # Allow user-agent base val for certification procedure (enforce for PartnerApp)
32
+ @base_headers = {}
33
+ @base_headers["User-Agent"] = options.delete(:user_agent) if options.has_key?(:user_agent)
34
+
33
35
  @consumer_options = XERO_CONSUMER_OPTIONS.merge(options)
34
36
  end
35
37
 
@@ -38,12 +40,16 @@ module XeroGateway
38
40
  end
39
41
 
40
42
  def request_token(params = {})
41
- @request_token ||= consumer.get_request_token(params)
43
+ # Underlying oauth consumer accepts body params and headers for request via positional params - explicit nilling of
44
+ # body parameters allows for correct position for headers
45
+ @request_token ||= consumer.get_request_token(params, nil, @base_headers)
42
46
  end
43
47
 
44
48
  def authorize_from_request(rtoken, rsecret, params = {})
45
49
  request_token = ::OAuth::RequestToken.new(consumer, rtoken, rsecret)
46
- access_token = request_token.get_access_token(params)
50
+ # Underlying oauth consumer accepts body params and headers for request via positional params - explicit nilling of
51
+ # body parameters allows for correct position for headers
52
+ access_token = request_token.get_access_token(params, nil, @base_headers)
47
53
  @atoken, @asecret = access_token.token, access_token.secret
48
54
 
49
55
  update_attributes_from_token(access_token)
@@ -65,10 +71,12 @@ module XeroGateway
65
71
 
66
72
  old_token = ::OAuth::RequestToken.new(consumer, access_token, access_secret)
67
73
 
74
+ # Underlying oauth consumer accepts body params and headers for request via positional params - explicit nilling of
75
+ # body parameters allows for correct position for headers
68
76
  access_token = old_token.get_access_token({
69
77
  :oauth_session_handle => session_handle,
70
78
  :token => old_token
71
- })
79
+ }, nil, @base_headers)
72
80
 
73
81
  update_attributes_from_token(access_token)
74
82
  rescue ::OAuth::Unauthorized => e
@@ -78,6 +86,22 @@ module XeroGateway
78
86
  raise XeroGateway::OAuth::TokenInvalid.new(e.message)
79
87
  end
80
88
 
89
+ def get(path, headers = {})
90
+ access_token.get(path, headers.merge(@base_headers))
91
+ end
92
+
93
+ def post(path, body = '', headers = {})
94
+ access_token.post(path, body, headers.merge(@base_headers))
95
+ end
96
+
97
+ def put(path, body = '', headers = {})
98
+ access_token.put(path, body, headers.merge(@base_headers))
99
+ end
100
+
101
+ def delete(path, headers = {})
102
+ access_token.delete(path, headers.merge(@base_headers))
103
+ end
104
+
81
105
  private
82
106
 
83
107
  # Update instance variables with those from the AccessToken.
@@ -4,11 +4,14 @@ module XeroGateway
4
4
  class CertificateRequired < StandardError; end
5
5
 
6
6
  NO_PRIVATE_KEY_ERROR_MESSAGE = "You need to provide your private key (corresponds to the public key you uploaded at api.xero.com) as :private_key_file (should be .crt or .pem files)"
7
-
7
+
8
8
  def_delegators :client, :session_handle, :renew_access_token, :authorization_expires_at
9
9
 
10
10
  def initialize(consumer_key, consumer_secret, options = {})
11
11
  raise CertificateRequired.new(NO_PRIVATE_KEY_ERROR_MESSAGE) unless options[:private_key_file]
12
+
13
+ #required by Xero for new partner apps, but only issuing warning to keep backward compat for any grandfathered apps
14
+ puts "WARNING: a unique User-Agent header is required for Xero partner apps, and is missing - this should be supplied as :user_agent" unless options[:user_agent]
12
15
 
13
16
  defaults = {
14
17
  :site => "https://api.xero.com",
@@ -1,3 +1,3 @@
1
1
  module XeroGateway
2
- VERSION = "2.4.0"
2
+ VERSION = "2.5.0"
3
3
  end
@@ -75,7 +75,20 @@ class OAuthTest < Test::Unit::TestCase
75
75
  xero.stubs(:consumer).returns(consumer)
76
76
 
77
77
  request_token = mock('request token')
78
- consumer.expects(:get_request_token).with(:oauth_callback => "http://callback.com").returns(request_token)
78
+ consumer.expects(:get_request_token).with({:oauth_callback => "http://callback.com"}, nil, {}).returns(request_token)
79
+
80
+ xero.request_token(:oauth_callback => "http://callback.com")
81
+ end
82
+
83
+ should "be able to create request token with specified base user agent" do
84
+ xero = XeroGateway::OAuth.new('token', 'secret', {user_agent: 'uagt'})
85
+ consumer = OAuth::Consumer.new('token', 'secret')
86
+ xero.stubs(:consumer).returns(consumer)
87
+
88
+ request_token = mock('request token')
89
+ consumer.expects(:get_request_token)
90
+ .with({:oauth_callback => "http://callback.com"}, nil, {"User-Agent" => 'uagt'})
91
+ .returns(request_token)
79
92
 
80
93
  xero.request_token(:oauth_callback => "http://callback.com")
81
94
  end
@@ -91,13 +104,33 @@ class OAuthTest < Test::Unit::TestCase
91
104
  access_token.stubs(:params).returns({})
92
105
 
93
106
  request_token = mock('request token')
94
- request_token.expects(:get_access_token).with(:oauth_verifier => "verifier").returns(access_token)
107
+ request_token.expects(:get_access_token).with({:oauth_verifier => "verifier"}, nil, {}).returns(access_token)
95
108
 
96
109
  OAuth::RequestToken.expects(:new).with(consumer, 'rtoken', 'rsecret').returns(request_token)
97
110
 
98
111
  xero.authorize_from_request('rtoken', 'rsecret', :oauth_verifier => "verifier")
99
112
  end
100
113
 
114
+ should "be able to create access token with specified base user agent" do
115
+ xero = XeroGateway::OAuth.new('token', 'secret', {user_agent: 'uagt'})
116
+ consumer = OAuth::Consumer.new('token', 'secret')
117
+ xero.stubs(:consumer).returns(consumer)
118
+
119
+ access_token = mock('access token')
120
+ access_token.expects(:token).twice.returns('atoken')
121
+ access_token.expects(:secret).twice.returns('asecret')
122
+ access_token.stubs(:params).returns({})
123
+
124
+ request_token = mock('request token')
125
+ request_token.expects(:get_access_token)
126
+ .with({:oauth_verifier => "verifier"}, nil, {"User-Agent" => 'uagt'})
127
+ .returns(access_token)
128
+
129
+ OAuth::RequestToken.expects(:new).with(consumer, 'rtoken', 'rsecret').returns(request_token)
130
+
131
+ xero.authorize_from_request('rtoken', 'rsecret', :oauth_verifier => "verifier")
132
+ end
133
+
101
134
  should "delegate get to access token" do
102
135
  access_token = mock('access token')
103
136
  xero = XeroGateway::OAuth.new('token', 'secret')
@@ -113,4 +146,24 @@ class OAuthTest < Test::Unit::TestCase
113
146
  access_token.expects(:post).returns(nil)
114
147
  xero.post('/foo')
115
148
  end
149
+
150
+ should "be able to specify base user-agent header for calls" do
151
+ xero = XeroGateway::OAuth.new('token', 'secret', user_agent: 'testagt')
152
+ consumer = OAuth::Consumer.new('token', 'secret')
153
+ xero.stubs(:consumer).returns(consumer)
154
+
155
+ access_token = mock('access token')
156
+ access_token.expects(:token).twice.returns('atoken')
157
+ access_token.expects(:secret).twice.returns('asecret')
158
+ access_token.stubs(:params).returns({})
159
+
160
+ request_token = mock('request token')
161
+ request_token.expects(:get_access_token).returns(access_token)
162
+ OAuth::RequestToken.expects(:new).with(consumer, 'rtoken', 'rsecret').returns(request_token)
163
+
164
+ xero.authorize_from_request('rtoken', 'rsecret')
165
+ assert xero.access_token.is_a? OAuth::AccessToken
166
+ assert_equal "atoken", xero.access_token.token
167
+ assert_equal "asecret", xero.access_token.secret
168
+ end
116
169
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xero_gateway
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Connor
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-07-12 00:00:00.000000000 Z
13
+ date: 2017-11-03 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: builder
@@ -270,7 +270,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
270
270
  version: '0'
271
271
  requirements: []
272
272
  rubyforge_project:
273
- rubygems_version: 2.6.11
273
+ rubygems_version: 2.5.1
274
274
  signing_key:
275
275
  specification_version: 4
276
276
  summary: Enables Ruby based applications to communicate with the Xero API