Skip to content

Commit 5b8eae4

Browse files
committed
finish merge
2 parents 43d5737 + 20d20de commit 5b8eae4

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

.rbenv-gemsets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
myob-api

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,33 @@ Or install it yourself as:
1818

1919
## Usage
2020

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+
2148
### API Client Setup
2249

2350
Create an api_client:
@@ -87,6 +114,12 @@ Return a list of all customers (a subset of contacts)
87114

88115
api_client.customer.all
89116

117+
#### Employees
118+
119+
Return a list of all employees
120+
121+
api_client.employee.all
122+
90123

91124
## Todo
92125

@@ -102,3 +135,7 @@ Return a list of all customers (a subset of contacts)
102135
3. Commit your changes (`git commit -am 'Add some feature'`)
103136
4. Push to the branch (`git push origin my-new-feature`)
104137
5. Create new Pull Request
138+
139+
140+
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/davidlumley/myob-api/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
141+

lib/myob/api/client.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ def initialize(options)
3838
end
3939

4040
def get_access_code_url(params = {})
41-
@client.auth_code.authorize_url(params.merge(scope: "CompanyFile", redirect_uri: @redirect_uri))
41+
@client.auth_code.authorize_url(params.merge(scope: 'CompanyFile', redirect_uri: @redirect_uri))
4242
end
4343

4444
def get_access_token(access_code)
45-
@token = @client.auth_code.get_token(access_code, redirect_uri: @redirect_uri)
46-
@access_token = @token.token
47-
@expires_at = @token.expires_at
45+
@token = @client.auth_code.get_token(access_code, redirect_uri: @redirect_uri)
46+
@access_token = @token.token
47+
@expires_at = @token.expires_at
4848
@refresh_token = @token.refresh_token
4949
@token
5050
end

0 commit comments

Comments
 (0)