Skip to content

Commit 891734e

Browse files
committed
Merge pull request davidlumley#1 from ghiculescu/master
Add employee model. Add functionality for access tokens.
2 parents 1b0d0c3 + acc6c2e commit 891734e

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

lib/myob/api.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
require 'myob/api/models/company_file'
77
require 'myob/api/models/contact'
88
require 'myob/api/models/customer'
9+
require 'myob/api/models/employee'
910

1011
require 'myob/api/client'

lib/myob/api/client.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ def initialize(options)
1212
model :CompanyFile
1313
model :Contact
1414
model :Customer
15+
model :Employee
1516

17+
@redirect_uri = options[:redirect_uri]
1618
@consumer = options[:consumer]
1719
@access_token = options[:access_token]
1820
@refresh_token = options[:refresh_token]
19-
@current_company_file = {}
21+
@current_company_file = options[:selected_company_file] || {}
2022
@client = OAuth2::Client.new(@consumer[:key], @consumer[:secret], {
2123
:site => 'https://secure.myob.com',
2224
:authorize_url => '/oauth2/account/authorize',
@@ -28,6 +30,18 @@ def initialize(options)
2830
end
2931
end
3032

33+
def get_access_code_url(params = {})
34+
@client.auth_code.authorize_url(params.merge(scope: "CompanyFile", redirect_uri: @redirect_uri))
35+
end
36+
37+
def get_access_token(access_code)
38+
@token = @client.auth_code.get_token(access_code, redirect_uri: @redirect_uri)
39+
@access_token = @token.token
40+
@expires_at = @token.expires_at
41+
@refresh_token = @token.refresh_token
42+
@token
43+
end
44+
3145
def headers
3246
{
3347
'x-myobapi-key' => @consumer[:key],

lib/myob/api/models/employee.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module Myob
2+
module Api
3+
module Model
4+
class Employee < Myob::Api::Model::Base
5+
def model_route
6+
'Contact/Employee'
7+
end
8+
end
9+
end
10+
end
11+
end

0 commit comments

Comments
 (0)