myob-api 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,12 @@
1
1
  require 'Base64'
2
+ require 'oauth2'
2
3
 
3
4
  module Myob
4
5
  module Api
5
6
  class Client
6
7
  include Myob::Api::Helpers
7
8
 
8
- attr_reader :current_company_file
9
+ attr_reader :current_company_file, :client
9
10
 
10
11
  def initialize(options)
11
12
  model :CompanyFile
@@ -14,8 +15,13 @@ module Myob
14
15
 
15
16
  @consumer = options[:consumer]
16
17
  @access_token = options[:access_token]
18
+ @refresh_token = options[:refresh_token]
17
19
  @current_company_file = {}
18
- @client = OAuth2::Client.new(@consumer[:key], @consumer[:secret])
20
+ @client = OAuth2::Client.new(@consumer[:key], @consumer[:secret], {
21
+ :site => 'https://secure.myob.com',
22
+ :authorize_url => '/oauth2/account/authorize',
23
+ :token_url => '/oauth2/v1/authorize',
24
+ })
19
25
 
20
26
  if options[:company_file]
21
27
  @current_company_file = select_company_file(options[:company_file])
@@ -39,8 +45,15 @@ module Myob
39
45
  end
40
46
 
41
47
  def connection
42
- @auth_connection ||= OAuth2::AccessToken.new(@client, @access_token)
48
+ if @refresh_token
49
+ @auth_connection ||= OAuth2::AccessToken.new(@client, @access_token, {
50
+ :refresh_token => @refresh_token
51
+ }).refresh!
52
+ else
53
+ @auth_connection ||= OAuth2::AccessToken.new(@client, @access_token)
54
+ end
43
55
  end
56
+
44
57
  end
45
58
  end
46
59
  end
@@ -1,5 +1,5 @@
1
1
  module Myob
2
2
  module Api
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.add_dependency "oauth2", "~> 0.8"
22
+
21
23
  spec.add_development_dependency "bundler", "~> 1.3"
22
24
  spec.add_development_dependency "rake"
23
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: myob-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-22 00:00:00.000000000 Z
12
+ date: 2013-11-14 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: oauth2
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '0.8'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '0.8'
14
30
  - !ruby/object:Gem::Dependency
15
31
  name: bundler
16
32
  requirement: !ruby/object:Gem::Requirement
@@ -79,7 +95,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
79
95
  version: '0'
80
96
  segments:
81
97
  - 0
82
- hash: -4044968237575791843
98
+ hash: 4098228060394924892
83
99
  required_rubygems_version: !ruby/object:Gem::Requirement
84
100
  none: false
85
101
  requirements:
@@ -88,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
104
  version: '0'
89
105
  segments:
90
106
  - 0
91
- hash: -4044968237575791843
107
+ hash: 4098228060394924892
92
108
  requirements: []
93
109
  rubyforge_project:
94
110
  rubygems_version: 1.8.23