myob-api 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +47 -2
- data/lib/myob/api.rb +1 -0
- data/lib/myob/api/client.rb +15 -1
- data/lib/myob/api/models/employee.rb +11 -0
- data/lib/myob/api/version.rb +1 -1
- metadata +5 -4
data/README.md
CHANGED
@@ -18,6 +18,33 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
+
### OAuth Authentication
|
22
|
+
|
23
|
+
If you've already got an OAuth access token, feel free to skip to API Client Setup.
|
24
|
+
|
25
|
+
The MYOB API uses 3 legged OAuth2. If you don't want to roll your own, or use the [OmniAuth strategy](https://github.com/davidlumley/omniauth-myob) you can authenticate using the `get_access_code_url` and `get_access_token` methods that [ghiculescu](https://github.com/ghiculescu) has provided like so:
|
26
|
+
|
27
|
+
class MYOBSessionController
|
28
|
+
def new
|
29
|
+
redirect_to myob_client.get_access_code_url
|
30
|
+
end
|
31
|
+
|
32
|
+
def create
|
33
|
+
@token = myob_client.get_access_token(params[:code])
|
34
|
+
@company_files = myob_client.company_file.all
|
35
|
+
# then show the user a view where they can log in to their company file
|
36
|
+
end
|
37
|
+
|
38
|
+
def myob_client
|
39
|
+
@api_client = Myob::Api::Client.new({
|
40
|
+
:consumer => {
|
41
|
+
:key => YOUR_CONSUMER_KEY,
|
42
|
+
:secret => YOUR_CONSUMER_SECRET,
|
43
|
+
},
|
44
|
+
})
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
21
48
|
### API Client Setup
|
22
49
|
|
23
50
|
Create an api_client:
|
@@ -30,6 +57,17 @@ Create an api_client:
|
|
30
57
|
:access_token => YOUR_OAUTH_ACCESS_TOKEN,
|
31
58
|
})
|
32
59
|
|
60
|
+
If you have a refresh token (the Myob API returns one by default) you can use that too:
|
61
|
+
|
62
|
+
api_client = Myob::Api::Client.new({
|
63
|
+
:consumer => {
|
64
|
+
:key => YOUR_CONSUMER_KEY,
|
65
|
+
:secret => YOUR_CONSUMER_SECRET,
|
66
|
+
},
|
67
|
+
:access_token => YOUR_OAUTH_ACCESS_TOKEN,
|
68
|
+
:refresh_token => YOUR_OAUTH_REFRESH_TOKEN,
|
69
|
+
})
|
70
|
+
|
33
71
|
Or if you know which Company File you want to access too:
|
34
72
|
|
35
73
|
api_client = Myob::Api::Client.new({
|
@@ -37,8 +75,9 @@ Or if you know which Company File you want to access too:
|
|
37
75
|
:key => YOUR_CONSUMER_KEY,
|
38
76
|
:secret => YOUR_CONSUMER_SECRET,
|
39
77
|
},
|
40
|
-
:access_token
|
41
|
-
:
|
78
|
+
:access_token => YOUR_OAUTH_ACCESS_TOKEN,
|
79
|
+
:refresh_token => YOUR_OAUTH_REFRESH_TOKEN,
|
80
|
+
:company_file => {
|
42
81
|
:name => COMPANY_FILE_NAME,
|
43
82
|
:username => COMPANY_FILE_USERNAME,
|
44
83
|
:password => COMPANY_FILE_PASSWORD,
|
@@ -75,6 +114,12 @@ Return a list of all customers (a subset of contacts)
|
|
75
114
|
|
76
115
|
api_client.customer.all
|
77
116
|
|
117
|
+
#### Employees
|
118
|
+
|
119
|
+
Return a list of all customers (a subset of contacts)
|
120
|
+
|
121
|
+
api_client.employee.all
|
122
|
+
|
78
123
|
|
79
124
|
## Todo
|
80
125
|
|
data/lib/myob/api.rb
CHANGED
data/lib/myob/api/client.rb
CHANGED
@@ -12,11 +12,13 @@ module Myob
|
|
12
12
|
model :CompanyFile
|
13
13
|
model :Contact
|
14
14
|
model :Customer
|
15
|
+
model :Employee
|
15
16
|
|
17
|
+
@redirect_uri = options[:redirect_uri]
|
16
18
|
@consumer = options[:consumer]
|
17
19
|
@access_token = options[:access_token]
|
18
20
|
@refresh_token = options[:refresh_token]
|
19
|
-
@current_company_file = {}
|
21
|
+
@current_company_file = options[:selected_company_file] || {}
|
20
22
|
@client = OAuth2::Client.new(@consumer[:key], @consumer[:secret], {
|
21
23
|
:site => 'https://secure.myob.com',
|
22
24
|
:authorize_url => '/oauth2/account/authorize',
|
@@ -28,6 +30,18 @@ module Myob
|
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
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
|
+
|
31
45
|
def headers
|
32
46
|
{
|
33
47
|
'x-myobapi-key' => @consumer[:key],
|
data/lib/myob/api/version.rb
CHANGED
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.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-11-
|
12
|
+
date: 2013-11-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: oauth2
|
@@ -78,6 +78,7 @@ files:
|
|
78
78
|
- lib/myob/api/models/company_file.rb
|
79
79
|
- lib/myob/api/models/contact.rb
|
80
80
|
- lib/myob/api/models/customer.rb
|
81
|
+
- lib/myob/api/models/employee.rb
|
81
82
|
- lib/myob/api/version.rb
|
82
83
|
- myob-api.gemspec
|
83
84
|
homepage: https://github.com/davidlumley/myob-api
|
@@ -95,7 +96,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
96
|
version: '0'
|
96
97
|
segments:
|
97
98
|
- 0
|
98
|
-
hash:
|
99
|
+
hash: 593053203672766037
|
99
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
101
|
none: false
|
101
102
|
requirements:
|
@@ -104,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
105
|
version: '0'
|
105
106
|
segments:
|
106
107
|
- 0
|
107
|
-
hash:
|
108
|
+
hash: 593053203672766037
|
108
109
|
requirements: []
|
109
110
|
rubyforge_project:
|
110
111
|
rubygems_version: 1.8.23
|